Update user account with email unchanged using User Provisioning REST API
Asked by Mrinalini Pal:

I am trying to update a user account using User Provisioning REST API mentioned in the [https://developer.atlassian.com/cloud/admin/user-provisioning/rest/api-group-users/#api-scim-directory-directoryid-users-userid-put](https://developer.atlassian.com/cloud/admin/user-provisioning/rest/api-group-users/#api-scim-directory-directoryid-users-userid-put "update user") document.

* If no primary email is sent as the request body, I am getting "Invalid payload: One email address need to be marked as primary." error.
* If primary email is unchanged in the request body, I am getting success but the user details are not getting updated.
* If primary email is changed in the request body, I am getting success and the user details are getting updated.

I want to change the email of the user only when the user requests for a change otherwise I want the details to get updated having the same email. Is there any work-around or is this a bug?


Answers:
author: Shannon S
body: Hello Mrinalini,

Welcome to Atlassian Community! It's nice to have you join us.

Can you show us the query you're sending in REST-API? Please make sure to block out any private information since this is a public forum.

You might also want to try the [Atlassian Developer Community](https://community.developer.atlassian.com/). The main community is more end users, but the Developer community works with API regularly and may know what the problem is.

Thank you!  
Shannon

comments: author: Mrinalini Pal
body: Hi Shannon,

I am calling the following API :  
curl --request PUT \\  
--url '<https://api.atlassian.com/scim/directory/{directoryId}/Users/{userId>}' \\  
--header 'Authorization: Bearer \<access_token\>' \\  
--header 'Accept: application/json' \\  
--header 'Content-Type: application/json' \\  
--data '{  
"userName": "\<string\>",  
"emails": \[  
{  
"value": "\<string\>",  
"type": "\<string\>",  
"primary": true  
}  
\],  
"name": {  
"formatted": "\<string\>",  
"familyName": "\<string\>",  
"givenName": "\<string\>",  
"middleName": "\<string\>",  
"honorificPrefix": "\<string\>",  
"honorificSuffix": "\<string\>"  
},  
"displayName": "\<string\>",  
"nickName": "\<string\>",  
"title": "\<string\>",  
"preferredLanguage": "\<string\>",  
"department": "\<string\>",  
"organization": "\<string\>",  
"timezone": "\<string\>",  
"phoneNumbers": \[  
{  
"value": "\<string\>",  
"type": "\<string\>",  
"primary": true  
}  
\],  
"active": true  
}'

The data passed in emails.value is same as in the existing account with userId


author: Shannon S
body: Hello Mrinalini,

Thank you for your reply. If you need to update the user details without changing the email, you can [use PATCH instead](https://developer.atlassian.com/cloud/admin/user-provisioning/rest/api-group-users/#api-scim-directory-directoryid-users-userid-patch).

Can you try that and let me know if you have any trouble?

Shannon


author: Mrinalini Pal
body: Thank you Shannon. It works like a charm.


author: Shannon S
body: Hi Mrinalini,

That's great. Thank you for confirming. I'm happy to hear it worked.

Take care, and have a pleasant rest of your week.

Shannon


author: Tom Maes
body: Hello,

When we update a mail adres by the patch instead, we've get an 405 error: Method is not allowed.  
curl --request PATCH\\  
--url '[https://api.atlassian.com/scim/directory/{directoryId}/Users/{userId](https://api.atlassian.com/scim/directory/%7BdirectoryId%7D/Users/%7BuserId)}' \\  
--header 'Authorization: Bearer \<access_token\>' \\  
--header 'Accept: application/json' \\  
--header 'Content-Type: application/json' \\  
--data '{  
{  
"schemas":\[  
"urn:ietf:params:scim:api:messages:2.0:PatchOp"  
\],  
"operations": \[  
{  
"op": "replace",  
"path": "emails.value",  
"value": "{EMAIL}"  
}  
\]  
}  
}  
Result:  
{  
"timestamp": "2023-06-26T15:13:15.006+00:00",  
"status": 405,  
"error": "Method Not Allowed",  
"message": "Method Not Allowed",  
"path": "/api/scim/directory/{directory-id}/Users"  
}

comments: author: Shannon S
body: Hi Tom,

Good afternoon. Thanks for following up on this question. First, I edited your API call to remove identifying information. Please note this is an open forum, and the public can view anything you post here.

I understand you're getting a 405 Method Not Allowed error when you try to patch (change) an email address from one of your managed accounts.

Can you confirm you're using the organization admin API key? See [Manage an organization with the admin APIs](https://support.atlassian.com/organization-administration/docs/manage-an-organization-with-the-admin-apis/). This is different from [the key you generate for your user account](https://support.atlassian.com/atlassian-account/docs/manage-api-tokens-for-your-atlassian-account/).

If you can confirm you're using the org admin API key and not your user API key, I recommend [raising a ticket with the Atlassian Access support team](https://support.atlassian.com/contact/#/?inquiry_category=technical_issues&is_cloud=true&product_key=com.atlassian.identity-manager&support_type=customer).

Let me know if you have any trouble with that.

Take care,

Shannon S \| Atlassian Cloud support


Tags: account

cloud

confluence-cloud