REST API v4: POST collection fields
Method to add a field to an existing collection. This is an HTTP POST call to the following URL:
https://api.copernica.com/v4/collection/$id/fields
The $id
should be replaced by the ID of the collection you want to add a
field to. The name of the field and other values should be added to the
message body. After a successful call the ID of the created request is returned.
Available parameters
The following variables can be added to the body of the message:
- name: name of the new field (mandatory)
- description: the description of the new field
- type: type of the new field
- value: default value of the new field
- textlines: the amount of lines to use in text fields
- length: maximum length for text fields
- index: boolean value to indicate whether or not to make an index for the field
- displayed: boolean value to indicate whether or not field should be displayed to the user in lists or grids
- hidden: boolean value to indicate that a field should never be displayed to the user interface
- ordered: boolean value to indicate whether profiles should be ordered by this field by default
- lock: boolean value to indicate that the field can only be modified or deleted via the API
A field can have any of the following types:
- integer: numerical value
- float: numerical floating point number
- date: mandatory date field
- empty_data: non-mandatory date field
- datetime: mandatory date + time field
- empty_datetime: non-mandatory date + time field
- text: regular textfield
- email: field with email for mailings (maximum of 1 per database)
- phone: phone number field
- phone_gsm: mobile phone number field that can be used for sms messages (maximum of 1 per database)
- select: multiple choice field
- big: large textfield
- foreign_key: numerical value with reference to other profile
JSON example
The following JSON demonstrates how to use the API method:
{
"name": "text_field",
"type": "text",
"value": "this is a text field",
"displayed": true,
"ordered": false,
"length": 50,
"textlines": 1,
"hidden": false,
"index": false
}
PHP Example
The following PHP script demonstrates how to call the API method:
// dependencies
require_once('CopernicaRestAPI.php');
// change this into your access token
$api = new CopernicaRestAPI("your-access-token", 4);
// data to pass to the call
$data = array(
'name' => 'extra_field',
'type' => 'text'
);
// do the call
$api->post("collection/{$collectionID}/fields", $data);
// return id of created request if successful
The example above requires the CopernicaRestApi class.