Authentication

Learn how to authenticate with the GraphQL API

To use the PMKIN API, you will need to create an API key for your project. You can create a new key inside your project's "API" section. The key will allow you to access resources inside the same project, like documents and categories. A single key can't be used for multiple projects.

Once you have created a key, you can pass it along with your API request in the "Authentication" header. We use the Bearer Token format:

Authorization: Bearer 42dfe105d247a45473eeb1d14a59fb408ef3805150edfe32c18a81e1d2f3d7fa

Remember that anyone with access to your API key will have access to all the content in the project. In this example, the API key is stored in an environment variable called PMKIN_API_KEY. This is a good practice because it keeps your key secure—never hard-code it directly into your code:

const { GraphQLClient } = require('graphql-request')

const client = new GraphQLClient( 'https://pmkin-delivery.onrender.com/graphql', {
  headers: {
    Authorization: `Bearer ${process.env.PMKIN_API_KEY}`
  }
})