400 bad request in graph API but same working in postman

Sagar Kumar 0 Reputation points

I am trying to hit a Get method - https://graph.microsoft.com/v1.0/me but I am getting 400 bad request. But the same API is working in Postman, with token

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,145 questions
{count} votes

1 answer

Sort by: Most helpful
  1. David Broggy 5,701 Reputation points MVP

    Hi Sagar,

    There's a good article in Medium for using/testing graph connections.


    As you may know, it's a 2 step process:

    • request a token using a POST request

    -query your resource

    To get your token, you need to go here:

    curl -X POST -d 'grant_type=client_credentials&client_id=[APP_ID]&client_secret=[PASSWORD]&resource=https%3A%2F%2Fmanagement.azure.com%2F' https://login.microsoftonline.com/[TENANT_ID]/oauth2/token

    Note that you will need to create a service principal for the above command.

    The article shows a clever way to do it with az commands but I usually configure an app registration in Azure.

    Then you can query your resource with your token.

    Remember there's a different url for every resource so you really need to know what you're looking for. The example in the article I mentioned is looking at the list of subscriptions for a given tenant:

    curl -X GET -H "Authorization: Bearer [TOKEN]" -H "Content-Type: application/json" https://management.azure.com/subscriptions/[SUBSCRIPTION_ID]/providers/Microsoft.Web/sites?api-version=2016-08-01

    Hope that helps.

    0 comments No comments