Restore a deleted user for a customer

Applies To

  • Partner Center

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


  • Credentials as described in Partner Center authentication. This scenario supports authentication with App+User credentials only.
  • A customer ID (customer-tenant-id). If you do not have a customer's ID, you can look up the ID in Partner Center by choosing the customer from the customers list, selecting Account, then saving their Microsoft ID.
  • The user ID. If you do not have the user ID, see View deleted users for a customer.

When can you restore a deleted user account?

The user state is set to "inactive" when you delete a user account. It remains that way for thirty 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 thirty day window. Note that 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).


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. Note that 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

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 must contain "active".
Attributes object N Contains "ObjectType": "CustomerUser".

Request example

Authorization: Bearer <token>
Accept: application/json
MS-RequestId: 6e668bc0-5bd7-44d6-b6fa-529d41ce9659
MS-CorrelationId: 32be760f-8282-4e01-a37b-829c8a700e8a
X-Locale: en-US
Content-Type: application/json
Content-Length: 269
Expect: 100-continue

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

REST Response

If successful, this method 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: 32be760f-8282-4e01-a37b-829c8a700e8a
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": "",
    "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"