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

Fix: Contentful webhook body parse. #40732

Merged
merged 2 commits into from Sep 22, 2022
Merged

Fix: Contentful webhook body parse. #40732

merged 2 commits into from Sep 22, 2022

Conversation

anthonyshew
Copy link
Contributor

Bug

  • Related issues linked using fixes #number
  • Integration tests added
  • Errors have a helpful link attached, see contributing.md

Feature

  • Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
  • Related issues linked using fixes #number
  • Integration tests added
  • Documentation added
  • Telemetry added. In case of a feature if it's used or not.
  • Errors have a helpful link attached, see contributing.md

Documentation / Examples

  • Make sure the linting passes by running pnpm lint
  • The "examples guidelines" are followed from our contributing doc

@ijjk ijjk added the examples Issue/PR related to examples label Sep 20, 2022
@@ -14,7 +14,7 @@ export default async function handler(req, res) {
}

try {
let postSlug = req.body.fields.slug['en-US']
let postSlug = JSON.parse(req.body).fields.slug['en-US']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the content-type: application/json header not being sent with the Webhook request? If it is present it should already be parsing the req.body to JSON automatically.

x-ref:

if (type === 'application/json' || type === 'application/ld+json') {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't explicitly check headers but I've ran into this before with a webhook so I knew to try this pretty quickly. I can confirm that it goes from doesn't work to works with this change. 😬

I also quickly tried disabling bodyParser through export const config = { ... } to see if something else strange was going on but that also did not work as you'd expect.

I can go back and firm up the headers if needed!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally the content-type header is set from the Webhook although since we don't control it sounds alright to land

@kodiakhq kodiakhq bot merged commit ef9ba45 into vercel:canary Sep 22, 2022
@mitul-s
Copy link

mitul-s commented Sep 26, 2022

There’s a step in the README that tells you to update the header in Contentful to application/json

In other words, if you follow that then this is a breaking change. Spent a few hours today confused and trying to debug.

The README should be updated, or the PR should be reverted.

ijjk added a commit that referenced this pull request Sep 26, 2022
@ijjk
Copy link
Member

ijjk commented Sep 26, 2022

Good catch, added a note to that section of the readme instead here #40925 as it's definitely favorable to use the correct content-type header.

ijjk added a commit that referenced this pull request Sep 27, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
examples Issue/PR related to examples
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants