How do I resolve 'Invalid request' error on Logic App for http POST action?

Vivek Komarla Bhaskar 911 Reputation points
2023-03-06T11:52:42.5133333+00:00

I have a logic setup with an HTTP POST action to retrieve a token, I have implemented my logic app as follows, but whenever I execute it, I receive the error 'Invalid request'. On Postman, the same works, but not here. How can I fix this?Screenshot 2023-03-06 at 11.40.29 am

Screenshot 2023-03-06 at 11.43.32 am

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
2,864 questions
0 comments No comments
{count} votes

Accepted answer
  1. Sonny Gillissen 3,271 Reputation points
    2023-03-06T17:15:40.2733333+00:00

    Hi @Vivek Komarla Bhaskar

    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:

    User's image

    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 :-)


4 additional answers

Sort by: Most helpful
  1. Alistair Ross 7,101 Reputation points Microsoft Employee
    2023-03-06T13:04:38.0333333+00:00

    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.

    • Can you verify the post request works from another service, such as PowerShell or https://www.postman.com/
    • Have you got all the required properties in the body not too many? It does seem strange to be providing a client secret and password in the same request, typically it would be one or the other when requesting a token, from my understanding.
    • Is the headers correct? Are you sure the content type isn't meant to be application/x-www-form-urlencoded ?

    Kind Regards

    Alistair


  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  3. MayankBargali-MSFT 68,656 Reputation points
    2023-03-06T13:29:03.4466667+00:00

    @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.


  4. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more