You have two options for updating a profile:

  • You can make a PATCH request to update some, but not all, the properties of a profile

  • You can make a PUT request to completely replace the contents of a profile

Patching a profile

You can use the following endpoint to change some, but not all, the properties of a profile:

  • PATCH /api/v2/user_profiles?identifier={identifier_query}
  • PATCH /api/v2/user_profiles/{profile_id}

If the profile is not found by identifier query or profile id, the request returns a 404 error.

Editable properties

You can update the following profile properties:

  • name
  • attributes

See Updating the attributes object.

You can also use a PATCH request to add identifiers to a profile. However, you can't update or delete existing identifiers. See Updating identifiers.

The following profile properties are read-only:

  • source
  • type
  • user_id

The properties are ignored in PATCH requests. If these properties were editable, updating them would create a different profile and possibly a different user in Zendesk. Use the PUT endpoints to create new profiles. See Creating profiles.

For more information on profile properties, see Anatomy of a profile.

Updating the attributes object

Include the new or updated properties in an attributes object in the request body. Example:

{  "profile": {    "attributes": {      "comm_pref": "email",      "joined": "2018"    }  }}

The attributes object in the request doesn't overwrite the attributes object in the profile. If a property in the request object doesn't exist in the profile object, the property is added. The other properties in the profile object are unaffected.

If a property in the request object exists in the profile object, the value of the property is updated in the profile object.

Updating identifiers

You can't use a PATCH request to update an existing identifier. Attempting to update one (such as updating an email address) adds a new identifier rather than update the existing one. If the identifier is a standard identifier type such as email or phone_number, a new identity is added to the Zendesk user record too.

If you want to change an identifier, you must completely replace the content of the profile. See Replacing a profile.

For example, if you want to delete an identifier to comply with data privacy laws, you must replace the existing profile with an updated version that doesn't include the identifier. See Complying with privacy and data protection laws.

Example

Data

  • Profile changes

    • Update name from "sunshine_user" to "Jane Doe"
    • Update saddle_height from "85cm" to "87cm"
  • Request path parameter:

    identifier=coolbikes:rider:email:jdoe@example.com
  • Request body in profile.json file:

    {    "profile": {      "name": "Jane Doe",      "attributes": {        "saddle_height": "87cm"      }    }  }

curl request

curl "https://coolbikes.zendesk.com/api/v2/user_profiles?identifier=coolbikes:rider:email:[email protected]" \  -d @profile.json \  -H "Content-Type: application/json" \  -v -u devs@coolbikes.com/token:6wiIBWbGkBMo1mRDMuVwkw1EPsNkeUj95PIz2akv -X PATCH

Python request

import json
import requests

identifier_query = 'coolbikes:rider:email:[email protected]'with open('profile.json', mode='r') as f:    profile = json.load(f)
url = 'https://coolbikes.zendesk.com/api/v2/user_profiles'params = {'identifier': identifier_query}headers = {'Content-Type': 'application/json'}api_token = '6wiIBWbGkBMo1mRDMuVwkw1EPsNkeUj95PIz2akv'credentials = '[email protected]/token', api_tokenresponse = requests.patch(url, params=params, json=profile, headers=headers, auth=credentials)if response.status_code != 200:    print(f'{response.status_code}: {response.text}')else:    print(response.json())

Response

Status 200
{  profile": {    "id":"01E06HXMJ8RJ6C0MR142D6FBSA",    "user_id":"81123613",    "source":"coolbikes",    "type":"rider",    "name":"Jane Doe",    "attributes":{      "favorite_color":"red",      "saddle_height":"87cm"    },    "created_at":"2020-02-03T22:14:48Z",    "updated_at":"2020-03-11T01:20:28Z",    "identifiers":[      {        "type":"email",        "value":"[email protected]"      }    ]  }}

Replacing a profile

You can use the following endpoints to replace the contents of a profile:

  • PUT /api/v2/user_profiles?identifier={identifier_query}
  • PUT /api/v2/user_profiles/{profile_id}
  • PUT /api/v2/users/{user_id}/profiles?identifier={identifier_query}

These are also the endpoints for creating profiles. See Creating profiles.

You must uniquely identify the profile with an identifier query or the profile's id. If no match is found using an identifier query, the API creates a separate profile.

If a profile is found, the API replaces the profile content but not the profile record. For example, the profile retains its profile id and created_at date. Events associated with the profile are unaffected.

Because the profile content is replaced, any data not included in the new version is lost. You can make a preliminary GET request to get the existing profile and merge the data into the new one. Also consider patching the profile instead of replacing it. See Patching a profile.

Example

Data

  • Profile changes

  • Request path parameter:

    identifier=coolbikes:rider:email:jdoe@example.com
  • Request body in profile.json file:

    {    "profile": {      "name": "Jane Doe",      "identifiers": [        {          "type": "email",          "value": "[email protected]"        }      ],      "attributes": {        "favorite_color": "red",        "saddle_height": "85cm"      }    }  }

curl request

curl "https://coolbikes.zendesk.com/api/v2/user_profiles?identifier=coolbikes:rider:email:[email protected]" \  -d @profile.json \  -H "Content-Type: application/json" \  -v -u devs@coolbikes.com/token:6wiIBWbGkBMo1mRDMuVwkw1EPsNkeUj95PIz2akv -X PUT

Python request

import json
import requests

identifier_query = 'coolbikes:rider:email:[email protected]'with open('profile.json', mode='r') as f:    profile = json.load(f)
url = 'https://coolbikes.zendesk.com/api/v2/user_profiles'params = {'identifier': identifier_query}headers = {'Content-Type': 'application/json'}api_token = '6wiIBWbGkBMo1mRDMuVwkw1EPsNkeUj95PIz2akv'credentials = '[email protected]/token', api_tokenresponse = requests.put(url, params=params, json=profile, headers=headers, auth=credentials)if response.status_code != 201:    print(f'{response.status_code}: {response.text}')else:    print(response.json())

Response

Status 201
{  profile": {    "id":"01E06HXMJ8RJ6C0MR142D6FBSA",    "user_id":"81123613",    "source":"coolbikes",    "type":"rider",    "name":"Jane Doe",    "attributes":{      "favorite_color":"red",      "saddle_height":"85cm"    },    "created_at":"2020-02-03T14:25:44Z",    "updated_at":"2020-03-11T22:20:28Z",    "identifiers":[      {        "type":"email",        "value":"[email protected]"      }    ]  }}