Clear a Userfield Value

Last modified on September 11, 2023 at 2:14 pm

Overview

To clear a userfield value, you can send an HTTP PUT request to the userfield values URL with a JSON object whose property names are the ids of the userfields to update for the current user, and whose values are null. Cleared fields will be removed, so subsequent GET requests for the userfield values for that user will no longer include the cleared field until a new value has been assigned.

Note that you are not limited to clearing one field at a time; all existing fields may be cleared in a single request. All fields not included will retain their current value.

Headers

These are the HTTP headers that may be included in the POST request (not counting authentication information).

HeaderNotes
Accept
required
Indicates the content type you as the API client will accept in response from the server. Must be application/json.
Content-type
required
Indicates the content type you are providing to the server in your request. Must be application/json.
Host
required
Identifies the hostname the request is intended for. Should be api.digitalchalk.com.

Example

This example shows the request-response sequence when clearing two userfield values.

Request
PUT /dc/api/v5/users/8da97a97a92efd18dcbc12876a4510e/userfieldvalues HTTP/1.1
Host: api.digitalchalk.com
Content-type: application/json
Accept: application/json

{
  "23875210aceace7892feefd0m239213" : null,
  "09ebbca742233464128256512102420" : null
}
Response
HTTP/1.1 204 No Content

Failure Cases

Below is a list of the most common failure scenarios your code should be prepared to handle. This list is not exhaustive.

Validation error

Although you are clearing a userfield value, the validation step still runs. Since null is always an acceptable value, the remaining validation failure you may encounter is when you specify an unknown or invalid field id.

In the following example, the field with id 8da97a97a92efd18dcbc12876a4510e no longer exists.

Request
POST /dc/api/v5/users/8acefd64962420ad8dcbc12876a4510e/userfieldvaluesHTTP/1.1
Host: api.digitalchalk.com
Content-type: application/json
Accept: application/json

{
	"8da97a97a92efd18dcbc12876a4510e": null
}
Response
HTTP/1.1 400 Bad Request
Content-type: application/json
Content-length: 210

{
	"fieldErrors" : {
		"8da97a97a92efd18dcbc12876a4510e": "Invalid field id"
	}
}