Unable to access API data on v2

Hi everyone!

I'm having some trouble with getting authenticated with the v2 endpoint.

This is what I'm currently doing:

const response = await fetch(
    `https://****.cdn.prismic.io/api/v2?access_token=${prismicToken}`,
  )
  const parsedResponse = await response.json()

  const masterRef =
    parsedResponse &&
    parsedResponse.refs &&
    parsedResponse.refs.find(ref => ref.isMasterRef)

  const url = new URL(`https://****.cdn.prismic.io/api/v2/documents/search`) endpoint instead?
  const params = {
    ref: masterRef.ref,
    q: '[[ at(my.url_redirects.uid,"all_redirects") ]]',
   access_token= prismicToken
  } 

I'm using the access_token which I created in the Prismic UI (under Permanent access tokens)

The first request to get the master ref works successfully, however when I do the search request I receive an error showing this:

{
    "error": "Access to this Ref requires an access token",
    "oauth_initiate": "https://***.cdn.prismic.io/auth",
    "oauth_token": "https://***.cdn.prismic.io/auth/token"
} 

Can I get some support to know what I'm doing incorrectly?

The API access for this repository is currently: "Public API for Master only - Require an access token to preview future releases".

Just to be clear I want to add the auth_token incase the Prismic API access becomes private.

Many thanks!

Hello @ardit.cenalia,

Welcome to the Forum.

After looking at your code, it seems the assignment to access_token is not correct. Could you please try with access_token: prismicToken instead of access_token= prismicToken.

Give this a try and let me know.

Thanks,

Priyanka

Hey,

Thanks for your quick response!

Sorry there was a typo when I was writing the question, it should have said this:

const params = {
    ref: masterRef.ref,
    q: '[[ at(my.url_redirects.uid,"all_redirects") ]]',
   access_token: prismicToken
  } 

And this didn't work :slightly_frowning_face:

Hello,

I can think of some issues:

  1. Run: prismic login in your terminal. Then log in again with your credentials, and then try running the demo project once more.

  2. You need to make sure you're adding the correct repo name you want to retrieve data from in the query request.

  3. Try to clear cookies on localhost. It can be tangled with a prismic cookie from another repo if you are using multiple repositories in Prismic.

If it still doesn't work could you share the URL of your repository and project code (you can send me a PM if you prefer)

Thanks,

Priyanka

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.