Error with authentication in Asset Upload via API

Hi Prismic Support,

I am attempting to upload images to the Media Library via the Asset API (https://asset-api.prismic.io/assets) using a Node.js script. Despite following the documentation, I am consistently receiving a 401 Unauthorized error with the body: {"error":"invalid_token"}.

Here is my setup:

  1. Endpoint: POST https://asset-api.prismic.io/assets

  2. Headers:

    • Authorization: Bearer [MY_TOKEN]

    • repository: [MY_REPO_NAME]

  3. Body: multipart/form-data containing the file and metadata.

  4. Token Source: I have tried using the Permanent Access Token generated under API and Security > Content API.

My Questions:

  1. Which token is required for the Asset API? Should I use the "Permanent Access Token" from Content API, or the "Write API Token" found under API > Write APIs > Tokens?

  2. Endpoint Authentication: Is the repository header mandatory when using the global asset-api.prismic.io URL, or should I be using a repository-specific URL?

Any clarification on the correct authentication flow for the Asset API in a Node.js environment would be greatly appreciated.

Hey @kristofferaandreasen,

You should indeed use the "Write API Token" found under API > Write APIs > Tokens :slight_smile: Regarding the endpoint authentication, the repository header is also mandatory.

Let me know if you have further questions!