Choose your language:
    Update a field
    Parameters
    defaultValue  boolean, null, string, number, object  Optional

    Default value for Field. When field is localized accepts an object of default values with site locales as keys

    label  string  Optional

    The label of the field

    apiKey  string  Optional

    Field API key

    localized  boolean  Optional

    Whether the field needs to be multilanguage or not

    validators  object  Optional

    Optional field validations

    appearance  object  Optional

    Field appearance details, plugin configuration and field add-ons

    position  integer  Optional

    Ordering index

    fieldType  string  Optional

    Type of input

    hint  string, null  Optional

    Field hint

    fieldset  null, fieldset.id  Required

    Fieldset linkage

    Returns
    Returns a field object.

    Examples

    Example code:
    const SiteClient = require('datocms-client').SiteClient;
    const client = new SiteClient('YOUR-API-TOKEN');
    const fieldIdOrApiKey = 'blog_post::title';
    client.field.update(fieldIdOrApiKey, {
    defaultValue: {
    en: 'A default value',
    it: 'Un valore di default'
    },
    label: 'Title',
    apiKey: 'title',
    localized: true,
    validators: {
    required: {}
    },
    appearance: {
    editor: 'single_line',
    parameters: {
    heading: false
    },
    addons: [
    {
    id: '1234',
    fieldExtension: 'lorem_ipsum',
    parameters: {}
    }
    ]
    },
    position: 1,
    fieldType: 'string',
    hint: 'This field will be used as post title',
    fieldset: null
    })
    .then((field) => {
    console.log(field);
    })
    .catch((error) => {
    console.error(error);
    });
    Returned output:
    > node example.js
    {
    "id": "124",
    "label": "Title",
    "fieldType": "string",
    "localized": true,
    "defaultValue": {
    "en": "A default value",
    "it": "Un valore di default"
    },
    "apiKey": "title",
    "hint": "This field will be used as post title",
    "validators": {
    "required": {}
    },
    "appearance": {
    "editor": "single_line",
    "parameters": {
    "heading": false
    },
    "addons": [
    {
    "id": "1234",
    "fieldExtension": "lorem_ipsum",
    "parameters": {}
    }
    ]
    },
    "position": 1,
    "itemType": "44",
    "fieldset": null
    }