Freigeben über


Did you get a “License assignment cannot be done for user with invalid usage location.” error when applying a license via Graph API?

One of the new features that was added on the 2013-11-08 release of Graph API is support for user licensing. If you happen to create your users via Graph API but fail to set the usageLocation property, you will run into the “License assignment cannot be done for user with invalid usage location. ” error.

There are 3 ways you can set the usageLocation. First, you can set it via the Office 365 Portal. You will need to set the User Location in the Office 365 Portal because you currently cannot set this via the Windows Azure Portal as it is unavailable.

image

The second way would be to use the Microsoft Online Services PowerShell . If you are familiar with the Microsoft Online Services PowerShell cmdlets, you simply call the Set-MsolUser cmdlet and pass the parameter UsageLocation and specify the 2 letter country code that you want to use.

For example, if you want to set the usage location to United States for all the users, you simply invoke the following cmdlet:

       Get-MsolUser -All | Set-MsolUser -UsageLocation US

Click the link for the table for the 2 letter country code values for the usage location property.

Last, you can set the usageLocation via the Graph API.

 PATCH https://graph.windows.net/contoso.onmicrosoft.com/users/Alex@contoso.onmicrosoft.com?api-version=2013-04-05 HTTP/1.1
Authorization: Bearer eyJ0eX ... FWSXfwtQ

Content-Type: application/json

Host: graph.windows.net

Content-Length: 59
{
    "usageLocation":"US"
}

NOTES:

Some regions may have local laws and restrictions that does not allow the use of the product being licensed. If this is the case, although you may have specified a usage location for the user, the license being applied will be blocked in order to comply with the local laws, therefore you will still get the error for this restricted region.