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.

Calling getEntries right after a webook publish event doesn't always fetch the updated content

See original GitHub issue
  • Node Version: 8.11.1
  • Npm Version: 5.6.0
  • Platform: MacOS 10.13.4
  • Package Version: 6.1.0

I’m using the webhook system to know when an entry has been published in my space. The webhook works fine and I’m getting the event on my server. But then, when I get the event, I’m calling getEntries to fetch the data related to my entry and all the links, and most of the time, the data I get is the old data, not the new one. I’ve found out that if I wait at least 20 seconds before calling getEntries, it will work fine and I’ll receive my updated data.

Any reason why calling getEntries when receiving the webhook result in out of date data?

The issue is particularly present when, on the webhook event, I need to fetch the parents entries (using links_to_entry, and finally calling getEntries on the final entries id. So the flow might be like this:

  1. Receive webhook publish event
  2. Calling getEntries with links_to_entry equals to the webhook entry id.
  3. Potentially calling 2) multiple times
  4. Once I have the entries I need, I’m calling getEntries again, but this time with include and sys.id set to what I need.
  5. Notice that the result of 4) is not the updated content, but the old one. [Unless I wait 20 seconds before doing 4)]

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
ilkkacommented, May 30, 2018

Won’t start a long discussion here, but @tleunen the method I described works for us with immediate updates, so no waiting for a sync. The downside is that we end up essentially maintaining a content cache (a microservice that does a full sync on boot and then incremental updates), but it lets us do our own tricks with how we resolve content for our UIs while still being able to use contentful’s tools for managing it.

0reactions
tleunencommented, May 30, 2018

@ilkka Do you mean that the sync api doesn’t have the same limitations than the delivery api (waiting x seconds for the changes to be propagated)?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Content Management API | Contentful
You should always update resources in the following order: Fetch current resource. Make changes to the current resource. Update the resource by passing...
Read more >
Best practices for using webhooks | Stripe Documentation
Implement these best practices when using webhooks. ... Fetching older events by calling /v1/events using a newer API version also has no impact...
Read more >
What is a webhook and why do you need it? - Mailjet
We'll compare API calls to webhooks, walk through some examples, ... so your system can be updated right when the event takes place....
Read more >
How to use API-first platforms to build your websites faster
The tutorial consists of 2 parts: The first will show you how to design the application to get a so-called happy path. We'll...
Read more >
When to Use Webhooks, WebSocket, Pub/Sub, and Polling
How webhooks work. Webhook communication is achieved by sending an HTTP request from a source application to a destination application. When an event...
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