Event Hubs: Return errors of REST API as JSON

Andre 0 Reputation points
2023-07-21T09:26:26.2966667+00:00

When sending successfully JSON events to Azure Event Hubs REST API (https://<NAMESPACE>.servicebus.windows.net/<INSTANCE>/messages), it returns code 201 and no text.

With e.g. a missspelled instance name in the URL or an ill-formed Shared Access Signature, the text of the response comes in XML format. Is it possible to influence this behaviour, so that errors are returned as JSON?

Or is it like for the API of BlobStorage, where that cannot be changed (https://learn.microsoft.com/en-us/answers/questions/158427/does-blobstorage-api-returns-errors-in-json-format)?

Thank you

Azure Event Hubs
Azure Event Hubs
An Azure real-time data ingestion service.
652 questions
{count} votes

1 answer

Sort by: Most helpful
  1. PRADEEPCHEEKATLA 90,241 Reputation points
    2023-07-24T05:34:29.5+00:00

    @Andre - Thanks for the question and using MS Q&A platform.

    When sending JSON events to Azure Event Hubs REST API, if the request is successful, it returns a code 201 and no text. However, if there is an error, such as a misspelled instance name in the URL or an ill-formed Shared Access Signature, the response text is returned in XML format.

    Unfortunately, it is not possible to influence this behavior and change the error response format to JSON. This is because the Azure Event Hubs REST API is designed to return error responses in XML format, and this behavior cannot be changed.

    Similarly, the Azure Blob Storage API also returns error responses in XML format, and this behavior cannot be changed either.

    However, you can parse the XML error response and convert it to JSON format in your application code if needed. There are several libraries available in different programming languages that can help you parse XML and convert it to JSON.

    Hope this helps. Do let us know if you any further queries.


    If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.