# Syncing Products

Use product sync APIs to sync the product and inventory of your store with Growlytics. This article will give you all the details you need to create products, collections and map products to collections.

## Data Structure Of Product And Collections

The data structure of products and collections is many to many kinds of relationships. One collection can have multiple products and one product can be in multiple collections.

![](/files/-MavNSDvruFFob5XJv1V)

## Add/Update Products

<mark style="color:green;">`POST`</mark> `https://dc.growlytics.in /product`

Using `/product` API, you can add products to Growlytics. If a product not found with the given id, it will be created, else it will be updated.

#### Headers

| Name             | Type   | Description        |
| ---------------- | ------ | ------------------ |
| x-growlytics-key | String | Growlytics API Key |

#### Request Body

| Name                | Type   | Description                                                                                                               |
| ------------------- | ------ | ------------------------------------------------------------------------------------------------------------------------- |
| id                  | string | Product id. Your system's unique product id. Max 50 chars allowed.                                                        |
| name                | string | Product name. Max 2000 chars allowed.                                                                                     |
| image               | string | Product Image url. Max 1000 characters allowed.                                                                           |
| description         | string | Product description. Max 2000 characters allowed. Null and empty values are alo allowed.                                  |
| url                 | string | Url of the product. Max 1000 characters allowed.                                                                          |
| price               | number | Price of the product. Decimals are also allowed. Example: 12.20, 1321, 15.5                                               |
| originalHigherPrice | number | Product price without discount. Decimals are also allowed. Provide this field to show discounts in the campaign messages. |
| vendor              | string | Vendor of the product. Max 1000 characters allowed.                                                                       |
| status              | string | Inventory status of the product. Allowed values are `inStock` and `outOfStock`                                            |

{% tabs %}
{% tab title="200 Product synced successfully." %}

```
{ success: true }
```

{% endtab %}

{% tab title="422 Invalid input. " %}

```
{
  "type": "ValidationError",
  "details": [
    {
      "message": "status must be one of [inStock, outOfStock]",
      "path": [
        "status"
      ],
      "type": "any.allowOnly",
      "context": {
        "value": "1outOfStock",
        "valids": [
          "inStock",
          "outOfStock"
        ],
        "key": "status",
        "label": "status"
      }
    }
  ]
}
```

{% endtab %}
{% endtabs %}

## Remove Product

<mark style="color:red;">`DELETE`</mark> `https://dc.growlytics.in/product/:id`

Use this API to delete products from Growlytics's product dataset.&#x20;

#### Path Parameters

| Name | Type   | Description                                                      |
| ---- | ------ | ---------------------------------------------------------------- |
| id   | string | Product Id. Your system's product Id. Max 50 characters allowed. |

#### Headers

| Name             | Type   | Description        |
| ---------------- | ------ | ------------------ |
| x-growlytics-key | string | Growlytics API Key |

{% tabs %}
{% tab title="200 Product deleted successfully." %}

```
{ success: true }
```

{% endtab %}
{% endtabs %}

## Add/Update Collection

<mark style="color:green;">`POST`</mark> `https://dc.growlytics.in/collection`

Using `/collection` API, you can add or update collection in the Growlytics collection dataset. If a collection does not exist for given id, it will be created, else it will be updated.

#### Headers

| Name             | Type   | Description        |
| ---------------- | ------ | ------------------ |
| x-growlytics-key | string | Growlytics API Key |

#### Request Body

| Name  | Type   | Description                                                               |
| ----- | ------ | ------------------------------------------------------------------------- |
| id    | string | Collection Id. Your system's unique collection id.  Max 50 chars allowed. |
| name  | string | Collection name. Max 2000 characters allowed.                             |
| image | string |                                                                           |
| url   | string |                                                                           |

{% tabs %}
{% tab title="200 " %}

```
{ success: true }
```

{% endtab %}

{% tab title="422 " %}

```
{
  "type": "ValidationError",
  "details": [
    {
      "message": "status must be one of [inStock, outOfStock]",
      "path": [
        "status"
      ],
      "type": "any.allowOnly",
      "context": {
        "value": "1outOfStock",
        "valids": [
          "inStock",
          "outOfStock"
        ],
        "key": "status",
        "label": "status"
      }
    }
  ]
}
```

{% endtab %}
{% endtabs %}

## Delete Collection

<mark style="color:red;">`DELETE`</mark> `https://dc.growlytics.in/collection/:id`

Use this api to delete collection from Growlytics collection dataset. You will need to pass the id of the collection in url.

#### Path Parameters

| Name | Type   | Description                                                      |
| ---- | ------ | ---------------------------------------------------------------- |
| id   | string | Id of the collection to be removed. Your system's collection id. |

#### Headers

| Name             | Type   | Description         |
| ---------------- | ------ | ------------------- |
| x-growlytics-key | string | Growlytics API Key. |

{% tabs %}
{% tab title="200 " %}

```
{ success: true }
```

{% endtab %}
{% endtabs %}

## Mapping Products & Collections

Products and Collections have many to many relationships. You can use APIs to add or remove multiple products from a particular collection.

## Add products to the collection

<mark style="color:green;">`POST`</mark> `https://dc.growlytics.in/collection/:id/products/add`

Use this API to add multiple products to the collection. You will need to pass the collection id in the URL.

#### Path Parameters

| Name | Type   | Description                                 |
| ---- | ------ | ------------------------------------------- |
| id   | string | Collection id. Your system's collection id. |

#### Request Body

| Name     | Type  | Description                                                                                 |
| -------- | ----- | ------------------------------------------------------------------------------------------- |
| products | array | <p>Array of string. List of product ids. <br>Example: \['produc id 1', 'product id 2'] </p> |

{% tabs %}
{% tab title="200 " %}

```
{ success: true }
```

{% endtab %}

{% tab title="422 " %}

```
{
  "type": "ValidationError",
  "details": [
    {
      "message": "status must be one of [inStock, outOfStock]",
      "path": [
        "status"
      ],
      "type": "any.allowOnly",
      "context": {
        "value": "1outOfStock",
        "valids": [
          "inStock",
          "outOfStock"
        ],
        "key": "status",
        "label": "status"
      }
    }
  ]
}
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
Make sure you have added products and collections in Growlytics before adding them to any collection. In short, products and collections to be mapped must exist in Growlytics.
{% endhint %}

## Remove products from the collection

<mark style="color:green;">`POST`</mark> `https://dc.growlytics.in/collection/:id/products/remove`

Use this API to remove multiple products from a particular collection. You will need to pass the collection id in the URL.

#### Path Parameters

| Name | Type   | Description                                 |
| ---- | ------ | ------------------------------------------- |
| id   | string | Collection id. Your system's collection id. |

#### Request Body

| Name     | Type  | Description                                                                  |
| -------- | ----- | ---------------------------------------------------------------------------- |
| products | array | <p>Array of string. List of product ids.<br>Example: \['pid 1', 'pid 2']</p> |

{% tabs %}
{% tab title="200 " %}

```
{ success: true }
```

{% endtab %}

{% tab title="422 " %}

```
{
  "type": "ValidationError",
  "details": [
    {
      "message": "status must be one of [inStock, outOfStock]",
      "path": [
        "status"
      ],
      "type": "any.allowOnly",
      "context": {
        "value": "1outOfStock",
        "valids": [
          "inStock",
          "outOfStock"
        ],
        "key": "status",
        "label": "status"
      }
    }
  ]
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.growlytics.in/rest-apis/syncing-products.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
