Authorization
Queries and mutations by default require a Permanent Auth Token token, but you can configure the Public API Permissions to allow unauthenticated requests.
GraphCMS allows you to configure access for each model, stage, environment, locale, and whether or not you permit mutations.
Public API PermissionsAnchor
By default all new projects disable public API access.
Enabling public access to your project means that anybody with your API endpoint can query sensitive data, and perform destructive actions if configured incorrectly.
You can configure custom permissions, or initialize the defaults.
For example, here you can see how to configure the Public API to allow access to READ the Post
model on stages Published
and QA
with the locale en
.
You can also specify an optional condition that restricts access even further. For example, you could specify the condition { "id": "ckoimwlu80ck20a88z6i754cw" }
. This would then only allow you to fetch the Post
with id
ckoimwlu80ck20a88z6i754cw
.
Learn more about Public API permissions
Default public stageAnchor
If no stage parameter is set on the GraphQL query, or via a HTTP header, the content from the default set content stage will be served.
The default public stage is set to PUBLISHED
for all new projects.
Permanent Auth TokensAnchor
Permanent Auth Tokens are used for controlling access to querying, mutating content, and comes in the form of Bearer token authentication.
Similar to Public API permissions, you can create individual PATs for specific API actions.
Some users create PATs for only querying data from the draft stage, for creating previews in staging environments. You may also opt to create a PAT for mutations, so you can perform changes to your content models server-side.
If you are mutating data from the frontend, you should hide this token at the server level, and not expose your PAT client-side.
The Permanent Auth Token must be passed via the Authorization
header on HTTP requests in the format of a Bearer token:
Authorization: Bearer PERMANENT_AUTH_TOKEN
Learn more about PAT permissions
API EndpointAnchor
With each GraphCMS project you create, or are invited to, it has a unique GraphQL API endpoint (per environment). These endpoint permits you to both query, and mutate data within your project.
GraphQL introspection is enabled by default, so anybody with access to your endpoint can traverse the graph to see your content types, as well as all queries and mutations.
The API endpoint also contains the current schema environment, by default this will be master
.
Your endpoint will look something like:
https://[region].graphcms.com/v2/[projectId]/[environment]