0

I have created a content in contentful.com. Was going through the api document, I tried the GET API to access the content, but i don't see edit/update content API anywhere in the document. Has anyone got any solution for it?

I found a document https://www.contentful.com/developers/docs/references/content-management-api/#/introduction/updating-content This document says "Contentful doesn't merge changes made to content, so when updating content, you need to send the entire body of an entry."

For which i made a GET call a gathered the entire body. But I dont see status in the whole body which i need to upgrade.

Below is the content's body:

    {
        "metadata": {
            "tags": []
        },
        "sys": {
            "space": {
                "sys": {
                    "type": "Link",
                    "linkType": "Space",
                    "id": "fdgre4353"
                }
            },
            "id": "xzvcfd5434",
            "type": "Entry",
            "createdAt": "2023-04-14T05:46:22.768Z",
            "updatedAt": "2023-04-14T05:47:27.521Z",
            "environment": {
                "sys": {
                    "id": "master",
                    "type": "Link",
                    "linkType": "Environment"
                }
            },
            "revision": 2,
            "contentType": {
                "sys": {
                    "type": "Link",
                    "linkType": "ContentType",
                    "id": "carousal"
                }
            },
            "locale": "en-US"
        },
        "fields": {
            "name": "Test-by-dnt",
            "panels": [
                {
                    "sys": {
                        "type": "Link",
                        "linkType": "Entry",
                        "id": "dsfw4e54332432fvdf"
                    }
                },
                {
                    "sys": {
                        "type": "Link",
                        "linkType": "Entry",
                        "id": "dsfvdft5e4tr43fg"
                    }
                }
            ]
        }
    }

1 Answers1

0

In the body that you send in the PUT request, you need to change the content you wish to update. For example, for one of my entries, I received the following output:

{
    "metadata": {
        "tags": []
    },
    "sys": {
        "space": {
            "sys": {
                "type": "Link",
                "linkType": "Space",
                "id": "SPACE"
            }
        },
        "id": "ENTRY_ID",
        "type": "Entry",
        "createdAt": "2022-09-09T09:30:29.716Z",
        "updatedAt": "2023-04-20T12:29:26.770Z",
        "environment": {
            "sys": {
                "id": "master",
                "type": "Link",
                "linkType": "Environment"
            }
        },
        "publishedVersion": 9,
        "publishedAt": "2023-04-20T12:29:26.770Z",
        "firstPublishedAt": "2022-09-09T09:30:31.408Z",
        "createdBy": {
            "sys": {
                "type": "Link",
                "linkType": "User",
                "id": "ENTRY_ID"
            }
        },
        "updatedBy": {
            "sys": {
                "type": "Link",
                "linkType": "User",
                "id": "ENTRY_ID"
            }
        },
        "publishedCounter": 5,
        "version": 10,
        "publishedBy": {
            "sys": {
                "type": "Link",
                "linkType": "User",
                "id": "ENTRT_ID"
            }
        },
        "automationTags": [],
        "contentType": {
            "sys": {
                "type": "Link",
                "linkType": "ContentType",
                "id": "blogPost"
            }
        }
    },
    "fields": {
        "title": {
            "en-US": "Automate with webhooks"
        },
        "slug": {
            "en-US": "automate-with-webhooks"
        },
        "heroImage": {
            "en-US": {
                "sys": {
                    "type": "Link",
                    "linkType": "Asset",
                    "id": "ASSET_ID"
                }
            }
        },
        "description": {
            "en-US": {
                "data": {},
                "content": [
                    {
                        "data": {},
                        "content": [
                            {
                                "data": {},
                                "marks": [],
                                "value": "Webhooks notify you, another person or system when resources have changed by calling a given HTTP endpoint.",
                                "nodeType": "text"
                            }
                        ],
                        "nodeType": "paragraph"
                    }
                ],
                "nodeType": "document"
            }
        },
        "body": {
            "en-US": {
                "data": {},
                "content": [
                    {
                        "data": {},
                        "content": [
                            {
                                "data": {},
                                "marks": [],
                                "value": "What are webhooks?",
                                "nodeType": "text"
                            }
                        ],
                        "nodeType": "heading-2"
                    },
                    {
                        "data": {},
                        "content": [
                            {
                                "data": {},
                                "marks": [],
                                "value": "The webhooks are used to notify you when content has been changed. Specify a URL, configure your webhook, and we will send an HTTP POST request whenever something happens to your content.",
                                "nodeType": "text"
                            }
                        ],
                        "nodeType": "paragraph"
                    },
                    {
                        "data": {},
                        "content": [
                            {
                                "data": {},
                                "marks": [],
                                "value": "How do I configure a webhook?",
                                "nodeType": "text"
                            }
                        ],
                        "nodeType": "heading-2"
                    },
                    {
                        "data": {},
                        "content": [
                            {
                                "data": {},
                                "marks": [],
                                "value": "Go to Settings → Webhooks from the navigation bar at the top. From there, hit Add webhook, and you will be directed to your new webhook. Then choose a name, put in the information of your HTTP endpoint (URL and authentication), specify any custom headers and select the types of events that should trigger the webhook.",
                                "nodeType": "text"
                            }
                        ],
                        "nodeType": "paragraph"
                    },
                    {
                        "data": {},
                        "content": [
                            {
                                "data": {},
                                "marks": [],
                                "value": "Why do I get an old version in the CDA?",
                                "nodeType": "text"
                            }
                        ],
                        "nodeType": "heading-2"
                    },
                    {
                        "data": {},
                        "content": [
                            {
                                "data": {},
                                "marks": [],
                                "value": "As the delivery API is powered by a CDN network consisting of hundreds of servers distributed across continents, it takes some time (up to a few minutes) to reflect the changes to the published content. This must be taken into consideration when reacting to webhooks. In normal conditions, there could be a reasonable delay of 2 to 5 minutes.",
                                "nodeType": "text"
                            }
                        ],
                        "nodeType": "paragraph"
                    },
                    {
                        "data": {},
                        "content": [
                            {
                                "data": {},
                                "marks": [],
                                "value": "Extracted from the ",
                                "nodeType": "text"
                            },
                            {
                                "data": {
                                    "uri": "https://www.contentful.com/faq/webhooks/"
                                },
                                "content": [
                                    {
                                        "data": {},
                                        "marks": [],
                                        "value": "Webhooks FAQ",
                                        "nodeType": "text"
                                    }
                                ],
                                "nodeType": "hyperlink"
                            },
                            {
                                "data": {},
                                "marks": [],
                                "value": ".",
                                "nodeType": "text"
                            }
                        ],
                        "nodeType": "paragraph"
                    }
                ],
                "nodeType": "document"
            }
        },
        "author": {
            "en-US": {
                "sys": {
                    "type": "Link",
                    "linkType": "Entry",
                    "id": "ENTRY_ID"
                }
            }
        },
        "publishDate": {
            "en-US": "2017-05-12T00:00+02:00"
        },
        "tags": {
            "en-US": [
                "javascript"
            ]
        },
        "disabled": {
            "en-US": true
        },
        "jurisdiction": {
            "en-US": "Amsterdam"
        }
    }
}

Now that I want to update only the title, this is what I send in the body (I just update the title, the rest remains the same):

{
    "metadata": {
        "tags": []
    },
    "sys": {
        "space": {
            "sys": {
                "type": "Link",
                "linkType": "Space",
                "id": "SPSCE"
            }
        },
        "id": "ENTRY_ID",
        "type": "Entry",
        "createdAt": "2022-09-09T09:30:29.716Z",
        "updatedAt": "2023-04-20T12:29:26.770Z",
        "environment": {
            "sys": {
                "id": "master",
                "type": "Link",
                "linkType": "Environment"
            }
        },
        "publishedVersion": 9,
        "publishedAt": "2023-04-20T12:29:26.770Z",
        "firstPublishedAt": "2022-09-09T09:30:31.408Z",
        "createdBy": {
            "sys": {
                "type": "Link",
                "linkType": "User",
                "id": "ENTRY_ID"
            }
        },
        "updatedBy": {
            "sys": {
                "type": "Link",
                "linkType": "User",
                "id": "ENTRY_ID"
            }
        },
        "publishedCounter": 5,
        "version": 10,
        "publishedBy": {
            "sys": {
                "type": "Link",
                "linkType": "User",
                "id": "ENTRY_ID"
            }
        },
        "automationTags": [],
        "contentType": {
            "sys": {
                "type": "Link",
                "linkType": "ContentType",
                "id": "blogPost"
            }
        }
    },
    "fields": {
        "title": {
            "en-US": "Automate Everything!!!!"
        },
        "slug": {
            "en-US": "automate-with-webhooks"
        },
        "heroImage": {
            "en-US": {
                "sys": {
                    "type": "Link",
                    "linkType": "Asset",
                    "id": "ENTRY_ID"
                }
            }
        },
        "description": {
            "en-US": {
                "data": {},
                "content": [
                    {
                        "data": {},
                        "content": [
                            {
                                "data": {},
                                "marks": [],
                                "value": "Webhooks notify you, another person or system when resources have changed by calling a given HTTP endpoint.",
                                "nodeType": "text"
                            }
                        ],
                        "nodeType": "paragraph"
                    }
                ],
                "nodeType": "document"
            }
        },
        "body": {
            "en-US": {
                "data": {},
                "content": [
                    {
                        "data": {},
                        "content": [
                            {
                                "data": {},
                                "marks": [],
                                "value": "What are webhooks?",
                                "nodeType": "text"
                            }
                        ],
                        "nodeType": "heading-2"
                    },
                    {
                        "data": {},
                        "content": [
                            {
                                "data": {},
                                "marks": [],
                                "value": "The webhooks are used to notify you when content has been changed. Specify a URL, configure your webhook, and we will send an HTTP POST request whenever something happens to your content.",
                                "nodeType": "text"
                            }
                        ],
                        "nodeType": "paragraph"
                    },
                    {
                        "data": {},
                        "content": [
                            {
                                "data": {},
                                "marks": [],
                                "value": "How do I configure a webhook?",
                                "nodeType": "text"
                            }
                        ],
                        "nodeType": "heading-2"
                    },
                    {
                        "data": {},
                        "content": [
                            {
                                "data": {},
                                "marks": [],
                                "value": "Go to Settings → Webhooks from the navigation bar at the top. From there, hit Add webhook, and you will be directed to your new webhook. Then choose a name, put in the information of your HTTP endpoint (URL and authentication), specify any custom headers and select the types of events that should trigger the webhook.",
                                "nodeType": "text"
                            }
                        ],
                        "nodeType": "paragraph"
                    },
                    {
                        "data": {},
                        "content": [
                            {
                                "data": {},
                                "marks": [],
                                "value": "Why do I get an old version in the CDA?",
                                "nodeType": "text"
                            }
                        ],
                        "nodeType": "heading-2"
                    },
                    {
                        "data": {},
                        "content": [
                            {
                                "data": {},
                                "marks": [],
                                "value": "As the delivery API is powered by a CDN network consisting of hundreds of servers distributed across continents, it takes some time (up to a few minutes) to reflect the changes to the published content. This must be taken into consideration when reacting to webhooks. In normal conditions, there could be a reasonable delay of 2 to 5 minutes.",
                                "nodeType": "text"
                            }
                        ],
                        "nodeType": "paragraph"
                    },
                    {
                        "data": {},
                        "content": [
                            {
                                "data": {},
                                "marks": [],
                                "value": "Extracted from the ",
                                "nodeType": "text"
                            },
                            {
                                "data": {
                                    "uri": "https://www.contentful.com/faq/webhooks/"
                                },
                                "content": [
                                    {
                                        "data": {},
                                        "marks": [],
                                        "value": "Webhooks FAQ",
                                        "nodeType": "text"
                                    }
                                ],
                                "nodeType": "hyperlink"
                            },
                            {
                                "data": {},
                                "marks": [],
                                "value": ".",
                                "nodeType": "text"
                            }
                        ],
                        "nodeType": "paragraph"
                    }
                ],
                "nodeType": "document"
            }
        },
        "author": {
            "en-US": {
                "sys": {
                    "type": "Link",
                    "linkType": "Entry",
                    "id": "ENTRY_ID"
                }
            }
        },
        "publishDate": {
            "en-US": "2017-05-12T00:00+02:00"
        },
        "tags": {
            "en-US": [
                "javascript"
            ]
        },
        "disabled": {
            "en-US": true
        },
        "jurisdiction": {
            "en-US": "Amsterdam"
        }
    }
}

Note that in your request, you also need to pass the X-Contentful-Version header. The GET response provides the current version of the entry.

Hope this helps.

harshil1712
  • 156
  • 4