Fields

4
Last updated 20 hours ago

A Field represents a single Field of data (for example a Product Rating) to be applied to an entity. All Fields have a type (string, integer, boolean, date or relationship), a default value and an optional set of validation rules.

The Field Object

Attribute

Type

Description

id

string

The unique identifier for this field

type

string

Represents the type of object being returned

name

string

The name of the field

slug

string

A unique slug identifier for the field

field_type

string

This field is immutable and cannot be updated. The type of field - string, integer, boolean, float, date, relationship

validation_rules

array[object]

See Flow Field Validation Rules

description

string

Any description for this field

required

boolean

true if required on input, false if not. Always false if the field_type is a relationship

unique

boolean

true if each entry should be unique, false if not

default

mixed

A default value if none is supplied and field is not required

enabled

boolean

If this field is enabled on the flow this should be true, otherwise false

order

integer

Denotes the order in which this field is returned relative to the rest of the flow fields

relationships

object

A relationship object to link this field to a flow

omit_null

boolean

Hide this field from responses if the value is null

get
Get all Fields

https://api.moltin.com
/v2/fields
Request
Response
Headers
Authorization
required
string
The Bearer token to grant access to the API
200: OK
{
"data": [
{
"id": "e88d03d3-d46e-40d0-8302-25e6b5b1bd33",
"type": "field",
"field_type": "boolean",
"slug": "on_sale",
"name": "On Sale?",
"description": "Is this on sale?",
"required": false,
"unique": false,
"default": null,
"enabled": true,
"order": null,
"omit_null": false,
"validation_rules": [],
"links": {
"self": "https://api.moltin.com/v2/flows/9d69c6cf-aaee-4dc6-8908-d2bd053446a2/fields/e88d03d3-d46e-40d0-8302-25e6b5b1bd33"
},
"relationships": {
"flow": {
"data": {
"id": "9d69c6cf-aaee-4dc6-8908-d2bd053446a2",
"type": "flow"
}
}
},
"meta": {
"timestamps": {
"created_at": "2018-08-23T10:28:43.609Z",
"updated_at": "2018-08-23T10:28:43.609Z"
}
}
}
]
}
cURL
JavaScript SDK
curl https://api.moltin.com/v2/fields \
-H "Authorization: Bearer XXXX"
const MoltinGateway = require('@moltin/sdk').gateway
const Moltin = MoltinGateway({
client_id: 'X'
})
Moltin.Fields.All().then(fields => {
// Do something
})

get
Get all Fields by Flow

https://api.moltin.com
/v2/flows/:slug/fields
Request
Response
Path Parameters
slug
required
string
The slug of the Flow you wish to return fields for
Headers
Authorization
required
string
The Bearer token to grant access to the API
200: OK
{
"data": [
{
"id": "23d26fd2-d2e2-4c72-b4b4-3ef7a31bc47f",
"type": "field",
"field_type": "string",
"slug": "background_colour",
"name": "background colours",
"description": "background colour for the product",
"required": false,
"unique": false,
"default": "#ffffff",
"enabled": true,
"validation_rules": [],
"order": null,
"omit_null": false,
"links": {
"self": "https://api.moltin.com/v2/flows/248c7776-bd9f-4075-8980-461b02ed3757/fields/23d26fd2-d2e2-4c72-b4b4-3ef7a31bc47f"
},
"relationships": {
"flow": {
"data": {
"id": "248c7776-bd9f-4075-8980-461b02ed3757",
"type": "flow"
}
}
},
"meta": {
"timestamps": {
"created_at": "2017-06-26T12:55:33.560Z",
"updated_at": "2017-12-19T12:31:24.570Z"
}
}
},
{
"id": "5f4be5bd-0c83-417a-b744-7d8c49636ab1",
"type": "field",
"field_type": "string",
"slug": "background_image",
"name": "Background Image",
"description": "The background image for the category",
"required": false,
"unique": false,
"default": null,
"enabled": true,
"validation_rules": [],
"order": null,
"omit_null": false,
"links": {
"self": "https://api.moltin.com/v2/flows/248c7776-bd9f-4075-8980-461b02ed3757/fields/5f4be5bd-0c83-417a-b744-7d8c49636ab1"
},
"relationships": {
"flow": {
"data": {
"id": "248c7776-bd9f-4075-8980-461b02ed3757",
"type": "flow"
}
}
},
"meta": {
"timestamps": {
"created_at": "2018-03-29T10:33:24.056Z",
"updated_at": "2018-03-29T10:33:24.056Z"
}
}
}
]
}
cURL
curl https://api.moltin.com/v2/flows/:slug/fields \
-H "Authorization: Bearer XXXX"

get
Get a Field

https://api.moltin.com
/v2/fields/:id
Request
Response
Path Parameters
id
required
string
The ID for the field you are requesting
Headers
Authorization
required
string
The Bearer token to grant access to the API
200: OK
{
"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,
"unique": 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"
}
}
}
}
cURL
JavaScript SDK
curl https://api.moltin.com/v2/fields/:id \
-H "Authorization: Bearer XXXX"
const MoltinGateway = require('@moltin/sdk').gateway
const Moltin = MoltinGateway({
client_id: 'X'
})
const fieldID = 'XXXX';
Moltin.Fields.Get(fieldID).then(field => {
// Do something
})

post
Create a Field

https://api.moltin.com
/v2/fields
Request
Response
Headers
Authorization
required
string
The Bearer token to grant access to the API
Body Parameters
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
unique
optional
boolean
true if each entry should be unique, false if not
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
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,
"unique": 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"
}
}
}
}

You cannot update the field_type once a Field has been created.

cURL
JavaScript SDK
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,
"unique": 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
})

put
Update a Field

https://api.moltin.com
/v2/fields/:id
Request
Response
Path Parameters
id
required
string
The ID for the field you are requesting to be updated
Headers
Authorization
required
string
The Bearer token to grant access to the API
Body Parameters
type
required
string
Represents the type of object being returned
name
optional
string
The name of the field
slug
optional
string
A unique slug identifier for the field
description
optional
string
Any description for this field
required
optional
boolean
true if required on input, false if not. Always false if the field_type is a relationship
unique
optional
boolean
true if each entry should be unique, false if not
default
optional
string
A default value if none is supplied and field is not required
enabled
optional
boolean
If this field is enabled on the flow this should be true, otherwise false
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
optional
object
A relationship object to link this field to a flow
200: OK
{
"data": {
"id": "102b2087-d56a-45e7-bf1c-e9517716abb3",
"type": "field",
"field_type": "integer",
"slug": "start-of-life",
"name": "start-of-life",
"description": "day the iphone will work",
"required": true,
"unique": false,
"default": "2018-01-01",
"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:36:01.208Z"
}
}
}
}
cURL
JavaScript SDK
curl -X "POST" "https://api.moltin.com/v2/fields/:id" \
-H "Authorization: XXXX" \
-H "Content-Type: application/json" \
-d $'{
"data": {
"id": "{FIELD_ID}",
"type": "field",
"name": "Average Product Rating",
}
}'
const MoltinGateway = require('@moltin/sdk').gateway
const Moltin = MoltinGateway({
client_id: 'X'
})
const fieldId = 'xx'
const data = {
id: '{fieldId}',
name: 'Average Product Rating'
}
Moltin.Fields.Update('{fieldId}', data).then(field => {
// Do something
})

delete
Delete a Field

https://api.moltin.com
/v2/fields/:id
Request
Response
Path Parameters
id
required
string
The ID fir the field you are requesting to be deleted
Headers
Authorization
required
string
The Bearer token to grant access to the API
200: OK
cURL
JavaScript SDK
curl -X DELETE https://api.moltin.com/v2/fields/:id \
-H "Authorization: Bearer XXXX"
const MoltinGateway = require('@moltin/sdk').gateway
const Moltin = MoltinGateway({
client_id: 'X'
})
const fieldId = 'xx'
const data = {
id: '{fieldId}',
name: 'Average Product Rating'
}
Moltin.Fields.Delete('{fieldId}').then(response => {
// Do something
})