question

PuviarasuSenthilKumarRBEIBSN3-5724 avatar image
0 Votes"
PuviarasuSenthilKumarRBEIBSN3-5724 asked MartinJaffer-MSFT commented

Event Hub: Not able to do http post to insert data into event hub

After creating Event Hub Namespace and Event Hub, I have done the below settings.

  1. Enabled Firewall security so that all networks are having access

  2. Regenerated SAS keys for the Event Hub namespace itself

  3. Copied the SAS key of the Event Hub namespace and did a http post request as mentioned in https://docs.microsoft.com/en-us/rest/api/eventhub/send-event

But the post requests are failing with 401 error.

Could you please guide?


azure-event-hubs
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello @PuviarasuSenthilKumarRBEIBSN3-5724 and welcome to Microsoft Q&A.

The general meaning of 401 error is "Unauthorized". The specific message you get back will tell you more. For example, when I paste in the SAS key without creating a full SAS signature, I get :

 <Error>
     <Code>401</Code>
     <Detail>MalformedToken: The credentials contained in the authorization header are not in the WRAP format. TrackingId:XXXXXXX, SystemTracker:XXXXXXX.servicebus.windows.net:XXXX/messages, Timestamp:XXXXXX</Detail>
 </Error>

Sadly, posting a message with SAS isn't as simple as copy-paste the key. The key is part of a larger message.


0 Votes 0 ·

@MartinJaffer-MSFT, thank you for the response. Actually the issue was that the SAS token is having an '=' which need to be encoded as '%3d' while setting the header. Once we did the url-encoding, the issue got resolved.

0 Votes 0 ·

@PuviarasuSenthilKumarRBEIBSN3-5724 did my response help? Without the specific error message you get, I cannot help further.

If you found your own solution, please share here with the community.

0 Votes 0 ·
PuviarasuSenthilKumarRBEIBSN3-5724 avatar image
1 Vote"
PuviarasuSenthilKumarRBEIBSN3-5724 answered MartinJaffer-MSFT commented

Actually the issue was that the SAS token is having an '=' which need to be encoded as '%3d' while setting the header. Once we did the url-encoding, the issue got resolved. We also changed our Content type as below.

ContentType: application/x-www-form-urlencoded

Reference Link: https://www.c-sharpcorner.com/article/azure-event-hub-messaging-using-rest/

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you for sharing the resolution. Keep up the good work!

0 Votes 0 ·
SerkantKaraca-MSFT avatar image
0 Votes"
SerkantKaraca-MSFT answered PuviarasuSenthilKumarRBEIBSN3-5724 commented

The error message indicates the authorization header is not in right format. The header should similar to the one in below sample HTTP request.

POST https://your-namespace.servicebus.windows.net/your-event-hub/messages?timeout=60&api-version=2014-01 HTTP/1.1
Authorization: SharedAccessSignature sr=your-namespace.servicebus.windows.net&sig=your-sas-key&se=1403736877&skn=RootManageSharedAccessKey
Content-Type: application/atom+xml;type=entry;charset=utf-8
Host: your-namespace.servicebus.windows.net

{ "DeviceId":"dev-01", "Temperature":"37.0" }

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@SerkantKaraca-MSFT, thank you for the response. Actually the issue was that the SAS token is having an '=' which need to be encoded as '%3d' while setting the header. Once we did the url-encoding, the issue got resolved.

1 Vote 1 ·