HTTP Response Error with Post to LinkedIn using Share API v2 - api

I am trying to post a Share to LinkedIn using OAuth v2 - I have got authorisation correctly and have the appropriate access keys.
This code is supposed to share a link on LinkedIn, but for some reason it's not working - I'm not sure why. Can anyone help?
this is my request body:
{
"distribution": {
"linkedInDistributionTarget": {}
},
"owner": "urn:li:person:XXXXXX",
"subject": "Test Share Subject",
"text": {
"text": "Hello !"
}
And this my call API shares :
publishPostLink(body : any, token : any){
this.headers = new HttpHeaders(
{
'Content-Type': 'application/json',
'Authorization':'Bearer '+token,
'cache-control': 'no-cache',
'X-Restli-Protocol-Version':'2.0.0', });
return this.http.post("https://api.linkedin.com/v2/shares" , body, {headers: this.headers});}
I get this issue:
I've already installed the Moesif CORS and it didn't worked
I fixed the error using this post..
it should use REST API from the backend and not from frontend

http://localhost is an insecure request origin so its not supportted in many cases.
Try using tunneling software like Ngork https://ngrok.com/

Related

insert multiple rows in a data extension by using rest api

I'm trying to insert multiple rows in my data extension by using a POST request on postman. I'm using this documentation :https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/postDataExtensionRowsetByKey.html.
Details of my first POST request :
My URL :
https://MY_SUBDOMAIN.auth.marketingcloudapis.com/v2/token
My body (by using the informations of the package created on marketing cloud) :
{
"client_id": "ssd6ssd6ssd6ssd6ssd6ss",
"client_secret": "p3sp3sp3sp3sp3sp3sp3sp3",
"account_id": "7842222",
"grant_type": "client_credentials"
}
I send the request => Status 200 OK
I copy the tokken access.
I create a second POST request.
Tab Authorization, Type = Bearer Token, I paste my token access
Details of my second POST request :
My URL :
https://MY_SUBDOMAIN.rest.marketingcloudapis.com/hub/v1/dataevents/key:EXTERNAL_KEY_OF_MY_DATA_EXTENSION/rowset
My body :
`
Host: https://MY_SUBDOMAIN.rest.marketingcloudapis.com
POST /hub/v1/dataevents/EXTERNAL_KEY_OF_MY_DATA_EXTENSION/rowset
Content-Type: application/json
[
{
"keys":{
"ID_Crawl": "test123"
},
"values":{
"Source": "2013-05-23T14:32:00Z",
"Type_contenu": "no",
"Statut_Notification": "non lu",
"Champ": "20081105",
"Origine_contenus": "test blablablablablablabla",
"Date_crawl": 02/02/2023
}
},
{
"keys":{
"ID_Crawl": "test"
},
"values":{
"Source": "2013-05-23T14:32:00Z",
"Type_contenu": "ok",
"Statut_Notification": "valide",
"Champ": "00000007",
"Origine_contenus": "test blablablablablablabla",
"Date_crawl": "02/02/2023"
}
}
]
I send the request and I had an error message (Status:400 Bad request means that bad synthax):
{"documentation":"https://developer.salesforce.com/docs/atlas.en-us.mc-apis.meta/mc-apis/error-handling.htm","errorcode":0,"message":"Bad Request"}
Does someone know where is my mistake ?
Sorry if it seems that my mistake is a stupid one, I'm completely a beginner in api call

sharing GCP image using api

I have been trying to share my GCP image with other accounts using API... on the UI I can do it in permissions and by adding members...
I used the following URL with the post request:
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/images/IMAGE_NAME:getIamPolicy
with headers 'Content-Type': 'application/json; charset=utf-8'
and with data:
{"version": "0",
"bindings":
[
{
"members": ["user:mymailid#gmail.com"],
"role":"roles/compute.imageUser"
}
]
}
}
bypassing the authorization bearer key,
after hitting it in postman or with curl or in python request, getting a response: 404 Not Found
I also enabled the API permissions using CLI using gcloud services enable pubsub.googleapis.com
what do I need to pass extra to make this work?
hoping I will get help from someone ... Thanks in advance
#Ganesh
To set IAM Policy, you need to use different url.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/images/IMAGE_NAME/setIamPolicy
json({
"version": "0",
"bindings": [
{
"members": ["user:mymailid#gmail.com"],
"role": "roles/compute.imageUser"
}
]
})
Note:
replace projectId
replace imagename
reference:
google-docs, collection, Dothttp

Request body missing from POST requests made using Postman scripting

I am trying to run a pre-request script for authenticating all my requests to the Spotify API. It works via the Postman GUI, but when I try to make the request via scripting, it fails because there is no body. Here is my code
const postRequest = {
url: pm.environment.get("spotifyAuthApi"),
method: "POST",
header: {
"Content-Type": "application/x-www-form-urlencoded",
"Accept": "*/*",
"Content-Length": 29,
"Authorization": "Basic " + btoa(pm.environment.get("client_id") + pm.environment.get("client_secret"))
},
body: {
grant_type: "client_credentials",
}
}
I get a
error: "unsupported_grant_type"
error_description: "grant_type parameter is missing"
And when I examine the request via the postman console, there is no request body, even though the request was built exactly like my fetch token request that does the same thing successfully in postman, only via the GUI instead of via a pre-request script. I have searched far and wide about this issue and tried multiple variations of the body object but to no avail. Either the body object doesn't generate my desired field, or it doesn't get created at all.
Mode might be missing in the body object. Try this:
body: {
mode: 'raw',
raw: JSON.stringify({ grant_type: 'client_credentials' })
}
More details might be found in Postman docs for RequestBody.
If you're using urlencoded, the body of the request would be structured like this:
body: {
mode: 'urlencoded',
urlencoded: [
{ key: 'grant_type', value: 'client_credentials'}
]
}

Github API v3, post issues / authentication

I am working on a project making a Kanban board using the Github API v3.
I have no problem with get methods, but when it comes to post methods i get a 404 response, and from what i read in the documentation, this seems to be a authentication error.
I am using personal token for authentication, and have successfully posted through postman, but when i try to post through my own application i get the error.
Link to project if anyone's interested : https://github.com/ericyounger/Kanban-Electron
Below is the code used for posting to github.
Might there be a problem with my code below? Or might it be settings in relation with the token?
postIssue(json){
let packed = this.packPost(json);
return Axios.post(`https://api.github.com/repos/${this.user}/${this.repo}/issues`, packed);
}
packPost(json) {
return {
method: "POST",
headers: {
"Authorization": `token ${this.tokenAuth}`,
"Content-Type": "application/json"
},
body: JSON.stringify({title: json.title})
};
}
This is what i receive:
{message: "Not Found", documentation_url: "https://developer.github.com/v3/issues/#create-an-issue"}
message: "Not Found"
documentation_url: "https://developer.github.com/v3/issues/#create-an-issue"
Console log error message
Without seeing any detailed logs, my first attempt would be to set body to not send the string representation of the body
body: {title: json.title}
This did the trick :)
postIssue(json){
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/vnd.github.v3.raw',
"Authorization": `token ${this.tokenAuth}`,
};
return Axios.post(`https://api.github.com/repos/${this.user}/${this.repo}/issues`, json , {headers: headers});
}

Getting Code 400 using Dialogflow on API request

this is my very first time using Dialogflow, so probably my mistake is very stupid.
here is my problem:
1) I created a sample agent "small-talk'.
2) I enabled the Webhook in the fulfilment section. I setup the URL of the web server making the request and the auth (username, password) of the that web server.
3) I uploaded a simple webpage on that web server with an API request that looks like this one below (this is the sample json referenced in their guide):
axios({
method: 'POST',
url: 'https://api.dialogflow.com/v1/query?v=20150910',
headers: {
'Authorization': 'Bearer ad7829588896432caa8940a291b66f84',
'Content-Type': 'application/json',
},
body: {
"contexts": [
"shop"
],
"lang": "en",
"query": "I need apples",
"sessionId": "12345",
"timezone": "America/New_York"
}
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.log(error);
})
I keep getting this error:
Cannot parse json. Please validate your json. Code: 400"
The only thing I can thing of, is that I noticed that Dialogflow is now working with the API V2 enabled by default in the agent settings and it seems there is no selection to V1 available anymore. But maybe this has nothing to do with my problem.
Thanks in advance!
Solved it!
In the json request, instead of
body: {...}
I replaced it with
data: {...}
Probably it was obvious, but I am an absolute newbie on these things!
By the way, Google has shutdown Dialogflow V1 starting from 12th July 2021 as per this URL - https://cloud.google.com/dialogflow/docs/release-notes#June_15_2021
In case you are getting http response code 400 (bad request), it means that it is time to migrate :-)