Search code examples
azurepostazure-eventhub

POST data on Azure Event hub is failing


This is regarding Azure Event hub and I am trying to send data using a POST api call from POSTMAN to my Event hub.

Steps I followed:

Created Event Hub, Generated SAS send token, Created Consumer group

Now in postman I am struggling to format the correct headers:

request I send:

POST:  https://testeventhu.servicebus.windows.net/myhub 

2 headers :

Content-Type : application/atom+xml;type=entry;charset=utf-8

Authorization:  SharedAccessSignature sig=kjheh/f6SqR8dIW2nRpGUCHuhdshss2KoCKo7Q6ozmY=&se=1571140739&skn=saspolicy&sr=https://testeventhu.servicebus.windows.net/myhub

and I get the error as 401 MalformedToken: Failed to parse simple web token

What wrong am I doing in here?the refrence used is from https://learn.microsoft.com/en-us/rest/api/eventhub/Send-event?redirectedfrom=MSDN

Thanks in advance


Solution

  • Please follow my steps as below:

    1.After you create your eventhub namesapce and eventhub instance in azure portal -> in azure portal, nav to your eventhub namespace -> Shared access policies, click "Add" button to create a sas policy(here, I just select the Send privilege for sending purpose). The screenshot as below:

    enter image description here

    2.Generate sas token, I create the sas token via powershell as per this link. Here is my powershell code and the returned sas token:

    enter image description here

    3.In postman:

    The request url should like this, remember add messages at the end: https://your_eventhub_namespace.servicebus.windows.net/your_eventhub_instance/messages

    The headers:

    Authorization : the sas token from step 2

    Content-Type: application/atom+xml;type=entry;charset=utf-8

    Host(optional): your-eventhub-namespace.servicebus.windows.net

    the screenshot as below, you can see the returned status code is 201 created:

    enter image description here

    And if you don't know how to set the message body, you can see my message in body in postman:

    enter image description here

    Please feel free to let me know if you still have any issues.