Reputation: 533
I have a 2 Content Models, A & B.
Model A has a 1-many reference to B.
I create A and publish, if I go back in and create B on A, A becomes 'changed' ( draft/unpublished ) and the new B is also unpublished.
I have a webhook that fires off on a B creation event. I need to grab A's information in this webhook using B.
Using Contentful's Node Libraries to try and grab entries using links_to_entry
will work when published and on a On Published to event
const entries = await this.contentfulDeliveryClient.getEntries({
links_to_entry: <id of entry sent in webhook>,
});
When I try to use the Content Preview Client, it finds my unpublished B , but using links_to_entry does not work to find it's parent A..... because its changed/draft/unpublished? But shouldn't the CPA still find it?
Upvotes: 0
Views: 533
Reputation: 533
The issue has nothing to do with the API's per say, but in the actual Contentful system it seems.
The Webhook is fired instantly on the Create event and when using the CPA almost instantly after to retrieve the linked data, it seems that Contentful's system hasn't yet updated or refreshed?
Placing a setTimeout() around 5 seconds or more and checking for the entries with links_to_entry for the entry I just created will yield the result I am expecting.
May have to leave a timeout or set up async workers to retry method a few times .
Upvotes: 0