Restore a deleted user for a customer

How to restore a deleted User by customer ID and user ID.

Prerequisites

  • Credentials as described in Partner Center authentication. This scenario supports authentication with App+User credentials only.

  • A customer ID (customer-tenant-id). If you don't know the customer's ID, you can look it up in Partner Center by selecting the Customers workspace, then the customer from the customer list, then Account. On the customer's Account page, look for the Microsoft ID in the Customer Account Info section. The Microsoft ID is the same as the customer ID (customer-tenant-id).

  • The user ID. If you do not have the user ID, see View deleted users for a customer.

GDAP roles

You'll need at least one of the following GDAP roles:

  • User Administrator
  • Directory Writer

Restore a deleted user account

The user state is set to "inactive" when you delete a user account. It remains that way for 30 days, after which the user account and its associated data are purged and made unrecoverable. You can only restore a deleted user account during this 30-day window. Once deleted and marked "inactive" the user account is no longer returned as a member of the user collection (for example, using Get a list of all user accounts for a customer).

C#

To restore a user, create a new instance of the CustomerUser class, and set the value of the User.State property to UserState.Active.

You restore a deleted user by setting the user's state to active. You do not have to repopulate the remaining fields in the user resource. Those values will automatically be restored from the deleted, inactive user resource. Next, use the IAggregatePartner.Customers.ById method with the customer ID to identify the customer, and the Users.ById method to identify the user.

Finally, call the Patch method and pass the CustomerUser instance to send the request to restore the user.

// IAggregatePartner partnerOperations;
// string selectedCustomerId;
// string selectedCustomerUserId;

var updatedCustomerUser = new CustomerUser()
{
    State = UserState.Active
};

// Restore customer user information.
var restoredCustomerUserInfo = partnerOperations.Customers.ById(selectedCustomerId).Users.ById(selectedCustomerUserId).Patch(updatedCustomerUser);

Sample: Console test app. Project: Partner Center SDK Samples Class: CustomerUserRestore.cs

REST request

Request syntax

Method Request URI
PATCH {baseURL}/v1/customers/{customer-tenant-id}/users/{user-id} HTTP/1.1

URI parameter

Use the following query parameters to specify the customer ID and user ID.

Name Type Required Description
customer-tenant-id guid Y The value is a GUID formatted customer-tenant-id that allows the reseller to filter the results to a given customer.
user-id guid Y The value is a GUID formatted user-id that belongs to a single user account.

Request headers

For more information, see Partner Center REST headers.

Request body

This table describes the required properties in the request body.

Name Type Required Description
State string Y The user state. To restore a deleted user, this string must contain "active".
Attributes object N Contains "ObjectType": "CustomerUser".

Request example

PATCH https://api.partnercenter.microsoft.com/v1/customers/4d3cf487-70f4-4e1e-9ff1-b2bfce8d9f04/users/a45f1416-3300-4f65-9e8d-f123b397a4ea HTTP/1.1
Authorization: Bearer <token>
Accept: application/json
MS-RequestId: 6e668bc0-5bd7-44d6-b6fa-529d41ce9659
MS-CorrelationId: aaaa0000-bb11-2222-33cc-444444dddddd
X-Locale: en-US
Content-Type: application/json
Host: api.partnercenter.microsoft.com
Content-Length: 269
Expect: 100-continue

{
    "State": "active",
    "Attributes": {
        "ObjectType": "CustomerUser"
    }
}

REST response

If successful, the response returns the restored user information in the response body.

Response success and error codes

Each response comes with an HTTP status code that indicates success or failure and additional debugging information. Use a network trace tool to read this code, error type, and additional parameters. For the full list, see Partner Center REST Error Codes.

Response example

HTTP/1.1 200 OK
Content-Length: 465
Content-Type: application/json; charset=utf-8
MS-CorrelationId: aaaa0000-bb11-2222-33cc-444444dddddd
MS-RequestId: 6e668bc0-5bd7-44d6-b6fa-529d41ce9659
MS-CV: ZTeBriO7mEaiM13+.0
MS-ServerId: 101112616
Date: Fri, 20 Jan 2017 22:24:55 GMT

{
    "usageLocation": "US",
    "id": "a45f1416-3300-4f65-9e8d-f123b397a4ea",
    "userPrincipalName": "e83763f7f2204ac384cfcd49f79f2749@dtdemocspcustomer005.onmicrosoft.com",
    "firstName": "Ferdinand",
    "lastName": "Filibuster",
    "displayName": "Ferdinand",
    "userDomainType": "none",
    "state": "active",
    "links": {
        "self": {
            "uri": "/customers/4d3cf487-70f4-4e1e-9ff1-b2bfce8d9f04/users/a45f1416-3300-4f65-9e8d-f123b397a4ea",
            "method": "GET",
            "headers": []
        }
    },
    "attributes": {
        "objectType": "CustomerUser"
    }
}