Composable Frontend 2.0 Learn more 

  • Commerce Cloud/
    Custom Data/
    Custom Data (Flows) API/
    Fields/
    Create a Field

    Create a Field

    POST Create a Field

    https://useast.api.elasticpath.com/v2/fields
    

    Custom names and values prefixed with $ are not supported.

    Parameters

    Headers

    NameRequiredTypeDescription
    AuthorizationRequiredstringThe Bearer token required to get access to the API.

    Body

    NameRequiredTypeDescription
    typeRequiredstringSpecifies the type of the resource object, use field.
    nameRequiredstringSpecifies the name of the field.
    slugRequiredstringSpecifies a unique slug identifier for the field.
    field_typeRequiredstringSpecifies the type of field, such as string, integer, boolean, float, date, relationship.
    descriptionRequiredstringSpecifies the description for this field.
    requiredRequiredbooleanSpecifies whether this field is required. The options are true or false. Use false if the field_type is a relationship.
    defaultOptionalUse the same type provided for field_typeSpecifies a default value for the field if no value is provided and the field is required.
    enabledRequiredbooleanSpecifies whether this field is enabled on the flow. The options are true or false.
    validation_rulesOptionalarray[object]Defines the validation rules to use with this field. For a list of rule types, see the validation rules section.
    orderOptionalintegerDenotes the order in which this field is returned relative to the rest of the flow fields.
    omit_nullOptionalbooleanSpecifies to omit this field from response if the value is null.
    relationshipsRequiredobjectSpecifies a relationship object to link this field to a flow.

    You can link a field to only one flow.

    You cannot update the field_type after creating a field.

    Request Examples

    Curl

    curl -X POST "https://useast.api.elasticpath.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"
                    },
                },
            },
        },
    }
    

    JavaScript SDK

    const 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",
                },
            },
        },
    };
    
    
    // Where `EPCC` is an authenticated client
    await EPCC.Fields.Create(data);
    

    Response Example

    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://useast.api.elasticpath.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": {
                "owner": "organization",
                "timestamps": {
                    "created_at": "2018-05-10T18:19:11.559Z",
                    "updated_at": "2018-05-10T18:19:11.559Z"
                }
            }
        }
    }
    
    Previous
    Get a Field