Register an Application in Azure AD using the graph API

Viewed 2271

I am trying to register an application on the azure ad using the Graph API calls.

I am using the postman to hit the APIs and I have admin access in Azure.

So Far I have tried the following things:

  1. I registered an application manually on Azure AD using this doc- https://docs.microsoft.com/en-us/azure/databricks/dev-tools/api/latest/aad/service-prin-aad-token. (I gave all the required permissions to my application)

  2. I am fetching the token using the service to service call client credentials- https://docs.microsoft.com/en-us/azure/active-directory/azuread-dev/v1-oauth2-client-creds-grant-flow.

  3. After getting the token I pass it in the Authorization and hit the MS graph Create Application endpoint. https://docs.microsoft.com/en-us/graph/api/application-post-applications?view=graph-rest-1.0&tabs=http.

  4. But In the postman, I am not getting any response body. I have checked my Azure Tenant but I am not able to find any newly Registered App.

    For Token service(Get) Endpoint- https://login.microsoftonline.com/{my-tenant-id}/oauth2/token body- grant_type:client_credentials client_id:{app-id} scope:https://graph.microsoft.com/.default client_secret:{secret} //resource:https://graph.microsoft.com Response success(200) with token

    For Create App(POST) https://graph.microsoft.com/v1.0/applications body: { "displayName": "Created with MS Graph API" } Authorization: Bearer {token} Response: Nothing is showing in response

Response from API

2 Answers

I found the solution, In the API Header, I was specifying the Content-Length= 67 which was not required. Now I am able to get the Success response.

https://docs.microsoft.com/en-us/graph/api/application-post-applications?view=graph-rest-1.0&tabs=http

If we look at the MS documentation, They have provided the below example

POST https://graph.microsoft.com/v1.0/applications
Content-type: application/json
Content-length: 67

{
  "displayName": "Display name"
}

We don't need to pass the Content-Length in headers.

Related