# Example: Sending Parent Item and Variant

## Example

Here we'll show an example of a parent item and a variant being sent. Once the items have been sent, we will promote the catalog as active. We then send a patch on the variant.

The sample of items:

{% code title="Item parent" %}

```javascript
{
    "id": "A0001",
    "attributes": {
        "title": "My item",
        "description": "This is my item."
    }
}
```

{% endcode %}

{% code title="Item variant" %}

```javascript
{
    "id": "B0001",
    "attributes": {
        "price": 2000,
        "color": "red"
    },
    "parentId": "A0001"
}
```

{% endcode %}

### Create the item schema

The first step is to create an item schema. It must contain the attributes of the item and its variant.

{% tabs %}
{% tab title="Request" %}
{% code title="POST /item-schemas?tenant=mycompany\&environment=production" %}

```javascript
{
    "name": "product",
    "attributes": [
        {
            "name": "title",
            "type": "TEXT"
        },
        {
            "name": "description",
            "type": "TEXT"
        }
    ],
    "nestedItemSchemas": [
        {
            "name": "variant",
            "attributes": [
                {
                    "name": "price",
                    "type": "INTEGER"
                },
                {
                    "name": "color",
                    "type": "TEXT"
                }
            ]
        }
    ]
}
```

{% endcode %}
{% endtab %}

{% tab title="Response" %}

```javascript
{
    "version": 1
}
```

{% endtab %}
{% endtabs %}

### Create the catalog

Next, create a catalog version. As this is the first catalog the version is 1, but you can [list your catalogs](https://crownpeak.gitbook.io/product-discovery/sending-and-managing-product-data/what-is-the-items-api/step-by-step-guide-for-fredhopper-customers/step-by-step).

{% hint style="warning" %}
**Remember!** Catalog API can handle only 2 catalogs at the same time. If this limit is reached, one inactive catalog must be deleted by using the API before creating a new one. Determining the inactive catalog is done by listing all catalogs API.
{% endhint %}

{% tabs %}
{% tab title="Request" %}
{% code title="POST /catalogs?tenant=mycompany\&environment=production" %}

```javascript
{
    "catalogItemSchemas": [
        {
            "name": "product",
            "version": 1
        }
    ]
}
```

{% endcode %}
{% endtab %}

{% tab title="Response" %}

```javascript
{
    "version": 1
}
```

{% endtab %}
{% endtabs %}

### Sending the items

{% tabs %}
{% tab title="Request" %}
{% code title="POST /items?tenant=mycompany\&environment=production" %}

```javascript
[
    {
        "id": "A0001",
        "catalogVersion": 1,
        "type": "product",
        "attributes": {
            "title": "My item",
            "description": "This is my item."
        }
    },
    {
        "id": "B0001",
        "catalogVersion": 1,
        "type": "variant",
        "attributes": {
            "price": 2000,
            "color": "red"
        },
        "parentId": "A0001"
    }
]
```

{% endcode %}
{% endtab %}

{% tab title="Response" %}

```javascript
{
    "requestIds": [
        {
            "itemId": {
                "id": "A0001",
                "catalogVersion": 1,
                "context": "",
                "type": "product",
                "tenant": "mycompany",
                "environment": "production"
            },
            "requestId": "1888742087434729"
        },
        {
            "itemId": {
                "id": "B0001",
                "catalogVersion": 1,
                "context": "",
                "type": "variant",
                "tenant": "mycompany",
                "environment": "production"
            },
            "requestId": "1888742087434730"
        }
    ]
}
```

{% endtab %}
{% endtabs %}

Then, promote your catalog version.

```http
POST /catalogs/promote/1?tenant=mycompany&environment=production
```

After a short period of time, the catalog will be active and usable.

## Patch method

To quickly change the attribute of an item, use the patch method.

Here is an example of changing the price of the variant:

{% tabs %}
{% tab title="Request" %}
{% code title="PATCH /items?tenant=mycompany\&environment=production" %}

```javascript
[
    {
        "id": "B0001",
        "catalogVersion": 1,
        "type": "variant",
        "attributes": {
            "price": 1500,
        },
        "parentId": "A0001"
    }
]
```

{% endcode %}
{% endtab %}
{% endtabs %}
