Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing values when creating entry from nodejs api #292

Closed
parik-ceb opened this issue Apr 2, 2020 · 2 comments
Closed

Missing values when creating entry from nodejs api #292

parik-ceb opened this issue Apr 2, 2020 · 2 comments

Comments

@parik-ceb
Copy link

parik-ceb commented Apr 2, 2020

Hi,
I was able to get the add entry with nodejs API work. I get a successful response but the issue is the values passed in the fields for the content type are not getting populated.

If you notice in the API response the field object is empty. Can anyone point me in the right direction?

The function to create entry:

async createEntry(contentTypeId = 'forms') {
const space = await this.client.getSpace(this.spaceId);
const environment = await space.getEnvironment('master');

const fields = {
  title: {
    'en-US': 'Test Form',
  },
  description: {
    'en-US': {
      content: {
        value: 'Adding a test form',
      },
    },
  },
};

const entry = await environment.createEntry(contentTypeId, fields);
return entry;
}

Response from API:

{ "sys": { "space": { "sys": { "type": "Link", "linkType": "Space", "id": "HIDDEN" } }, "id": "3xGT79qHgMTuOjc6i8cgGV", "type": "Entry", "createdAt": "2020-04-02T19:51:01.267Z", "updatedAt": "2020-04-02T19:51:01.267Z", "environment": { "sys": { "id": "master", "type": "Link", "linkType": "Environment" } }, "createdBy": { "sys": { "type": "Link", "linkType": "User", "id": "HIDDEN" } }, "updatedBy": { "sys": { "type": "Link", "linkType": "User", "id": "HIDDEN" } }, "publishedCounter": 0, "version": 1, "contentType": { "sys": { "type": "Link", "linkType": "ContentType", "id": "forms" } } }, "fields": {} }

@parik-ceb
Copy link
Author

After looking at the documentation https://www.contentful.com/developers/docs/references/content-management-api/#/reference/entries/entry/create-update-an-entry/console/js

I have removed environment and directly calling the function from
space.createEntry

still the same issue.

@parik-ceb
Copy link
Author

parik-ceb commented Apr 2, 2020

Found the issue I was not constructing the field object correctly. Here is the updated working code.

The function to create entry:

async createEntry(contentTypeId = 'forms') {
const space = await this.client.getSpace(this.spaceId);
const environment = await space.getEnvironment('master');

const fields = {
      fields: {
        title: {
          'en-US': 'Test Form',
        },
      },
    };

const entry = await environment.createEntry(contentTypeId, fields);
return entry;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant