Linkedin API request fails "Resource rest does not exist" when get sharesid - linkedin-api

Good Morning,
I'm trying to get shareid of my test publication on Api Linkedin my request is:
https://api.linkedin.com/v2/rest/posts/shareUrn(urn:li:share:6947445733109194752)?X-Restli-Protocol-Version=2.0.0&LinkedIn-Version=202206
I also have my token but I don´t understand the reply:
{
"serviceErrorCode": 0,
"message": "Resource rest does not exist",
"status": 404
}
Any help is greatly appreciated
Thanks

you either go with 'V2' versioning or 'rest' versioning. The endpoints with headers should be (in python):
V2:
url = 'https://api.linkedin.com/v2/rest/posts/shareUrn/'
headers = {
'Authorization': f'Bearer {token}',
}
Rest:
url = 'https://api.linkedin.com/v2/rest/posts/shareUrn/'
headers = {
'Authorization': f'Bearer {token}',
'LinkedIn-Version': REST_VERSION,
}
where REST_VERSION is something like '202212'.
Optionally (not all LI endpoints accept it) you can add to the headers info about protocol:
"X-Restli-Protocol-Version": "2.0.0"

Remove "/rest" from the endpoint.
Include "X-Restli-Protocol-Version" and "LinkedIn-Version" in the header of the request.
Make sure all the query params in the request are in correct format.
Goodluck!

Related

How to add API key to Axios post request for mailchimp

I'm trying to set up an axios post request to add members to an audience list, but I can't figure out how to add the API key (keeps giving error 401: 'Your request did not include an API key.'). I've tried a bunch of things in the "Authorization" header, like what I put below (also: "Bearer ${mailchimpKey}", "${mailchimpKey}", "Bearer ${mailchimpKey}", "Basic ${mailchimpKey}", and probably more...).
I also don't know what the "username" would be, but "any" worked when I tested the API elsewhere.
Does anyone know how I should set this up?
axios
.post(
`https://${server}.api.mailchimp.com/3.0/lists/${list_id}/members`,
{
email_address: email,
status: "subscribed",
},
{
"User-Agent": "Request-Promise",
Connection: "keep-alive",
Authorization: `Basic any:${mailchimpKey}`,
// Testing on localhost
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "Content-Type",
}
)
If your intention is to use HTTP Basic authentication, just use the Axios auth config option
axios.post(
`https://${server}.api.mailchimp.com/3.0/lists/${encodeURIComponent(list_id)}/members`,
{
email_address: email,
status: "subscribed",
},
{
auth: {
username: "anystring",
password: mailchimpKey
},
headers: { // personally, I wouldn't add any extra headers
"User-agent": "Request-Promise"
}
}
)
HTTP Basic auth headers look like
Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=
where the string after "Basic" is the Base64 encoded "username:password" string. Axios provides the auth option as a convenience so you don't need to encode the string yourself.
Some other problems you had were:
Adding request headers outside the headers config option
Attempting to send Access-Control-Allow-Origin and Access-Control-Allow-Headers as request headers. These are response headers only. Adding them to your request will most likely cause more CORS errors

Stripe API request working with Postman but failing with Apex Rest Callout

I'm trying to make a callout to a Stripe Api with Apex. I made the exactly same request in Postman with the same Http configuration and have this working well. But when running it with Apex i get a Http 400 (Bad Request) with this error message:
{
"error": {
"message": "This property cannot be expanded (data).",
"type": "invalid_request_error"
}
}
What I want to do is to query a list of Payment Intents from stripe and expand the balance transaction stored in the payment charge data. And here is how I do it
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setHeader('Authorization', 'Bearer Token');
request.setHeader('Content-Type', 'application/x-www-form-urlencoded');
String payload = 'expand[]=data.charges.data.balance_transaction';
request.setMethod('GET');
request.setEndpoint(API_ENDPOINT + '/v1/payment_intents');
request.setBody(payload);
HttpResponse response = http.send(request);
System.debug(response.getBody());
Can anyone help me please to understand what I am missing here?
Try expand[]=charges.data.balance_transaction Instead.

Error while generating access_token using Ebay 's REST API - Python requests

I'm trying to use the ebay REST-API for the first. I am simply trying to generate an access_token using the client credentials grant-request. I followed the instructions here https://developer.ebay.com/api-docs/static/oauth-client-credentials-grant.html
HTTP method: POST
URL (Sandbox): https://api.sandbox.ebay.com/identity/v1/oauth2/token
HTTP headers:
Content-Type = application/x-www-form-urlencoded
Authorization = Basic <B64-encoded_oauth_credentials>
Request body (wrapped for readability):
grant_type=client_credentials&
redirect_uri=<RuName-value>&
scope=https://api.ebay.com/oauth/api_scope
I'm getting this error: {'error': 'invalid_client', 'error_description': 'client authentication failed'} and my code looks like this:
path = 'https://api.sandbox.ebay.com/'
app_json = 'application/json'
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': base64.b64encode(b'Basic CLIENT_ID:CLIENT_SECRET')
}
payload = 'grant_type=client_credentials&redirect_uri=Searchez&scope=https://api.ebay.com/oauth/api_scope'
def get_oath_token():
url = 'https://api.sandbox.ebay.com/identity/v1/oauth2/token'
r = requests.post(url, headers=headers, data=payload)
print(r.json())
get_oath_token()
What do I have configured incorrectly? Thanks.
You're base64encoding "Basic " and shouldn't be.
The doc says just encode your Client ID + ":" + Client Secret, and leave the word "Basic" and the space that follows it alone.
In your code, i can see sandbox endpoint URI but in the request body scope, you have used production URL, instead of sandbox

Using cors across two independently running local apps

I have two applications running indepepently, one taking care of my backend (written in Scala Play) then other one being my frontend (Angular with a static Node server).
I try to request data on my frontend through a form from my Scala Play app.
this.insertionOrder = function(){
$http({
method: 'POST',
url: '//localhost:9000/insertsupplier',
header: {
'Content-type': 'application/json',
'Access-Control-Allow-Origin' : '*',
'Access-Control-Allow-Methods' : 'POST, GET, OPTIONS'
},
data:{
'supplier_id': 1,
'suppliername': 'xxx',
'supplier_address': 'xxx xxx xxx xxx',
'contact': 'xxx#xxx.com',
'datecreated': '2017-10-15T09:45:00.000UTC+00:00'
}
}).then(function(response){
console.log(response);
return response.data
}, function(err){
console.log(err)
});
};
and my play app looks like this:
Controller:
def insertsupplier = Action(parse.json) { implicit request =>
val json = request.body
val sup: Supplier = json.as[Supplier]
sup.insertSql(con)
Ok("test")
}
my build.sbt contains filters:
libraryDependencies ++= Seq(
cache ,
ws,
jdbc,
filters
)
and the MyFilters.scala
class MyFilters (implicit inj:Injector) extends HttpFilters with Injectable {
implicit val as = inject[ActorSystem]
implicit val mat = ActorMaterializer()
val gzip = new GzipFilter()
val csrf = inject[CSRFFilter]
val cors = inject[CORSFilter]
//println(s"csrf: ${csrf.tokenProvider}")
//println(s"csrf: ${csrf.tokenProvider.generateToken}")
def filters = Seq(gzip,cors,csrf)
}
and finally my application.conf
play.filters.cors {
pathPrefixes = ["*"]
allowedOrigins = ["http://localhost:3000","https://localhost:3000","http://localhost:3000/*","https://localhost:3000/*"]
allowedHttpMethods = ["GET", "POST", "OPTIONS"]
allowedHttpHeaders = ["Accept"]
# preflightMaxAge = 1 hour
}
play.filters.csrf {
cookie.name = "XSRF-TOKEN"
header.name = "X-XSRF-TOKEN"
}
play.http.filters = "filters.MyFilters"
I keep getting the error "XMLHttpRequest cannot load http://localhost:9000/insertsupplier. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 500."
I feel that first my CORS setup is wrong anyway --> What needs to be changed? I am new to this.
And am I even able to use cors in order to access data from localhost?
It may be that there’s nothing wrong at all with your CORS setup, because the “The response had HTTP status code 500” part of the error message indicates that the actual immediate problem is that an OPTIONS request to your server caused some unexpected failure on the server side.
From just the code snippets in the question, it’s not possible to tell what might be causing that 500 failure in the server side. It may be completely unrelated to your CORS config.
But regardless, you should drop the parts of your frontend code that are adding the header 'Access-Control-Allow-Origin' : '*', and 'Access-Control-Allow-Methods'. Those headers are response headers that must be sent from the server side, not from frontend code.
But the 'Content-type': 'application/json' part of your frontend code is valid, and assuming it’s actually necessary in order to get the expected response from the server, there’s no way you can make your request without triggering browsers to do a CORS preflight OPTIONS request.
But if the CORS preflight OPTIONS request fails, the browser never gets around to trying the POST request your code is actually attempting to send. And if your backend responds to that OPTIONS request with a 500 response, then the preflight fails. It must instead respond with a 200 or 204.

dotmailer request token from REST API

I struggle in call the REST API at Dotmailer.
he provide a document for call the OAuth and get the token.
but it's always throws the same error.
Input is
Post Method
URI: https://r1-app.dotmailer.com/OAuth2/Tokens.ashx
JSON input is
{
"client_id" : "apiuser-XXXXXXXXXXX#apiconnector.com",
"redirect_uri" : null,
"client_secret" : "XXXXXXXXXXXX",
"grant_type": "authorization_code",
"code":"MyServerCode",
"test_mode":true
}
Out put is
{
"error": "invalid_request",
"error_description": "There was a problem with the 'grant_type' parameter: The parameter is required."
}
Anyone know the error.
Thanks in advance...
I think Dotmailer OAuth have some problem.
I was used alternatively Basic Authentication method to access the dotmailer API.
Base URI = https://api.dotmailer.com/v2/
Header
Content-type: application/json
Authorization: Basic base64_convertion(username:password).
Sample
Content-type: application/json
Authorization: Basic XXXXXXXXXXXXXXXX.
Use WADL method.
https://api.dotmailer.com/v2/help/wadl