Field with fielset always results in error

Hi!

We are trying to create a field and associate it to a previously created fieldset, but the same error continues to show.

ApiException: 422 INVALID_FORMAT (details: {"messages":["#/data/relationships/fieldset/data: failed schema #/definitions/field/links/0/schema/properties/data/properties/relationships/properties/fieldset/properties/data: No subschema in \"anyOf\" matched."]})

How the field and fieldset are created:

     const navigationKey = "navigation";

    // Create fieldset
    const styleFieldset = await client.fieldsets.create(navigationKey, {
        title: 'Style',
        hint: 'Some text here',
        position: 3,
        collapsible: true,
        startCollapsed: true
    });

    // Bg color
    await client.fields.create(navigationKey, {
        label: 'Background',
        apiKey: 'bg',
        hint: 'The background color of the navigation element',
        fieldType: 'color',
        localized: true,
        fieldset: { type: "fieldset", id: styleFieldset.id }
    });

For the field set we’ve also tried fieldset: { type: styleFieldset.itemType.id, id: styleFieldset.id }.

not sure what is wrong.

Hello @technology

apiKey should be api_key
and
fieldType should be field_type

You can read all of the parameter keys here: Create a new field - Field - Content Management API

That doens’t seem to be the problem. If I comment out the fieldset property from the creation, without changing camel case to underescore, the fields are created, but not associated to the fieldset.

    await client.fields.create(navigationKey, {
        label: 'Background',
        apiKey: 'bg',
        hint: 'The background color of the navigation element',
        fieldType: 'color',
        localized: true,
        //fieldset: { type: styleFieldset.itemType, id: styleFieldset.id }
    });

This creates all the fields just fine, but it doesn’t put them “inside” the fieldset. I tried your suggestion of:

    // Create fieldset
    const styleFieldset = await client.fieldsets.create(navigationKey, {
        title: 'Style',
        hint: 'Text here',
        position: 3,
        collapsible: true,
        start_collapsed: true
    });

    // Bg color
    await client.fields.create(navigationKey, {
        label: 'Background',
        api_key: 'bg',
        hint: 'The background color of the navigation element',
        field_type: 'color',
        localized: true,
        fieldset: { type: styleFieldset.itemType, id: styleFieldset.id }
       // Also tried --> fieldset: { type: "fieldset", id: styleFieldset.id }
    });
REQUEST

The format of the parameters passed is incorrect, take a look at the details of the error to know what's wrong! 

{"data":{"type":"field","attributes":{"label":"Background","field_type":"color","api_key":"bg","localized":true,"hint":"The background color of the navigation element"},"relationships":{"fieldset":{"data":{"type":"fieldset","id":{"type":"fieldset","id":"313889"}}}}}}

RESPONSE

{"data":[{"id":"92a3ea","type":"api_error","attributes":{"code":"INVALID_FORMAT","details":{"messages
":["#/data/relationships/fieldset/data: failed schema #/definitions/field/links/0/schema/properties/d
ata/properties/relationships/properties/fieldset/properties/data: No subschema in \"anyOf\" matched."
]}}}]}

@technology i see, can you send us the node, and datocms-client package version you are using to make the requests so we can take a closer look at it?

Sure thing!

“datocms-client”: “^3.4.7”, (actual installed 3.5.14)
“node”: v16.4.0

Thank you!

@technology that is the issue then: you are using the old Javascript client, and following the documentation for the new client to create fields and field-sets.

To install the new version of the JS client you can run

npm install @datocms/cma-client-node

and then build the client through

import { buildClient } from '@datocms/cma-client-node';
const client = buildClient({ apiToken: '<YOUR_TOKEN>' });

Or, if you want to keep the legacy JS client, you can, but you will need to follow the documentation under the “Legacy JS Client” tab:

1 Like