Introduction

District has two GraphQL APIs: the Marketplace API for storefronts, and the Admin API for seller tools and sync services. This page gives the GraphQL rules that both APIs follow, a recommended client, and the keys that each kind of app sends.

About GraphQL

Each API has one endpoint. Send each operation to it as an HTTP POST with a JSON body that holds the query and its variables. A query selects only the fields that you need, and the data of the response has the same shape as the selection.

Objects such as products and orders have a global id: give it to node(id:) to read the object again. A field that returns a connection takes first and after: request a page with first, and the next page with after set to pageInfo.endCursor, while pageInfo.hasNextPage is true. When the API refuses a request, for example an invalid query or a request without a valid key, the response has a top-level errors list. A mutation returns an expected failure as a typed result: select ... on Error { message } in its payload.

Introspection

Both APIs answer GraphQL introspection queries. An introspection query needs no key and no access token, so a tool can read the schema before you have a key.

Desktop clients such as Bruno, HTTPie, Insomnia and Postman load the schema from the endpoint. They use it to show the fields that you can select and to complete your queries. To run an operation, add the headers of your kind of app.

Authentication

Each request to a District API sends a client key. The kind of app that you build selects the API, the key and the sign-in.

Only a publishable key (district_pk_live_…) can go in a browser or an app. Keep every other District key on your server.

Choose how you connect

Storefront

Who uses it?
Your buyers
What it is
A shop or an app for buyers
API
Marketplace API
Key
Publishabledistrict_pk_live_…
Sign-in
OptionalBuyers sign in for bookmarks and similar features.
Runs in
  • browser
  • app
  • server

Seller tool

Who uses it?
Your sellers and staff
What it is
A back office, a pick list, a label printer
API
Admin API
Key
Publishabledistrict_pk_live_…
Sign-in
RequiredEach member signs in.
Runs in
  • browser
  • app
  • server

Sync service

Who uses it?
Nobody: it runs on its own
What it is
Inventory and order sync from your own systems
API
Admin API
Key
Restricteddistrict_rk_live_…
Sign-in
NoneThe key acts for itself.
Runs in
  • your server only
A restricted key can change listings and orders with no signed-in member. Keep it on your server: never in a browser, an app or a repository.

Storefront

A storefront is a shop or an app for buyers. It uses the Marketplace API.

Send the publishable key in the District-Client-Authorization header of each request. The key is safe to use in a browser or an app. Reach out to your Enterprise account manager to get your key.

District-Client-Authorization: Bearer district_pk_live_…

Buyer sign-in is optional. To act for a signed-in buyer, also send the access token of the buyer in the Authorization header. Without it, the API answers for a visitor who is not signed in, and viewer is null.

Authorization: Bearer <buyer access token>

Some fields need a client key with a scope. The reference marks each of these fields.

Seller tool

A seller tool is an app for the sellers and staff of a marketplace, such as a back office, a pick list or a label printer. It uses the Admin API.

Each request sends the publishable key and the access token of a signed-in member of the marketplace. Each request needs a member.

District-Client-Authorization: Bearer district_pk_live_…
Authorization: Bearer <member access token>

The client of your key needs the admin scopes that your tool uses. Your Enterprise solutions team sets them up.

The role of the member also limits each operation. The reference shows the minimum role of each operation.

Sync service

A sync service moves inventory and orders between your own systems and District. It runs on your server, and no person signs in. It uses the Admin API with a restricted key (district_rk_live_…) that your District contact gives you.

Send only the restricted key, in the District-Client-Authorization header:

District-Client-Authorization: Bearer district_rk_live_…

Header to leave out

Do not send an Authorization header. A request with an Authorization header, also an empty or a Basic one, does not run as the agreed member. Some HTTP clients add an empty Authorization header: make sure that yours does not.

What the key can do

The key works for one marketplace only. Each request runs as one member of that marketplace, which you agree with District. The history of a listing or an order shows each change as a change by that member.

The member must stay an active member of the marketplace. If the member is removed, the key stops working. A later release records your app in place of the member. Your requests do not change.

The key has these scopes:

  • admin:products:read
  • admin:products:write
  • admin:products:delete
  • admin:orders:read
  • admin:orders:settle
  • admin:shipments:read
  • admin:shipments:write

The API refuses an operation that needs another scope, for example a payout operation.

Keep the key secret

The key is a server secret. Do not put it in a browser, a mobile app or a public repository.

Rotation

District can give you a new key for the same client, with no other change. When District revokes a key, the key stops working in about 60 seconds.

Sync service keys do not get webhooks yet.

Signing in

Both APIs use District Auth access tokens. Send the token in the Authorization header: Authorization: Bearer <access token>.

  • Storefronts: optional. Buyers sign in for features such as bookmarks.
  • Seller tools: required. Each member signs in.
  • Sync services: no sign-in. The restricted key acts for itself.

Documentation coming soon. Your Enterprise solutions team will reach out to you if your web app needs it.

Continue to the guides

GraphQL

Marketplace API

Build a storefront for one marketplace: products, carts, checkout and orders.

GraphQL

Admin API

Run a marketplace: listings, orders, shipping and members.

Events

Webhooks

Get an HTTPS request when a listing, an order, a livestream or a seller changes.