I'm quite new to curl and I don't know how to convert this to axios statement
curl https://{subdomain}.zendesk.com/api/v2/users/{user_id}/password.json \
-X POST -d '{"password": "newpassword"}' -H "Content-Type: application/json" \
-v -u {email_address}:{password}
I can make this run in postman but I'm not sure to convert it to axios.
Below is my sample axios code but it I get a EOF error
const response = await axios.post(`https://${subdomain}.zendesk.com/api/v2/users/${userId}/password.json`,
{
"password": "12345678"
},
{
auth: {
username: `${email}/token`,
password: ZENDESK_API_KEY
}
})
Related
I need to send a request like the one below.
curl --request POST --url https://dev-jlsubxnitkpok2tw.au.auth0.com/oauth/token
--header 'content-type: application/json' \
--data '{"client_id":"","client_secret":"","audience":"","grant_type":"client_credentials"}'
I am using Ballerina like below
http:Client securedEP = check new ("http://postman-echo.com", {
auth: {
tokenUrl: "xxx/oauth/token",
clientId: "xxx",
clientSecret: "xxx",
scopes: ["read", "submit"]
}
}
I get an error like the one below from the service.
cause: Failed to get a success response from the endpoint. Response code: '403'.
Response body: '{"error":"access_denied","error_description":"No audience
parameter was provided, and no default audience has been configured"}'
How can I achieve this in Ballerina?
You can use the optionalParams parameter in ClientCredentialsGrantConfig to specify that.
http:Client securedEP = check new ("http://postman-echo.com", {
auth: {
tokenUrl: "xxx/oauth/token",
clientId: "xxx",
clientSecret: "xxx",
scopes: ["read", "submit"],
optionalParams: {
"audience": "aud"
}
}
});
Note that the auth record field here is coming from CommonClientConfiguration type.
Stupid question here, but I am pulling my hair out (i'm bald) as to what I could possibly be doing wrong. I am doing a UrlFetchApp.fetch in google app scripts:
var result = UrlFetchApp.fetch(url, { headers: headers });
When using this as my headers, it works:
var headers = {
Authorization: 'Bearer ' + getAccessToken()
}
Now I need to pass in 'method' as 'PUT' instead of the default of 'GET' (above), and and trying like this:
var headers = {
method : 'put',
headers : {
Authorization: 'Bearer ' + getAccessToken()
}
}
When I try sending this, it is not finding the token:
Exception: Request failed for https://api.spotify.com returned code 401. Truncated server response: {
"error": {
"status": 401,
"message": "No token provided"
}
How can I format the headers so that I can pass in the Authorization with token and also pass in 'method' as 'PUT'?
I see in the URLFetchApp.Fetch documentation for Google, that this is passed into options:
https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app
headers Object a JavaScript key/value map of HTTP headers for the request
method String the HTTP method for the request: get, delete, patch, post, or put. The default is get.
Thank you so much for any help!
phi
I believe your goal is as follows.
You want to convert the following curl command to Google Apps Script. Ref And, from I know the call works with a simple GET method, your access token is valid.
curl --request PUT \
--url https://api.spotify.com/v1/me/player/play \
--header 'Authorization: ' \
--header 'Content-Type: application/json' \
--data '{
"context_uri": "spotify:album:5ht7ItJgpBH7W6vJ5BqpPr",
"offset": {
"position": 5
},
"position_ms": 0
}'
In this case, how about the following sample script?
Sample script:
Please modify data for your actual situation.
var data = {
"context_uri": "spotify:album:5ht7ItJgpBH7W6vJ5BqpPr",
"offset": {
"position": 5
},
"position_ms": 0
};
var options = {
method: 'put',
headers: { "Authorization": 'Bearer ' + getAccessToken() },
contentType: "application/json",
payload: JSON.stringify(data)
};
var url = "https://api.spotify.com/v1/me/player/play";
var res = UrlFetchApp.fetch(url, options);
console.log(res.getContentText());
Note:
I think that this request is the same as the curl command. But if an error occurs, please check the access token and the values in data, again.
References:
Start/Resume Playback
fetch(url, params)
For some reason, a POST requests fails with a timeout, while an according CURL request works perfectly fine. What could get wrong?
Working CURL request:
curl -X POST \
-H 'Content-Type: application/json' \
-d '{"jwt": "jwt"}' \
https://iam.api.cloud.yandex.net/iam/v1/tokens
Not working Vert.x WebClient request:
#Test
fun `get api token`(vertx: Vertx, testContext: VertxTestContext) {
val webClient = WebClient.create(vertx)
webClient.post(443, "iam.api.cloud.yandex.net", "iam/v1/tokens")
.putHeader("Content-Type", "application/json")
.ssl(true)
.sendJsonObject(JsonObject().put("jwt", "test"), testContext.succeeding {
testContext.verify {
Assertions.assertEquals(200, it.statusCode())
testContext.completeNow()
}
})
}
What is the equivalent axios request for cURL request below?
curl -X POST \
http://159.89.90.5:5000/users/login \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"email": "pwerner#gmail.com",
"password": "password"
}'
I've tried using axios request as follow:
let axiosConfig = {
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
}
};
this.$http.post('http://159.89.90.5:5000/users/login', {"email": "pwerner#gmail.com", "password": "password"}, axiosConfig)
.then(response => {
console.log(response)
}).catch(function (error) {
console.log(error);
currentObj.output = error;
});
but I keep getting CORS error because the request doesn't fit with the request I made in cURL above. What am I missing here? if correct like curl request above I'll get email parameter with value pwerner#gmail.com
below is the error I've got when trying to make the request:
but if I use formData instead of using json for the same code, it works, and my server (flask framework) is already provided header: response.headers.add("Access-Control-Allow-Origin", "*") for solving CORS issue
Is there any way to revoke coinbase oauth token? Coinbase documentation says that token is revoked after 2 hours, but I want my users to revoke access at any time they want.
I don't think there's a way to do this through the API, but you could link your users to https://coinbase.com/applications where they can revoke access themselves.
This is now allegedly supported (https://developers.coinbase.com/docs/wallet/coinbase-connect/access-and-refresh-tokens), but it does not work.
The access token can be revoked with the https://api.coinbase.com/oauth/revoke endpoint. Here is a curl request on how to use it:
curl --location --request POST 'https://api.coinbase.com/oauth/revoke' \
--header 'Authorization: Bearer ACCESS_TOKEN' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'token=ACCESS_TOKEN'
Or with Node.js (Source):
app.get('/refreshToken', async (req, res) => {
const data = qs.stringify({
'token': 'ACCESS_TOKEN'
});
const config = {
method: 'post',
url: 'https://api.coinbase.com/oauth/revoke',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Bearer ACCESS_TOKEN'
},
data
};
try {
const response = await axios(config);
res.send({ response: response?.data })
} catch (e) {
console.log("Could not refresh token", e.response.data)
}
})