How to use the Shopify Partner API

The Shopify Partner API allows you to extract app performance data from Shopify itself. Like all new Shopify API it uses GraphQL. Currently, there the API can only be with a manually generated token.

The process of token creation is straight forward and only requires access to the Shopify partners admin section. You can find the option under Settings -> Partner API clients -> Manage Partner API Clients.

Then you have the option to give your new token a name so you can remember what it was used for.

Generally it is always recommended to generate a new token for each use.

Permissions

To have complete access to the financial transactions and to be able to see app events we should use the following permissions:

View financials: This permission gives access all Transaction resources.

Manage apps: This permission allows to access App resources, including all app-related events such as installs, uninstalls, and charges.

All permissions apply to the complete partner account and not to a specific app.

Besides the token, we also need to know our partner ID, which is the number in the URL after you log in to your partners account.

If the URL is for example https://partners.shopify.com/14919011491901 is your Partner ID

Sending your first API Query

Now with the token and the partner ID we are ready to use the Shopify Partner API. I recommend using a API client like Insomnia to to do this. Here we need to set up a few things:

URL: https://partners.shopify.com/partner_id/api/2023-07/graphql.json with partner_id as your ID from before

Request Type: POST

Content: GraphQL

Now under authentication, create a new header field called X-Shopify-Access-Token. Set the token you have generated as a value for the field. Now that we are ready to make our first GraphQL request:

query  {
  transactions(
    first: 3
  ) {
    edges {
      node {
        __typename
        id
        createdAt
        ... on AppSubscriptionSale {
            chargeId
            app {
                id
                name
            }
            shop {
                myshopifyDomain
                id
            }
            netAmount {
                amount
                currencyCode
            }
        }
        ... on AppUsageSale {
            chargeId
            app {
              id
              name
            }
            shop {
              myshopifyDomain
              id
            }
            netAmount {
                amount
                currencyCode
            }
        }
      }
      cursor
    }
    pageInfo {
      hasNextPage  
    }
  }
}

This request give the newest 3 financial transaction that were created by merchants with our apps in JSON format as is standard with GraphQL.

Towards the end of the response you can see that pageInfo.hasNextPage is true, which means the API is ready of offer us more records.

They can be fetched by passing the last cursor as the before argument in the GraphQL query. If you are curious if the cursors contain more information, go ahead an try to decode them using base64. For the sake of using the Shopify Partner API, it is enough to use them the way they are.

Also if you are looking to reproduce the figures from your Shopify Partner Dashboard I recommend checkout out my article about this.

Next Steps

In this brief introduction to the Shopify Partner API I’m only going into the financial transaction. We can however also get app events like installs, uninstalls and plan names from the partner API.

Alternatively you can also use Fusionmetrics to get this information in a visual form and ready to explore with a no-code setup.