> For the complete documentation index, see [llms.txt](https://docs.ergonode.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ergonode.com/graphql/guides/integrating-data.md).

# Integrating data

Note: the following examples are based on the API Stream integration concept - if you are not yet familiar with it check an overview of the [Query types](/graphql/overview/query-types.md) to understand the approach.

### A simple example of integrating categories into the system from scratch:

#### Fetch the first page of the Category stream

```graphql
{
  categoryStream(first: 1) {
    pageInfo {
      endCursor
      hasNextPage
    }
    edges {
      node {
        code
        name {
          value
          language
        }
      }
      cursor
    }
  }
}
```

{% hint style="info" %}
`first` parameter put on limit how many categories are fetched in one result
{% endhint %}

example response:

```graphql
{
  "data": {
    "categoryStream": {
      "pageInfo": {
        "endCursor": "YXJyYXljb25uZWN0aW9uOjQ5",
        "hasNextPage": true
      },
      "edges": [
        {
          "node": {
            "code": "category_name_clothing",
            "name": [
              {
                "value": "Clothing",
                "language": "en_GB"
              },
              {
                "value": "Odzież",
                "language": "pl_PL"
              }
            ]
          },
          "cursor": "YXJyYXljb25uZWN0aW9uOjQ5"
        }
      ]
    }
  }
}
```

#### Fetch the next page of the Category stream

Since we received information that the next page exists `data.categoryStream.pageInfo.hasNextPage=true` we should request the next resource. The query is very similar to the previous one except we are passing the appropriate `cursor` with the request:

```graphql
{
  categoryStream(first: 1, after: "YXJyYXljb25uZWN0aW9uOjQ5") {
    ...
}
```

{% hint style="info" %}
`after` parameter represents the appropriate cursor that identifies a last-fetched resource. Available as either `cursor` field of the node or the `endCursor` of `PageInfo` object.
{% endhint %}

example response:

```graphql
{
  "data": {
    "categoryStream": {
      "pageInfo": {
        "endCursor": "YXJyYXljb25uZWN0aW9uOjUw",
        "hasNextPage": false
      }
      ...
    }
  }
}
```

we do know that there is no next page, therefore, there is nothing to fetch at the very moment. We can retry the next request(for the retrieved cursor) with i.e., an increased interval not to waste resources.

### &#x20;A more complex example of integrating categories

Alternatively in some systems, we will want only to fetch the identifier of the resource using some sort of queueing system in order to distribute the consumption processes. In that case, we can just fetch our resource ID (code in the case of categories) and the `PageInfo` object:

```graphql
{
  categoryStream(first: 1) {
    pageInfo {
      endCursor
      hasNextPage
    }
    edges {
      node {
        code
      }
    }
  }
}
```

and fetch it in the separate consuming process via a single resource query:

```graphql
{
  category(code: "category_name_clothing") {
    name {
      value
      language
    }
    code
  }
}
```

The rest of the process looks the same for the paginating over the stream.

{% hint style="info" %}
Though given above content provides an example of handling categories you can use the same approach for every other resource available via streams like products, multimedia, and attributes.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.ergonode.com/graphql/guides/integrating-data.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
