Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Azure AD API POST

Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
You are on page 1of 4

Sure, I can give you some examples of POST requests with Azure AD concerning the resource users.

According to the Azure AD Graph API documentation¹, you can perform various operations on users
using POST requests, such as:

- Creating a new user

- Assigning a manager to a user

- Adding a user to a group

- Assigning an app role to a user

- Resetting a user's password

For each operation, you need to specify the URI of the resource, the HTTP method (POST), the
access token, and the request body with the relevant data. For example, if you want to assign a
manager to a user using a POST request, you can use the following syntax¹:

```http

POST https://graph.windows.net/myorganization/users/{user_id}/manager/$ref?api-version=1.6

Authorization: Bearer {access_token}

Content-Type: application/json

    "url": "https://graph.windows.net/myorganization/users/{manager_id}"

```

Source : conversation avec Bing, 18/03/2023(1) Azure AD Graph API Operations on Users |
Microsoft Learn. https://learn.microsoft.com/fr-fr/previous-versions/azure/ad/graph/api/users-
operations Consultée 18/03/2023.

(2) Tutorial: Azure AD SSO integration with Postman - Microsoft Entra.


https://learn.microsoft.com/en-us/azure/active-directory/saas-apps/postman-tutorial Consultée
18/03/2023.

(3) Azure REST API reference documentation | Microsoft Learn.


https://learn.microsoft.com/en-us/rest/api/azure/ Consultée 18/03/2023.
Hello, this is Bing. Azure AD supports various POST request operations such as creating, updating,
or deleting resources¹. To perform a POST request operation with Azure AD, you need to specify the
following parameters¹²:

- The URI of the resource you want to access

- The HTTP method (POST) and any additional header fields

- The access token for authentication and authorization

- The request body with the data you want to send

For example, if you want to create a new user in Azure AD using a POST request operation, you can
use the following syntax³:

```csharp

// Create a HttpClient object

HttpClient client = new HttpClient();

// Set the URI of the resource (Azure AD Graph API endpoint for creating a user)

string uri = "https://graph.windows.net/myorganization/users?api-version=1.6";

// Set the HTTP method (POST) and the content type header

HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, uri);

request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

// Set the access token for authentication and authorization

request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

// Create a user object with some properties

User user = new User();

user.accountEnabled = true;
user.displayName = "Alex Wu";

user.mailNickname = "AlexW";

user.passwordProfile = new PasswordProfile();

user.passwordProfile.password = "Test1234";

user.passwordProfile.forceChangePasswordNextLogin = false;

user.userPrincipalName = "AlexW@contoso.onmicrosoft.com";

// Serialize the user object into JSON format and set it as the request body

string json = JsonConvert.SerializeObject(user);

request.Content = new StringContent(json, Encoding.UTF8, "application/json");

// Send the request and get the response asynchronously

HttpResponseMessage response = await client.SendAsync(request);

// Check if the request was successful and display some information

if (response.IsSuccessStatusCode)

        Console.WriteLine("User created successfully.");

        Console.WriteLine("Request content: {0}", json);

        Console.WriteLine("Response content: {0}", await response.Content.ReadAsStringAsync());

else

        Console.WriteLine("Error occurred: {0}", response.ReasonPhrase);

```
Source : conversation avec Bing, 18/03/2023(1) Azure REST API reference documentation |
Microsoft Learn. https://learn.microsoft.com/en-us/rest/api/azure/ Consultée 18/03/2023.

(2) HTTP with Azure AD - Connectors | Microsoft Learn.


https://learn.microsoft.com/en-us/connectors/webcontents/ Consultée 18/03/2023.

(3) How to call external api with Azure function with POST method with ....
https://stackoverflow.com/questions/69875752/how-to-call-external-api-with-azure-function-with-
post-method-with-request-body Consultée 18/03/2023.

You might also like