question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Create new entry failing

See original GitHub issue

When creating an new entry as per guidelines https://contentful.github.io/contentful-management.js/contentful-management/3.3.4/typedef/index.html#static-typedef-Entry I get the following error: (getting the space works correctly - this error happens when invoking space.createEntry({}).

{ BadRequest: {
  "status": 400,
  "statusText": "Bad Request",
  "message": "Missing object",
  "details": {},
  "request": {
    "url": "https://api.contentful.com:443/spaces/myspace/entries",
    "headers": {
      "Accept": "application/json, text/plain, */*",
      "Content-Type": "application/vnd.contentful.management.v1+json",
      "X-Contentful-User-Agent": "contentful-management.js/3.3.4",
      "Authorization": "Bearer ACCESS_TOKEN",
      "user-agent": "node.js/v6.10.0",
      "Accept-Encoding": "gzip",
      "X-Contentful-Content-Type": {}
    },
    "method": "post"
  },
  "requestId": "removedforissue"
}

If I put content into body

space.createEntry({
      fields: {
        title: {'en-AU': slugThisMonth},
        body: {
          file: {'en-AU': pdfAssetId},
          effectiveDate: {'en-AU': new Date().toISOString()},
          name: {'en-AU': slugThisMonth}
        }
      },
    })

I get the following error (much the same, just with the extra body)

{ BadRequest: {
  "status": 400,
  "statusText": "Bad Request",
  "message": "Missing object",
  "details": {},
  "request": {
    "url": "https://api.contentful.com:443/spaces/myspace/entries",
    "headers": {
      "Accept": "application/json, text/plain, */*",
      "Content-Type": "application/vnd.contentful.management.v1+json",
      "X-Contentful-User-Agent": "contentful-management.js/3.3.4",
      "Authorization": "Bearer ACCESS_TOKEN",
      "user-agent": "node.js/v6.10.0",
      "Accept-Encoding": "gzip",
      "X-Contentful-Content-Type": {
        "fields": {
          "title": {
            "en-AU": "cf-April-2017"
          },
          "body": {
            "file": {
              "en-AU": "afileid"
            },
            "effectiveDate": {
              "en-AU": "2017-04-05T04:09:55.461Z"
            },
            "name": {
              "en-AU": "cf-April-2017"
            }
          }
        }
      }
    },
    "method": "post"
  },
  "requestId": "removedforissue"
}

Following the documentation at https://www.contentful.com/developers/docs/references/content-management-api/#/reference/entries leads to the same path.

I do have content types setup, in my space, and can’t determine how to create an entry within a content type - maybe this is what i’m missing?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
axe312gercommented, Apr 5, 2017

Ohh sorry, I overlooked that:

The first parameter of space.createEntry() is the content type as string, the second is your actual entry data.

Also, you need to create an asset first before you can attach it to the entry. (At least if you want to be present in the entry in the moment when the entry is created)

In total, it might later look like this:

space.createAsset({
  fields: {
    file: {
      'en-AU': { 
        contentType: 'image/jpeg',
        fileName: 'test.jpg',
        upload: 'http://www.example.com/test.jpg'
      }
    }
  }
})
.then(asset => asset.processForAllLocales())
.then(asset => asset.publish())
.then(function(asset) {
  return space.createEntry('doc', {
    fields: {
      file: {
        'en-AU': {
          sys: {
            id: asset.sys.id,
            linkType: 'Asset',
            type: 'Link'
          }
        }
      },
      effectiveDate: {'en-AU': new Date().toISOString()},
      name: {'en-AU': slugThisMonth},
      jiraId: {'en-AU': jiraId}
    },
  })
})
.then(function(entry) {
  console.log(entry)
})

Cheers, Benedikt

1reaction
bohdan-karapet-vaimocommented, Jul 4, 2022

Hi, my comment is a bit outdated) I faced with same error and found that we need to pass 2 arguments to createEntry - first one is content type id and second one is entry itself.

I use "contentful-management": "^10.6.3"

Example: space.createEntry('contentTypeId', { fields: { ... } })

In the example above you can see that entry JSON was added to “X-Contentful-Content-Type” header: "X-Contentful-Content-Type": { "fields": { "title": { "en-AU": "cf-April-2017" }, ... } }

But this header is responsible for content type, as per Contentful API examples (saw in Contentful trainig video).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Java - How to create new Entry (key, value) - Stack Overflow
I'd like to create new item that similarly to Util. Map. Entry that will contain the structure key , value . The problem...
Read more >
Solved: Failed to create a new item - Canvas Community
Solved: Hi! There are instances when I try to upload an item in the module, a pink dialog box appears saying "Failed to...
Read more >
Failed to Create New Entry for an Issue Because Conflicting ...
Cause. More than one row in the AO_60DB71_ISSUERANKING table exists for the custom field YYYYY, which is pointing to the issue XXXXX.
Read more >
create new record failed | Support Center
Hi, while creating a new record i'm getting error saying create new record failed: pxCreateRecord api failed.
Read more >
Action 'Create item' failed (Flow cannot create it...
Please check if you have filled proper value within fields of "Create item" action. Also please check if the data type of dynamic...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found