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

# Making a graphql request

The SIBI public API is a GraphQL API. You can use any GraphQL client to make requests to our API. The examples below use [curl](https://curl.se/) & [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch)

## Endpoint

Our API is available at: [https://graphql.sibipro.com](https://graphql.sibipro.com)

This endpoint also hosts a GraphQL playground where you can explore the API and test your queries.

## Authentication

The SIBI public API uses API keys to authenticate requests. You can create an API key in the [SIBI developer dashboard](https://developer.sibipro.com). The API expects the key to be included in all requests in the `Authorization` header, prefixed by `Bearer`.

```shell Curl theme={null}
curl \
  --request POST \
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --data '{"query": "<YOUR_QUERY>"}' \
  https://graphql.sibipro.com
# => {"data": {...}}
```

```javascript Fetch theme={null}
const response = await fetch('https://graphql.sibipro.com, {
  method: 'POST',
  headers: { 'Authorization': `Bearer ${yourApiKey}` },
  body: JSON.stringify({ query: '<YOUR_QUERY>'}),
});
const body = await response.json();
const invoices = body.data.invoices.edges;
console.log(JSON.stringify(invoices, null, 2))
# => {"data": {...}}
```

## Querying

All requests are made using the `POST` method. The body of the request should be a JSON object with a `query` key. The value of the `query` key should be a GraphQL query. The following examples show how to ask for just the invoice number of all invoices.

```shell Curl theme={null}
curl \
  --request POST \
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --data '{"query": "query Invoices() { invoices { edges { invoiceNumber } } }"}' \
  https://graphql.sibipro.com
```

```javascript Fetch theme={null}
const query = `# graphql
  query Invoices() {
    invoices {
      edges {
        invoiceNumber
      }
    }
  }
`;
const response = await fetch('https://graphql.sibipro.com', {
  method: 'POST',
  headers: { Authorization: `Bearer ${yourApiKey}` },
  body: JSON.stringify({ query }),
});
const body = await response.json();
const invoices = body.data.invoices.edges;
console.log(JSON.stringify(invoices, null, 2));
```

The API will return a JSON response:

```json Response theme={null}
{
  "data": {
    "invoices": {
      "edges": [{ "invoiceNumber": "INV-0001" }, { "invoiceNumber": "INV-0002" }]
    }
  }
}
```

## Projections

The GraphQL API will only return the specific fields requested in the query. This is called a projection. The following example query shows how to ask for the invoice date and total of all invoices.

```graphql theme={null}
query Invoices() {
  invoices {
    edges {
      invoiceDate
      total
    }
  }
}
```

To request every property available, you can use this query:

```graphql theme={null}
query Invoices() {
  invoices {
    page
    hasNextPage
    hasPreviousPage
    totalHits
    totalPageCount
    edges {
      accountNumber
      invoiceNumber
      invoiceDate
      orderIdentifier
      total
      tax
      partner
      partnerName
      partnerIconImageUrl
      poNumber
      propertyAddress {
        line1
        line2
        city
        stateOrProvince
        postalCode
      }
      lineItems {
        description
        quantity
        unitPriceAmount
        sku
        serialNumber
      }
    }
  }
}
```

For a description list of each of the fields, see the [Invoice Schema](https://sibipro.readme.io/docs/invoice).

## Pagination

The SIBI public API uses page-based pagination (as opposed to cursor-based). By default, the API returns the first page of results. If included in the query projection, the reponse will include pagination information including the current page and whether or not there is a next page:

```graphql theme={null}
query InvoicesPage {
  invoices(page: 0) {
    currentPage
    hasNextPage
  }
}
```

Will return:

```json theme={null}
{
  "data": {
    "invoices": {
      "currentPage": 1,
      "hasNextPage": true
    }
  }
}
```
