GET requests randomly returning 403 Forbidden

First of all, I am posting this under PHP because we use the PHP Kit to make our requests to the Prismic API. The problem might not be related to this kit, but to the API itself.
I've gone through all the other related posts on this matter and none of them seems to have a solution or explanation for this issue.

We basically keep only one ref (the master ref) to manage our content. Any updates made to our docs are published to the master ref or put into a scheduled release.
On every update, Prismic sends us the webhook notifying the update and then we request the document up to date to Prismic to make the appropriate updates on our side.
For reference, this is our piece of code (using the PHP Kit) that queries the document by ID:

    ->query(Predicates::at('', $prismicId))

This is the API call that randomly generates the following 403 response:

The GET request to the repository resulted in a 403 Forbidden error. Complete URL:

And I have no idea why. I have followed the API and Kit documentation step by step and I cannot find what exactly we're doing wrong.
When this happens, the content doesn't get updated on our side and to fix it we have to go to the Prismic dashboard and republish the same document, and then it works. We received this 403 response three times in the past 2 weeks.

Are we missing something here?

Hi @sulpriv,

Thanks for reaching out.

It seems that the issue is that probably to are caching the master ref (can you confirm how you store the master ref), master refs change periodically, and it is not a good idea to provide it manually.
The Prismic client will get the master ref for you automatically if you don't provide it by calling the /api Prismic endpoint

You can also have a look at our PHP documentation

Can you try to remove this line of code and monitor your application for new errors?

Looking forward to your response,

We don't store the master ref, we always pass it to the queries in order to 'force' the latest one to be used. We recently added that bit.

But I will do as per your suggestion and remove that piece of code.

Just for clarification, we instantiate the client for each webhook request. So for scheduled releases with more than one document, will the client always fetch the correct master ref?

Hello again, sorry for double posting, but we need assistance as this is becoming a big hassle for us. I pushed the suggested update from @Fares but sometimes we receive the documents with outdated information. To be honest, we 'forced' the master ref in the query (with the ->ref()) to fix this problem.

Last night a scheduled release went live and the query mentioned in the first post returned the following value for is_prebooking_available:

The value was supposed to be true, as defined in the document.
For reference, the prismic ID for this document is Ye6k0hAAAIAWXYJ_ and the master ref used was YinVthEAACUAom1S.

A few hours later, our content manager noticed that the information was wrong on our side, she republished the document with no changes and then we received the correct information:

The master ref used for this query was YipOGxAAACUALPfm.

Can anyone assist with this? We've had this problem for several months now, and it's just random. Sometimes the request fails as I mentioned in the first post, sometimes we receive the document with outdated information as described above. This is just an example using a boolean value, but some other information was incorrectly returned to us in the past.

1 Like

Hi @sulpriv,
I apologize for the delay; I'm checking with our dev team and will get back to your soon.

Can you please share your repository name (in a private message if necessary) to be able to have a look at the history and to report it to your dev team?
It would be also useful to have the release id that had the problem.

Note: One thing that can be useful is to try to query the same document using the rest API when such an issue happens before republishing to check if it is a problem of the PHP kit or the API.

Sure @Fares, I will send you a private message with the repo name.

And thanks for the note, I will ask our Content Manager to inform us the next time it happens to be able to compare the results using the kit and the API.

1 Like

Hi @sulpriv
I havn't received any private message from you recently!

Done now @Fares
I was pretty sure I did it before. Sorry for the delay

1 Like

Hi @sulpriv
I have created an issue in our tracker to have one of our devs to investigate, to be honest, such an error can take some time to investigate.