I keep getting an "Unsupported grant type: " error when trying to run the UPS OAuth API. It works in their documentation using the "Try it" feature but in my actual code it's not working and I've basically copy and pasted the code they provide in their documentation.
Here's my code:
const formData = {
grant_type: 'client_credentials'
};
const url = 'https://wwwcie.ups.com/security/v1/oauth/token';
const clientID = {clientID};
const clientSecret = {clientSecret};
const auth = 'Basic ' + Utilities.base64Encode(`${clientID}:${clientSecret}`);
let options = {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': auth
},
payload: JSON.stringify(formData)
}
Here's the error message
{ [Exception: Request failed for https://wwwcie.ups.com returned code 400. Truncated server response: {"response":{"errors":[{"code":"10400","message":"Unsupported grant type : "}]}} (use muteHttpExceptions option to examine full response)] name: 'Exception' }
Can anyone help me figure out what's going on? The documentation says that "client_credentials" is the only valid value so I'm not really sure how to proceed.
From your showing script, if you have wanted to use "Create Token", how about the following modification? When I saw the official document, the sample curl command was as follows.
When this is converted to Google Apps Script, it becomes as follows.
Sample script:
Please set your values of
usernameandpassword. Although I'm not sure about your actual situation, are the values ofclientIDandclientSecretin your showing scriptusernameandpassword, respectively?Note:
References: