> ## Documentation Index
> Fetch the complete documentation index at: https://docs.salesbricks.com/llms.txt
> Use this file to discover all available pages before exploring further.

# GraphQL API (Legacy)

The Salesbricks GraphQL API offers a robust, introspectable schema, empowering you to effortlessly explore and interact with its extensive capabilities.

<Note>
  The GraphQL API remains fully supported, and existing integrations continue to work.

  For new integrations we recommend the [REST API](/api-reference/getting-started/overview) — it covers the
  full subscription lifecycle and is where new functionality lands, including the self-serve
  endpoints for [starting a subscription](/api-reference/getting-started/starting-a-subscription).
</Note>

<Tip>
  Before you begin, ensure you have read the
  [Authentication](/api-reference/getting-started/authentication) guide to find your
  `X-SALESBRICKS-KEY` and the correct **endpoint** for your use case.
</Tip>

## Setting up an Apollo Client

In this guide, we leverage Apollo Client, extending the example from their documentation [here](https://www.apollographql.com/docs/react/networking/authentication/).

```javascript JavaScript theme={null}
import { ApolloClient, createHttpLink, InMemoryCache } from '@apollo/client';
import { setContext } from '@apollo/client/link/context';

// discovered using the Authentication guide
const SALESBRICKS_API_ENDPOINT = 'https://api.salesbricks.com/api/v1/graphql';
const SALESBRICKS_API_TOKEN = '00000000-0000-0000-0000-000000000000';

const httpLink = createHttpLink({
  uri: SALESBRICKS_API_ENDPOINT,
});

const authLink = setContext((_, { headers }) => {
  return {
    headers: {
      ...headers,
      'X-SALESBRICKS-KEY': SALESBRICKS_API_TOKEN,
    },
  };
});

const client = new ApolloClient({
  link: authLink.concat(httpLink),
  cache: new InMemoryCache(),
});
```

## Query the schema

Once your client is configured, make queries following the defined schema.

Below is an example query to retrieve all orders:

### Example Query

```javascript JavaScript theme={null}
client
  .query({
    query: gql`
      query {
        companyOrders {
          orders {
            id
            buyer {
              id
              name
            }
          }
        }
      }
    `,
  })
  .then((result) => console.log(result));
```

### Example Response

```json JSON theme={null}
{
  "data": {
    "companyOrders": {
      "orders": [
        {
          "id": "00000000-0000-0000-0000-000000000000",
          "buyer": {
            "id": "00000000-0000-0000-0000-000000000000",
            "name": "Buyer Name"
          }
        }
      ]
    }
  }
}
```

## REST equivalents

If you are moving an existing integration across, these are the most common mappings:

| GraphQL                   | REST                                                                                                                                                  |
| ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| `companyOrders`           | [List all customers](/api-reference/customers/list-all-customers) and [Retrieve a subscription](/api-reference/subscriptions/retrieve-a-subscription) |
| `createSubscriptionToken` | [Retrieve subscription management URL](/api-reference/subscription-management/retrieve-subscription-management-url)                                   |


## Related topics

- [Authentication](/api-reference/getting-started/authentication.md)
- [REST API Overview](/api-reference/getting-started/overview.md)
- [Manage My Subscription](/api-reference/manage-my-subscription.md)
