Always get response 404 - jawbone

I have handled the process to get a valid access token;
nevertheless, now I am stuck to get data from the server;
I have checked the forum and other web pages, but I could not figure out what I am doing wrong;
I am running the following Google Application Script:
var jawbone_access_token = "my private access token - long string";
var options = {
'Accept' : 'application/json',
'Authorization' : 'Bearer ' + jawbone_access_token
}
var jawbone_request = "https://jawbone.com/nudge/api/v.1.1/users/#me";
response = UrlFetchApp.fetch(jawbone_request, options).getContentText();
writeLog(response);
nevertheless, I always get the following response:
ERROR - Stau:Exception: Fehler bei der Anfrage für
https://jawbone.com/nudge/api/v.1.1/users/#me. Folgender Code wurde
zurückgegeben: 404. Gekürzte Serverantwort: {"meta": {"error_detail":
"Unsupported API version 1.1, unless called with an OAuth header",
"code": 404, "error_type": "endpoint_error", "time": 1.... Verwenden
Sie "muteHttpExceptions", um die vollständige Antwort zu lesen.
can you please help me to figure out what I am doing wrong;
Thank you very much in adavance for your help;
Best Regards
Rudolf

That is the response you get when you haven't provided the Access Token in the header.
I took a quick look at the UrlFetchApp documentation, and you need to put your headers in a headers object:
var options = {
'headers': {
'Accept': 'application/json',
'Authorization': 'Bearer ' + jawbone_access_token
}
}

Related

github API check_runs returning 415, "Unsupported Media Type"

really that simple, making a request with github api: https://docs.github.com/en/rest/reference/checks#list-check-runs-for-a-git-reference
I am trying to find the check runs for a particular branch I have. Below is the url I GET from:
url = ...api/v3/repos/{repo_fullname}/commits/{branch}/check-runs'
Here are my headers:
headers = {
'Authorization': 'token ' + token,
"Accept": "application/vnd.github.v3+json"
}
I get hit with the: 415 Client Error: Unsupported Media Type for url...
Please help, been banging my head for hours. Thanks!
Perhaps you could try a different accept? I work with octokit for node and this fixed my problem, maybe it would help in this case.
headers = {
'Authorization': 'token ' + token,
"Accept": "application/vnd.github.antiope-preview+json"
}

Http with token in Ionic 4

(Sorry for my bad english) I have to access an api, with a token that they have provided me. My problem is that I don't know how to implement it, after searching and searching, it gives me the following error:
Access to XMLHttpRequest at 'https://www.presupuestoabierto.gob.ar/api/v1/credito' from origin 'http://localhost:8100' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
I pass my code to you, to indicate that it is wrong in the definition of the token (the x instead of the token) and eventually in the CORS policy, thank you very much!
const headers = { 'Authorization': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': 'http://localhost:8100'}
this.http.get<any>('https://www.presupuestoabierto.gob.ar/api/v1/credito', { headers }).subscribe(data => {
this.datos = data.blabla;
})
Headers should pass like this in Ionic- Angular. Make sure that you have a service file.Visit this link to know more about services:
https://angular.io/tutorial/toh-pt4
let headers = new Headers({
'Content-Type' : 'application/json',
'Auth':authvalue
});
return this.http.get(url,options).pipe(map(res => res.json()));

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});
}

Axios POST status 400 bad request [duplicate]

This question already has an answer here:
Getting error when using axios POST
(1 answer)
Closed 3 years ago.
I am trying to make a POST request to the spotify web api. I am using this piece of code for doing so:
axios.post(ACCESS_URL, {
"grant_type": 'authorization_code',
"code": code,
"redirect_uri": REDIRECT_URI
},
{
headers: {
"Authorization": "Basic " + Buffer.from(CLIENT_ID + ":" + CLIENT_SECRET).toString("base64"),
'Content-Type': 'application/x-www-form-urlencoded'
},
})
In the snippet above code is the users authorization code and everything else are server constants. The problem is that I am getting the following error when I am performing the request:
error: 'unsupported_grant_type',
error_description: 'grant_type must be client_credentials, authorization_code or refresh_token'
As you can see, the grant type that I am sending in the request body is one of the 3 specified grant types, but I am stil getting status 400 and I can't figure out why. Any ideas?
Thanks in advance since I am sure it's a silly question with an easy answer, but I just don't see it
See Unsupported grant type error when requesting access_token on Spotify API with Meteor HTTP for a similar problem.
Spotify expects the grant_type in the query string parameters, not in the post request body. Actually the configuration in the above question/answer looks pretty similar to the axios config. Simply wrap your first three parameters into a params object:
axios.post(ACCESS_URL, {
params: {
"grant_type": 'authorization_code',
"code": code,
"redirect_uri": REDIRECT_URI
},
headers: {
"Authorization": "Basic " + Buffer.from(CLIENT_ID + ":" + CLIENT_SECRET).toString("base64"),
'Content-Type': 'application/x-www-form-urlencoded'
}
})
I found the solution. I had to encode the data using querystring like this:
return axios.post(ACCESS_URL,querystring.stringify({
"grant_type": 'authorization_code',
"code": code,
"redirect_uri": REDIRECT_URI
}),
{headers: {
"Authorization": "Basic " + Buffer.from(CLIENT_ID + ":" + CLIENT_SECRET).toString("base64"),
'Content-Type': 'application/x-www-form-urlencoded'
}
}
)
Thanks everyone for the help

Angular-5 StripeConnect -303 Error -Response for Preflight is invalid (Redirect)

I am doing StripeConnect(Standard Account Type) with Angular 5 and Asp.NetCore.
I am able to get redirected to required URL with code={} value.
When I am trying to use this code in below URL,
https://connect.stripe.com/oauth/token\client_secret={{secret test key}}\code={{code}}\grant_type = authorization_code"
1.I get preflight is invalid (Redirect) error in browser from my angular solution.
2.The html for stripe login page from Postman.
The code I wrote for making the post call to above URL (in angular) is :
getCredentialsFromStripe(code: any)
{
let Url = "https://connect.stripe.com/oauth/token";
//\client_secret=" + {{key}} + "\code=" + code + "\grant_type
= authorization_code";
return this.http.post(Url, {
Body: "client_secret = {{key}}\code =" + code,
Headers: {
'Authorization': 'Bearer '+ code,
"Accept": "application/json; charset=UTF-8",
"Access-Control-Allow-Origin": "https://connect.stripe.com/oauth/token"
}
}).map(res => res.json());
}
As per suggestions on internet,I tried making the post call from backend(.NET core(2.0) API for me),but didn't get through in creating account for standard account type.
Moreover testing from postman is giving the full html page of login ,instead of getting this object:
{
"token_type": "bearer",
"stripe_publishable_key": "{PUBLISHABLE_KEY}",
"scope": "read_write",
"livemode": false,
"stripe_user_id": "{ACCOUNT_ID}",
"refresh_token": "{REFRESH_TOKEN}",
"access_token": "{ACCESS_TOKEN}"
}
Can anybody give me a lead on this.I have been stuck past two days.
Any thoughts will be really appreciated.
Well,I was able to fix it. Instead of creating accounts using the URL (given above) in angular project (following the node.js documents),I called the stripe api's in Asp.net core (my api solution) and called them.It worked easily.