Getting started

This page will help you start to use the salesbricks public API

The public GraphQL API for salesbricks gives you deep access to your subscriptions and orders and has a fully introspectable schema, so if you want to what's available to view or edit, you can just ask the schema!

Here's a quick guide to getting authenticated and running your first queries. We've chosen to use Apollo GraphQL for this example.

Step 1: Authentication

Access to the API is obtained by appending an X-SALESBRICKS-KEY attribute to your request headers. The value is your Public API Token, which can be obtained from your admin settings UI here.

import {
  ApolloClient,
  InMemoryCache,
  gql
} from "@apollo/client";

// Configure fetch to send the X-SALESBRICKS-KEY in its request headers
const getAuthorizedFetch = (uri, options) => {
  options.headers['X-SALESBRICKS-KEY'] = 'YOUR_API_TOKEN_HERE';
  return fetch(uri, options);
};

const link = new HttpLink({ fetch: getAuthorizedFetch });

const client = new ApolloClient({
  uri: 'https://api.salesbricks.com/api/v1/graphql',
  cache: new InMemoryCache()
});

Step 2: Query the schema

Once you have your client configured, you can make any queries you want following the defined schema. Here's an example query to get all orders with in-progress upgrades:

client.query({
    query: gql`
      query {
        companyOrders (limit: 3, stages:[building_upgrade] orderBy:"closed_at") {
          orders {
            id
            stage
            buyer {
              name
            }
                        metadata
            orderskuSet {
              sku {
                name
                code
              }
              quantity
            }
          }
        }
      }
    `
  })
  .then(result => console.log(result));


/* Output:
{
  "data": {
    "companyOrders": {
      "orders": [
        {
          "id": "17f14b02-780a-45f3-9419-843880b6fff1",
          "stage": "BUILDING_UPGRADE",
          "buyer": {
            "name": "MultiAcc"
          },
          "metadata": "{
            "salesforceAccountId": "bancc1701xbwhc_c"
          }",
          "orderskuSet": [
            {
              "sku": {
                "name": "Service Hours",
                "code": null
              },
              "quantity": 4
            },
            {
              "sku": {
                "name": "Enterprise",
                "code": null
              },
              "quantity": 3
            },
            {
              "sku": {
                "name": "Seats",
                "code": null
              },
              "quantity": 1
            }
          ]
        },
        {
          "id": "38ab3d10-049d-4fe6-be9f-2c84f912ac63",
          "stage": "BUILDING_UPGRADE",
          "buyer": {
            "name": "[email protected]"
          },
          "metadata": "{}",
          "orderskuSet": [
            {
              "sku": {
                "name": "Service Hours",
                "code": null
              },
              "quantity": 3
            },
            {
              "sku": {
                "name": "Enterprise",
                "code": null
              },
              "quantity": 2
            },
            {
              "sku": {
                "name": "Seats",
                "code": null
              },
              "quantity": 2
            }
          ]
        },
        {
          "id": "e7a9ce5a-c7e3-4bd0-b52f-fbeaaf5bb020",
          "stage": "BUILDING_UPGRADE",
          "buyer": {
            "name": "[email protected]"
          },
          "metadata": "{}",
          "orderskuSet": [
            {
              "sku": {
                "name": "Starter",
                "code": null
              },
              "quantity": 1
            },
            {
              "sku": {
                "name": "Admin Seats",
                "code": null
              },
              "quantity": 10
            },
            {
              "sku": {
                "name": "Seats are great  and also really really really really long and also really really really really long and also really really really really long and also really pomelo also really really really really long",
                "code": ""
              },
              "quantity": 1
            }
          ]
        }
      ]
    }
  }
}

*/