Reputation:
I'm complete beginner at using API's, but I'm trying to exchange my secret for a JWT, using a Token endpoint.
(removed the client_credentials
on purpose)
fetch('', {
method: 'POST',
body: 'grant_type=client_credentials&client_id=' + key + '&client_secret=' + secret,
headers: {
"Content-Type": "Bearer [JWT]",
}
}).then(function (resp) {
// Return the response as JSON
return resp.json();
}).then(function (data) {
// Log the API data
console.log('token', data);
}).catch(function (err) {
// Log any errors
console.log('something went wrong', err);
});
I get this error:
"token {error: "invalid_request", error_description: "grant_type missing"}"
Upvotes: 0
Views: 132
Reputation: 253
Please try below code to correct your header section
headers: {
"Content-Type": "application/json",
"Authorization":"Bearer [value of JWT Token]"}
Let me know if that works for you. Thanks.
Upvotes: 1