Cosmic JS GraphQL API Learn how to make requests to the Cosmic JS GraphQL API.

GraphQL API

Connect to your Cosmic JS Bucket through GraphQL queries to the Cosmic JS API.

Required Parameters

All queries require a bucket_slug parameter.

Optional Parameters

For queries that return arrays, optional parameters limit and skip can be used to paginate returned data. If you have added a read_key to your Bucket, this will need to be included in every request.

All API requests begin from the host URL:

https://graphql.cosmicjs.com/v1

Get All Objects

Returns Objects from a Bucket by querying by bucket_slug.

Try it

REST Equivalent

https://api.cosmicjs.com/v1/creative-agency/objects?pretty=true&limit=4

Get Objects by Type

Returns Objects from a Bucket by querying by bucket_slug and type_slug.

Try it

REST Equivalent

https://api.cosmicjs.com/v1/creative-agency/object-type/team-members?pretty=true&limit=4&skip=2

Get Single Object

Returns a single Object by querying by bucket_slug and slug.

Try it out

REST Equivalent

https://api.cosmicjs.com/v1/creative-agency/object/about?pretty=true

Examples

These examples get content from the Creative Agency app.

CURL

Get all the Objects in the Creative Agency app. Run the following in your command line app:

curl -XPOST -H "Content-Type:application/graphql"  -d 'query { objects(bucket_slug: "creative-agency") { title, metadata } }' https://graphql.cosmicjs.com/v1

AJAX

Get one object from the Creative Agency app.