Testing APIM API is giving null response when 200 ok

Venkatesh Korrapati 0 Reputation points
2025-01-07T16:09:13.5466667+00:00

Hi Team,

We have multiple APIs managed by APIM when test APIs by powershell it returns null response for 200 status code but we could see these there is some response for 401s.

What could be the reason and how to fix it.

Thanks

venkatesh.k

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
2,248 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,726 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Michael Taylor 55,841 Reputation points
    2025-01-08T15:13:52.6766667+00:00

    Status codes and response bodies are 2 completely different things. Status code indicates the general successfulness of the request. If there is any data to return then the response body has that. It is perfectly legal, and common, to return success (200) with no data. Generally it is preferred that you use 204 (no content) but it is not at all required.

    Please confirm that your API actually returns data for the request you're sending by using a tool like Postman or curl. If you can share with us your PS code that would be great. PS can call APIs several different ways and it makes assumptions depending on what you're using. For example the Invoke-RestMethod assumes a REST API and, I believe, JSON response. It converts the response, if any, to a typed-object based upon the JSON. However if you use Invoke-WebRequest then you can call anything and it returns the raw response that you then have to reach into to get the data. Please provide us the PS call you're using along with the expected response (from Postman or similar) and what you're actually getting in PS.


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.