Thank you for reaching out on Microsoft Q&A!
An endpoint for token requests usually supports the "application/x-www-form-urlencoded" content type, as is the case in your system as well when referring to the screenshots you shared. In that case the body should not be formed as a JSON, but as a "query string" like below:
You can use my query string below as reference, by changing the values to match yours:
client_id=YOURCLIENTID&client_secret=YOURCLIENTSECRET&grant_type=GRANTTYPE&password=YOURPASSWORD&username=YOURUSERNAME
Please click "Accept answer" if this answer is helpful, and upvote it. Feel free to drop additional comments below :-)
Seems like the grant_type is not set correctly. My assumption is this should be "password".
I tried all below -
password="password"
password="pass-word"
password=pass-word
For all the above, I get error Unsupported grant type
You should not change the password, this should just be the password for the user. You should set grant_type=password, then it should work :-)
Sorry for my mistake, I did try all the below but get the same error -
grant_type="password"
grant_type="pass-word"
grant_type=pass-word
grant_type=password
Password is currently set as 7J(&F6w'Btd!Nt
Does this have anything to do with the issue I'm facing currently?
Could be that the ampersand is the problem here. What if you wrap the password in encodeUriComponent() function like encodeUriComponent('7J(&F6w'Btd!Nt') ?
While answering I saw there was a ' in the password as well, this doesn't make this function work as it sees the ' as the end of the string, and then it continues. Think you should try to recreate the password without & and ' when possible.
Thanks, Sonny, I have requested my source to change the password. `
I will get back with an update soon.
The issue is resolved. The root cause is because of the password, as you rightly highlighted password can't have & and '
Great to hear that!
Sign in to comment
2 additional answers
Sort by: Most helpful
Hello @Vivek Komarla Bhaskar
I am hoping I can answer this with some trouble shooting steps as you have obscured the URL, therefore I cannot look up what is required (if it is a Microsoft URL for example)
The issue here most likely won't be with the logic app, but the service you are trying to get the token from.
Kind Regards
Alistair
Hi @Alistair Ross,
Yes, I tried it on Postman and it worked. My postman content type was application/x-www-form-urlencoded and I tried it on Logic App as well, but I still get the same error.
Can you provide details of the service you are trying to make the API call to. If it is an internal URL, do you have the relevant network access for the Logic App to communicate with that API?
Yes, this is internal and there are no network firewalls. When I set up Postman I didn't have to do anything and just entering the details worked. Please see below the success screenshot on Postman for the same -
Sign in to comment
@Vivek Komarla Bhaskar Thanks for reaching out. As you are using Content-Type as application/x-www-form-urlencoded so the body in most case will be below and not as the JSON object. Please validate if this is not the case as you are getting 400 errors that means that the request was not correctly formed.
Body:
client_id=97e0a5b7-d745-40b6-94fe-5f77d35c6e05&clientsecret=secreate&grant-type=granttype&password=password&username=username
In case if the above doesn't help then please share the fiddler/postman request screenshot that you are passing so I can assist you further.
Please accept as "Yes" if the answer is helpful so that it can help others in the community. If you need any help/clarification/concerns/follow up questions, then please click on "Add Comment" on my answer and provide more details.
Hi @MayankBargali-MSFT
I have tried this too but get the same error. Please see below the success screenshot on Postman for the same.
@Vivek Komarla Bhaskar Thanks for sharing the screenshot. Have you tested the Content-Type as application/x-www-form-urlencoded and body as JSON object as per the screenshot. Further I can see the header value as 7. Can you make sure that you are passing all the headers? Your endpoint is getting called as you are getting 400 error so the issue should be generating the right request. Let's try to execute the same endpoint using fiddler to make sure we are not missing any parameter. I can also connect with you offline for the quick assistance if the above doesn't help you.
@MayankBargali-MSFT The headers(7) here is by default. I didn't add or modify this. Here is the screenshot -

Sign in to comment
Activity