Home > Mobile >  Unable to post message to Azure Service Bus Queue from Azure API using Managed Identity
Unable to post message to Azure Service Bus Queue from Azure API using Managed Identity

Time:03-31

I am trying to test out the sample code by azure "Authenticate using Managed Identity to access Service Bus" and its on github:

enter image description here

On running a test on API I get error: "500 Internal Server Error". The message of course is not being sent. Any idea what I may be doing wrong here? Help appreciated.

CodePudding user response:

It seems to be issue with your Authorization header and the calling URL. All other steps looks good.

Please find below Policy code snippet which works fine at my end. I am able to send the data to service bus successfully. My operation endpoint is '/messages' with POST method. enter image description here

CodePudding user response:

I found the issue which is almost what @pankaj has suggested. I made a mistake when I created a POST operation on the api I created. When we add an operation for an api in azure apim, it asks for a URL also as shown below: [![Azure API - adding an Operation][1]

The issue was that I added a random text something like "/message". What this does is, it adds this path to the set-backend-service base-url

As that modified backend url was incorrect, so was the reason for error. I updated it to just a "/" in the POST operation path and the error got resolved.

I then again faced this issue when my request had some query parameters. It was again appending these query parameters to the backend url. To resolve that I added below:

<set-query-parameter name="{{replace-with-query-param}}" exists-action="delete" />

Thank you everyone for trying to help me. Hopefully, this post will be of some help to others [1]: https://i.stack.imgur.com/Rechc.jpg

  • Related