# Return individual items

> Let's return some items from a given customer session.

> For the complete documentation index, see [llms.txt](https://docs.talon.one/llms.txt).

We do this by calling the [Return cart items](/integration-api#tag/Customer-sessions/operation/returnCartItems).
endpoint. This endpoint automatically changes the session state from `closed` to `partially returned`,
and we can expect rollback effects to be triggered.

:::note
Before following this tutorial, we recommend that you read about
[customer session states](/docs/dev/concepts/entities/customer-sessions.md#customer-session-states).
:::

Let's imagine that our customer purchased one pair of shoes and two units of the same shirt.
With [cart item flattening](/docs/product/rules/cart-item-flattening.md),
identical products are viewed as single items in the cart. So, we have a total of three items
in our cart.

The customer session is closed because the checkout step is complete, and it contains
the following cart items:

```json title="Cart items in the customer session"
"cartItems": [
  {
    //...
    "name": "shoes1",
    "sku": "9696",
    "quantity": 1,
    "price": 60,
    "category": "shoes"
  },
  {
    //...
    "name": "shirts3",
    "sku": "6478",
    "quantity": 2,
    "price": 20,
    "category": "shirts"
  }
]
```

This session is part of a campaign that gives a $5 discount [per item](/docs/dev/integration-api/api-effects.md#setdiscountperitem).

After the purchase, our customer wants to return one discounted shirt out of the three items.

The [Update customer session](/integration-api#tag/Customer-sessions/operation/updateCustomerSessionV2) request
that closed the customer session during checkout returned the following discount effects:

```json title="Applied discount effects"
{
  //...
  "effectType": "setDiscountPerItem",
  "props": {
    "name": "5forALL",
    "value": 5,
    "position": 0, // the pair of shoes
    "subPosition": 0
  }
},
{
  //...
  "effectType": "setDiscountPerItem",
  "props": {
    "name": "5forALL",
    "value": 5,
    "position": 1, // the shirts
    "subPosition": 0 // the first shirt
  }
},
{
  //...
  "effectType": "setDiscountPerItem",
  "props": {
    "name": "5forALL",
    "value": 5,
    "position": 1, // the shirts
    "subPosition": 1 // the second shirt
  }
}
```

If the customer wants to return a shirt, we return the item in position `1`,
subposition `0`.

Let's use the [Return cart items](/integration-api#tag/Customer-sessions/operation/returnCartItems) endpoint to
create a return request for one of the shirts in the cart.
We can use the `quantity` optional property to indicate how many units of a given item
we want to return.

The request contains the following body:

```json title="Return request"
{
  "return":{
    "returnedCartItems": [
      {
        "position": 1, // cart item to partially return
        "quantity": 1 // number of units to return
      }
    ]
  }
}
```

:::note
We can also return items [directly in the Campaign Manager](/docs/product/applications/display-customer-sessions.md#return-individual-cart-items).

If we do this, we still have to take care of any expected rollback effects.
:::

Because of the return request, we receive a [`rollbackDiscount`](/docs/dev/integration-api/api-effects.md#rollbackdiscount)
effect to undo the discount effect applied during the closing of the session.

For the item we returned, we get the following `effects` array in the response:

```json title="Rollback effect"
{
  "effects": [
    {
      //...
      "effectType": "rollbackDiscount",
      "props": {
        "name": "5forALL",
        "value": 5,
        "cartItemPosition": 1,
        "cartItemSubPosition": 0
      }
    }
  ]
}
```

The session state automatically changes from `closed` to `partially returned`, and the
impact of the effect on any [campaign budgets](/docs/product/campaigns/settings/manage-campaign-budgets.md#discount-limits)
is reverted.

At this point, the rest of the workflow happens in our e-commerce app, where we apply
the necessary steps to refund the correct amount.

## Related pages

- [Cart item flattening](/docs/product/rules/cart-item-flattening.md)
- [Display customer sessions](/docs/product/applications/display-customer-sessions.md)
- [API discount effects](/docs/dev/integration-api/api-effects.md#discounts)
- [Manage general settings](/docs/product/applications/manage-general-settings.md)
- [Cancel a session with campaign budgets](/docs/dev/tutorials/roll-back-effects.md)
