Create a Field
POST
Create a Field
https://api.moltin.com/v2/fields
Headers:
Name | Required | Type | Description |
---|---|---|---|
Authorization | Required | string | The Bearer token to grant access to the API. |
Body:
Name | Required | Type | Description |
---|---|---|---|
type | Required | string | Represents the type of object being returned. |
name | Required | string | The name of the field. |
slug | Required | string | A unique slug identifier for the field. |
field_type | Required | string | The type of field - string , integer , boolean , float , date , relationship . |
description | Required | string | Any description for this field. |
required | Required | boolean | true if required on input, false if not. Always false if the field_type is a relationship. |
default | Optional | string | A default value if none is supplied and field is not required. |
enabled | Required | boolean | If this field is enabled on the flow this should be true , otherwise false . |
validation_rules | Optional | array[object] | Defines the validation rules to use with this field. For a list of rule types, see validation rules. |
order | Optional | integer | Denotes the order in which this field is returned relative to the rest of the flow fields. |
omit_null | Optional | boolean | Omit this field from responses if the value is null . |
relationships | Required | object | A relationship object to link this field to a flow. |
Please note that in this instance, you can link a field to only one flow.
201 Created
{
"data": {
"id": "102b2087-d56a-45e7-bf1c-e9517716abb3",
"type": "field",
"field_type": "integer",
"slug": "product-rating",
"name": "Product Rating",
"description": "Average rating as given by our users",
"required": false,
"default": null,
"enabled": true,
"validation_rules": [
{
"type": "between",
"options": {
"from": 1,
"to": 5
}
}
],
"order": 1,
"omit_null": false,
"links": {
"self": "https://api.moltin.com/v2/flows/6d320b42-237d-4474-8452-d49f884d4ae1/fields/102b2087-d56a-45e7-bf1c-e9517716abb3"
},
"relationships": {
"flow": {
"data": {
"id": "6d320b42-237d-4474-8452-d49f884d4ae1",
"type": "flow"
}
}
},
"meta": {
"timestamps": {
"created_at": "2018-05-10T18:19:11.559Z",
"updated_at": "2018-05-10T18:19:11.559Z"
}
}
}
}
warning
You cannot update the field_type
after a Field has been created.
curl -X POST "https://api.moltin.com/v2/fields" \
-H "Authorization: XXXX" \
-H "Content-Type: application/json" \
-d $'{
"data": {
"type": "field",
"name": "Product Rating",
"slug": "product-rating",
"field_type": "integer",
"validation_rules": [
{
"type": "between",
"options": {
"from": 1,
"to": 5
}
}
],
"description": "Average rating as given by our users",
"required": false,
"default": 0,
"enabled": true,
"order": 1,
"omit_null": false,
"relationships": {
"flow": {
"data": {
"type": "flow",
"id": "e4145c27-aba1-46af-81a3-58f5e1cf7f15"
}
}
}
}
}'
const MoltinGateway = require('@moltin/sdk').gateway
const Moltin = MoltinGateway({
client_id: 'X'
})
const data = {
name: 'Product Rating',
slug: 'product-rating',
description: 'Average rating as given by our users',
enabled: true
}
Moltin.Fields.Create(data).then(field => {
// Do something
})