Currently, I am able to retrieve an "access_token" using Postman; however, I am attempting to recreate this process in ajax for experimentation purposes on jsfiddle.
In Postman, the following setup is used:
- A POST request URL:
- No active headers
- Body includes four key-value pairs (refer below)
https://i.sstatic.net/F8vJs.png
Executing the request results in a response containing the access_token:
https://i.sstatic.net/BfH5y.png
For replicating this in ajax, with assistance from others, the following script was created:
$.ajax({
type: 'POST',
url: 'https://login.microsoftonline.com/***/oauth2/token',
data: JSON.stringify({
grant_type: 'client_credentials',
client_id: '***',
client_secret: '***',
resource: 'https://analysis.windows.net/powerbi/api'
}),
success: data => {
console.log(data.access_token)
},
error: (xhr, textStatus, error) => {
console.log('rr', error)
}
});
However, every time this script is run, it returns an error in the console:
https://i.sstatic.net/IiJoi.png
Although I believe I am close to resolving the issue, I have not been able to figure it out yet.