# My account (https://docs.loybox.com.ar/en/api-reference/mi-cuenta)



Endpoints for the **end user**, authenticated with the access token returned by
[verifying the code](https://docs.loybox.com.ar/api-reference/autenticacion/verificar-codigo):

```
Authorization: Bearer {access}
X-Commerce-Id: {your-commerce-id}
```

Everything they return is scoped to the commerce in the `X-Commerce-Id` header:
points, benefits, history and tier belong to that program and nothing else. The
same user can be in several Loybox programs, and each one only sees its own.

## The typical circuit
This is how a loyalty website is built with these endpoints:

<Steps>
  <Step>
    ### The first render
    [`GET /v1/me`](https://docs.loybox.com.ar/api-reference/mi-cuenta/obtener) brings the points, the commerce's
    branding and the points about to expire, all at once. With a single call you paint
    the header and the balance.
  </Step>

  <Step>
    ### The catalog
    [`GET /v1/me/benefits/available`](https://docs.loybox.com.ar/api-reference/mi-cuenta/beneficios-disponibles)
    to show what they can redeem.
  </Step>

  <Step>
    ### The purchase
    [`POST /v1/me/benefits/exchange`](https://docs.loybox.com.ar/api-reference/mi-cuenta/comprar-beneficio)
    trades points for a benefit.
  </Step>

  <Step>
    ### The codes
    [`GET /v1/me/benefits`](https://docs.loybox.com.ar/api-reference/mi-cuenta/mis-beneficios) to show them the
    codes they hold to present at the commerce.
  </Step>
</Steps>

## When building the UI
Three things that save round trips:

* Each of the user's benefit `client_benefit_code` is **also the coupon code**: in
  an online store it is what the user pastes at checkout.
* Benefits carry `benefit_type`, which separates catalog ones (`normal`) from the
  special rewards (`welcome`, `birthday`, `monthly_top`, `level`), and `color`, the
  commerce's brand color.
* **How much the user is short** for a benefit is the benefit's `cost` minus the
  `points` from [`GET /v1/me`](https://docs.loybox.com.ar/api-reference/mi-cuenta/obtener).

## Buying and redeeming are not the same
|                  | Buying                                                                        | Redeeming                                                       |
| ---------------- | ----------------------------------------------------------------------------- | --------------------------------------------------------------- |
| **What it does** | Trades points for a benefit                                                   | Uses the benefit at the commerce                                |
| **Who calls it** | The user, from your website                                                   | Your server, at the sale                                        |
| **Endpoint**     | [`POST /v1/me/benefits/exchange`](https://docs.loybox.com.ar/api-reference/mi-cuenta/comprar-beneficio) | [`POST /v1/benefits/redeem`](https://docs.loybox.com.ar/api-reference/beneficios/canjear) |
| **Credential**   | End-user token                                                                | Commerce API key                                                |

## The endpoints
<Cards>
  <Card title="My account" icon="User" description="Points, commerce branding and points about to expire, in one call." href="/api-reference/mi-cuenta/obtener" />

  <Card title="Benefits I can buy" icon="Gift" description="The commerce's live catalog." href="/api-reference/mi-cuenta/beneficios-disponibles" />

  <Card title="Buy a benefit" icon="Coins" description="Trades points for a benefit. Accepts Idempotency-Key." href="/api-reference/mi-cuenta/comprar-beneficio" />

  <Card title="My benefits" icon="Tag" description="The ones already bought, with their redemption code." href="/api-reference/mi-cuenta/mis-beneficios" />

  <Card title="My history" icon="Clock" description="Consumptions, purchases, redemptions and rewards. Cursor paginated." href="/api-reference/mi-cuenta/historial" />

  <Card title="My tier" icon="Crown" description="Current tier, multiplier and progress to the next one." href="/api-reference/mi-cuenta/nivel" />

  <Card title="Program rewards" icon="Sparkles" description="Welcome, birthday and member of the month." href="/api-reference/mi-cuenta/recompensas" />

  <Card title="Join the program" icon="UserPlus" description="Joining the club. Returns the welcome reward." href="/api-reference/mi-cuenta/adherirme" />

  <Card title="Opt out" icon="Repeat" description="Leaving the club without losing the points." href="/api-reference/mi-cuenta/darme-de-baja" />
</Cards>

## The 401 across the whole section
All of these endpoints return `401` when the access token is missing, expired, or
does not belong to an end user. It is the normal case once time has passed:
[renew it](https://docs.loybox.com.ar/api-reference/autenticacion/renovar-token) and retry the call.
