Create text userfield

Last modified on September 11, 2023 at 1:45 pm

Overview

Create a new custom text-type userfield by sending an HTTP POST request with JSON representing the text userfield to create. On success, the request will return HTTP 201 Created with a Location header pointing to the URL of the newly created userfield resource; otherwise, an appropriate error will be returned. See the failure cases section for more details.

JSON Object Definition

The following is the subset of the JSON object representing userfields applicable to the text userfield type.

{
  "type": "text",
  "name": "",
  "categoryName": "",
  "orderIndex": 0,
  "required": false,
  "constraints": {
    // constraint type : value,
    // ...
  }
}

Userfield Property Details

PropertyNotes
type
required
To create a text userfield, this property must be present and have the value text.
name
required
This property will be the default label on the user information form presented to the end-user.
categoryName
required
Sets the category the userfield is located within. To the end user, categories will appear as sections or groupings of userfields on the user information form. To create a category or retrieve a list of your existing categories, see the userfield category documentation.
orderIndexSpecifies what position the userfield appears in within its category. This should be an integer value greater than or equal to 0. If not provided, the userfield will be placed at the end of the category.
requiredSets whether the user must provide a value for this userfield. This should be a boolean true or false value.
constraintsA JSON object whose properties are the names of constraints with values representing the constraint limit. Text fields support the constraints minimumLength and maximumLength. The values for both of these constraints must be integer values greater than or equal to 0. Additionally, if you specify both a minimumLength and a maximumLength, the minimumLength constraint cannot be greater than the maximumLength constraint.

Examples

Create Custom Text Userfield

This example shows the creation of a custom user-visible text userfield with one localized name and one constraint.

Request
POST /dc/api/v5/userfields HTTP/1.1
Host: api.digitalchalk.com
Content-type: application/json
Accept: application/json

{
	"type": "text",
	"name": "Example Text Input",
	"categoryName": "5738aeadc3d0feaedcbc12876a4510e", 
	"required": true,
	"constraints": { "maximumLength": 10 }
}
Response
HTTP/1.1 201 Created 
Location: https://org.digitalchalk.com/dc/api/v5/userfields/877f00ced040feaedcbc12878679305
Content-length: 0

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

If there is no userfield resource located at the given URL, the server will issue a 400 Bad Request response with a JSON object in the response body. The object contains a message attribute describing the eror.

Request
POST /dc/api/v5/userfields HTTP/1.1
Host: api.digitalchalk.com
Content-type: application/json
Accept: application/json

{
	"type": "text",
	"name": "Example Text Input",
	"required": true,
	"constraints": { "maximumLength": 10 }
}
Response
HTTP/1.1 400 Bad Request
Content-type: application/json
Content-length: 210

{
	  fieldErrors: {
        categoryName: "required"
    }
}

References