The GraphQL API

#Getting started

As GraphQL aggregates the GET Rest API calls, a Rest API Token is required to use GraphQL.

#Step 1: Get your token

To connect to the PIM API, you can use two types of tokens:

  1. Connection token - lasts for one hour and is generated when you connect to the API.
  2. App token - permanent and generated via OAuth2 for App connections.

We recommend using an App token for development purposes. However, for testing purposes, we suggest using a connection token.

#1. Using a connection token

To generate a token from a connection you will need:

  • A clientId/clientSecret in addition of a username/password, you can find all the detail here

You can now ask for a token using a dedicated GraphQL query, to execute it:

  • Go to https://graphql.sdk.akeneo.cloud, a GraphQL in browser IDE will be displayed and allow you to execute queries.
  • Replace my-username, my-password, my-client-id, and my-client-secret found on the connection page in the following query.

    {
      token(
        username: "my-username"
        password: "my-password"
        clientId: "my-client-id"
        clientSecret: "my-client-secret"
      ) {
        data {
          accessToken
        }
      }
    }
    
    
  • Enter the previous query on the left panel

  • Add header information on the bottom left panel


    {
      "X-PIM-URL": "https://your-pim-url",
      "X-PIM-CLIENT-ID": "your-client-id"
    }
    
  • You can now click on the ▶️ button, you should receive the following response:

    {
      "data": {
        "token": {
          "data": {
            "accessToken": "xxxxxxxxxxxxxxxxxxMzQyYWNhYjc5Nxxxxxxxxxxxxxxxxxxxxxxxx"
          }
        }
      }
    }
    
  • Here is a screenshot that corresponds to the previous steps

Graphql-Token-Query

Congratulations! You now have an access token! You’re ready to query your PIM using GraphQL.

#2. Using an App token

All the required steps are documented here

#Step 2: Make your first query

In the previous step, you got the following configuration:

  • Your PIM URL
  • Your client id & token (previously generated)

You can now execute your first query to get a list of products with their category codes & labels


    {
      products {
        items {
          uuid
          categories {
            code
            labels
          }
        }
      }
    }
    
  • Add header information on the bottom left panel

    {
      "X-PIM-URL": "https://your-pim-url",
      "X-PIM-CLIENT-ID": "your-client-id",
      "X-PIM-TOKEN": "your-token"
    }
    
  • You can now click on the play button
  • Here is a screenshot that corresponds to the previous steps

Graphql-First-Query