# Store products

> The products on your B7R store, the ones you can still add, and putting them on, showing, hiding, pinning, moving and taking them off.

Source: https://docs.b7r.app/store-products

> Ids, names, prices and times in the examples are samples. Read the real values from the API.

Reading needs the key area `my_store:read` and changing needs `my_store:write` beside it. The calls answer as the [My Store](https://docs.b7r.app/my-store) calls do when B7R stores are not open to your account (`409 feature_not_available`), when B7R cannot tell (`503 service_unavailable`), and before you open a store in the B7R app (`404 not_found` with `store_missing`). A change counts against `store_writes_per_minute` (`GET /v1/me?include=limits`) and takes an `Idempotency-Key`; a call sent again with the same key answers what the first answered.

A floor is the lowest price the store allows a product, worked out from its cost and B7R’s settings: it is null, and the promotions say why, when it cannot be worked out right now.

## List the products on your store

`GET /v1/my-store/products`

Oldest on the store first, at most `limit` (1 to 100, 50 by default) a page; pass `next_cursor` as `cursor` for the next one, and follow it until it is `null`: a page can be shorter than `limit`. `position` is the order the store shows them in. `hidden_reason` says why B7R hides one (`below_floor`, for one priced under its floor); `taken_down` means its design was taken down, so it cannot be shown or pinned.

Key: A key with the `my_store:read` area.

Query:

- `limit` (string)
- `cursor` (string): 1 to 256.

Answer:

- `data` (array of object, required)
  - `store_product_id` (string (uuid), required)
  - `product_id` (string (uuid), required)
  - `name` (object, required)
    - `ar` (string, required)
    - `en` (string, required)
  - `image_url` (string or null, required)
  - `retail_price` (string, required)
  - `floor_price` (string or null, required)
  - `visible` (boolean, required)
  - `pinned` (boolean, required)
  - `position` (integer, required)
  - `hidden_reason` (string or null, required)
  - `taken_down` (boolean, required)
  - `archived` (boolean, required)
  - `seo` (object, required)
    - `title` (string or null, required)
    - `description` (string or null, required)
- `next_cursor` (string or null, required)

Errors: `unauthorized` (401), `area_forbidden` (403), `account_inactive` (403), `connection_disabled` (403), `https_required` (403), `not_found` (404), `invalid_request` (400), `rate_limited` (429), `internal_error` (500), `upstream_unavailable` (502), `api_unavailable` (503), `request_expired` (503), `service_unavailable` (503), `upstream_timeout` (504), `feature_not_available` (409). See [Errors](https://docs.b7r.app/errors).

Request:

```bash
curl https://api.b7r.app/v1/my-store/products \
  -H "Authorization: Bearer $B7R_API_KEY"
```

```javascript
const res = await fetch("https://api.b7r.app/v1/my-store/products", {
  headers: {
    Authorization: `Bearer ${process.env.B7R_API_KEY}`,
  },
});
const data = await res.json();
```

```python
import os, requests

res = requests.get(
    "https://api.b7r.app/v1/my-store/products",
    headers={
        "Authorization": f"Bearer {os.environ['B7R_API_KEY']}",
    },
    timeout=30,
)
data = res.json()
```

Answer (200 OK):

```json
{
  "data": [
    {
      "store_product_id": "3c4d5e6f-7a8b-4c9d-8e1f-2a3b4c5d6e7f",
      "product_id": "4d5e6f7a-8b9c-4d0e-9f2a-3b4c5d6e7f8a",
      "name": {
        "ar": "قميص الخط العربي",
        "en": "Calligraphy shirt"
      },
      "image_url": "https://media.b7r.sa/mockups/shirt.jpg",
      "retail_price": "120.00",
      "floor_price": "84.00",
      "visible": true,
      "pinned": true,
      "position": 0,
      "hidden_reason": null,
      "taken_down": false,
      "archived": false,
      "seo": {
        "title": null,
        "description": null
      }
    }
  ],
  "next_cursor": null
}
```

## List the products you can add

`GET /v1/my-store/products/candidates`

Your active products that are not on the store yet, newest first, paged as the list above; a page can even be empty while `next_cursor` is set, so follow it until it is `null`. `can_add` is true when the price is at or above the floor and the product’s base product is still sold. Before you open a store, these are the products the store can open with.

Key: A key with the `my_store:read` area.

Query:

- `limit` (string)
- `cursor` (string): 1 to 256.

Answer:

- `data` (array of object, required)
  - `product_id` (string (uuid), required)
  - `name` (object, required)
    - `ar` (string, required)
    - `en` (string, required)
  - `image_url` (string or null, required)
  - `retail_price` (string, required)
  - `floor_price` (string or null, required)
  - `floor_status` (string, required): One of `ok`, `below_floor`, `unavailable`.
  - `base_product_available` (boolean, required)
  - `can_add` (boolean, required)
- `next_cursor` (string or null, required)

Errors: `unauthorized` (401), `area_forbidden` (403), `account_inactive` (403), `connection_disabled` (403), `https_required` (403), `invalid_request` (400), `rate_limited` (429), `internal_error` (500), `upstream_unavailable` (502), `api_unavailable` (503), `request_expired` (503), `service_unavailable` (503), `upstream_timeout` (504), `feature_not_available` (409). See [Errors](https://docs.b7r.app/errors).

Request:

```bash
curl https://api.b7r.app/v1/my-store/products/candidates \
  -H "Authorization: Bearer $B7R_API_KEY"
```

```javascript
const res = await fetch("https://api.b7r.app/v1/my-store/products/candidates", {
  headers: {
    Authorization: `Bearer ${process.env.B7R_API_KEY}`,
  },
});
const data = await res.json();
```

```python
import os, requests

res = requests.get(
    "https://api.b7r.app/v1/my-store/products/candidates",
    headers={
        "Authorization": f"Bearer {os.environ['B7R_API_KEY']}",
    },
    timeout=30,
)
data = res.json()
```

Answer (200 OK):

```json
{
  "data": [
    {
      "product_id": "4d5e6f7a-8b9c-4d0e-9f2a-3b4c5d6e7f8a",
      "name": {
        "ar": "كوب الخط العربي",
        "en": "Calligraphy mug"
      },
      "image_url": null,
      "retail_price": "60.00",
      "floor_price": "48.00",
      "floor_status": "ok",
      "base_product_available": true,
      "can_add": true
    }
  ],
  "next_cursor": null
}
```

The calls below change the products on the store. Each answers the store product it changed, as the list gives it; `{id}` is its `store_product_id`. One that is not on your store, or is on another account’s, answers `404 not_found`, the same as one that does not exist.

> If an answer is lost and you send the call again with a new key, a second add answers `409 my_store_rejected` with `already_published`, naming the store product in `existing_id`, and a second remove answers `404`. Read `GET /v1/my-store/products` to see what happened. The same key always answers what the first call answered.

## Put a product on your store

`POST /v1/my-store/products`

Adds one of your products, by its `product_id` (as `GET /v1/products` lists it), at the end of the store, as the app does. `GET /v1/my-store/products/candidates` lists the ones you can add. Refused with `409 my_store_rejected` and the reason: `already_published` (with `existing_id`), `product_archived`, `design_taken_down`, `base_product_unavailable`, `below_floor` (its price is under the floor, given in `minimum_price`) or `store_suspended`. A product that is not yours answers `404`. When the floor cannot be worked out now, the call answers `503 service_unavailable`, which you can send again.

Key: A key with the `my_store:write` area. Send `Idempotency-Key` and `Content-Type: application/json`.

Body:

- `product_id` (string (uuid), required)

Answer:

- `product` (object, required)
  - `store_product_id` (string (uuid), required)
  - `product_id` (string (uuid), required)
  - `name` (object, required)
    - `ar` (string, required)
    - `en` (string, required)
  - `image_url` (string or null, required)
  - `retail_price` (string, required)
  - `floor_price` (string or null, required)
  - `visible` (boolean, required)
  - `pinned` (boolean, required)
  - `position` (integer, required)
  - `hidden_reason` (string or null, required)
  - `taken_down` (boolean, required)
  - `archived` (boolean, required)
  - `seo` (object, required)
    - `title` (string or null, required)
    - `description` (string or null, required)

Errors: `unauthorized` (401), `area_forbidden` (403), `account_inactive` (403), `connection_disabled` (403), `https_required` (403), `not_found` (404), `invalid_request` (400), `idempotency_key_required` (400), `request_too_large` (413), `unsupported_media_type` (415), `rate_limited` (429), `internal_error` (500), `upstream_unavailable` (502), `api_unavailable` (503), `request_expired` (503), `service_unavailable` (503), `upstream_timeout` (504), `idempotency_mismatch` (409), `idempotency_in_flight` (409), `verification_required` (403), `feature_not_available` (409), `my_store_rejected` (409). See [Errors](https://docs.b7r.app/errors).

Request:

```bash
curl -X POST https://api.b7r.app/v1/my-store/products \
  -H "Authorization: Bearer $B7R_API_KEY" \
  -H "Idempotency-Key: $(uuidgen 2>/dev/null || node -e 'console.log(crypto.randomUUID())')" \
  -H "Content-Type: application/json" \
  -d '{
    "product_id": "4d5e6f7a-8b9c-4d0e-9f2a-3b4c5d6e7f8a"
  }'
```

```javascript
const res = await fetch("https://api.b7r.app/v1/my-store/products", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.B7R_API_KEY}`,
    "Idempotency-Key": crypto.randomUUID(),
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "product_id": "4d5e6f7a-8b9c-4d0e-9f2a-3b4c5d6e7f8a"
  }),
});
const data = await res.json();
```

```python
import os, requests, uuid

res = requests.post(
    "https://api.b7r.app/v1/my-store/products",
    headers={
        "Authorization": f"Bearer {os.environ['B7R_API_KEY']}",
        "Idempotency-Key": str(uuid.uuid4()),
    },
    json={
        "product_id": "4d5e6f7a-8b9c-4d0e-9f2a-3b4c5d6e7f8a"
    },
    timeout=30,
)
data = res.json()
```

Answer (201 Created):

```json
{
  "product": {
    "store_product_id": "3c4d5e6f-7a8b-4c9d-8e1f-2a3b4c5d6e7f",
    "product_id": "4d5e6f7a-8b9c-4d0e-9f2a-3b4c5d6e7f8a",
    "name": {
      "ar": "قميص الخط العربي",
      "en": "Calligraphy shirt"
    },
    "image_url": "https://media.b7r.sa/mockups/shirt.jpg",
    "retail_price": "120.00",
    "floor_price": "84.00",
    "visible": true,
    "pinned": true,
    "position": 0,
    "hidden_reason": null,
    "taken_down": false,
    "archived": false,
    "seo": {
      "title": null,
      "description": null
    }
  }
}
```

## Take a product off your store

`POST /v1/my-store/products/{id}/remove`

Takes it off the store only: the product itself and the other stores that sell it are not changed.

Key: A key with the `my_store:write` area. Send `Idempotency-Key`.

Path:

- `id` (string (uuid), required)

Answer:

- `removed` (constant, required): Always `true`.
- `store_product_id` (string (uuid), required)

Errors: `unauthorized` (401), `area_forbidden` (403), `account_inactive` (403), `connection_disabled` (403), `https_required` (403), `not_found` (404), `invalid_request` (400), `idempotency_key_required` (400), `request_too_large` (413), `unsupported_media_type` (415), `rate_limited` (429), `internal_error` (500), `upstream_unavailable` (502), `api_unavailable` (503), `request_expired` (503), `service_unavailable` (503), `upstream_timeout` (504), `idempotency_mismatch` (409), `idempotency_in_flight` (409), `feature_not_available` (409). See [Errors](https://docs.b7r.app/errors).

Request:

```bash
curl -X POST https://api.b7r.app/v1/my-store/products/{id}/remove \
  -H "Authorization: Bearer $B7R_API_KEY" \
  -H "Idempotency-Key: $(uuidgen 2>/dev/null || node -e 'console.log(crypto.randomUUID())')"
```

```javascript
const res = await fetch("https://api.b7r.app/v1/my-store/products/{id}/remove", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.B7R_API_KEY}`,
    "Idempotency-Key": crypto.randomUUID(),
  },
});
const data = await res.json();
```

```python
import os, requests, uuid

res = requests.post(
    "https://api.b7r.app/v1/my-store/products/{id}/remove",
    headers={
        "Authorization": f"Bearer {os.environ['B7R_API_KEY']}",
        "Idempotency-Key": str(uuid.uuid4()),
    },
    timeout=30,
)
data = res.json()
```

Answer (200 OK):

```json
{
  "removed": true,
  "store_product_id": "3c4d5e6f-7a8b-4c9d-8e1f-2a3b4c5d6e7f"
}
```

## Show, hide, pin or change a product on your store

`PATCH /v1/my-store/products/{id}`

Send exactly one of `visible`, `pinned` or `seo` a call. `visible: false` hides the product on the store; `pinned: true` adds it to the store’s featured products, four at most; the first pin also shows the featured section (a fifth is refused with `pin_limit`). A product whose design was taken down cannot be shown or pinned (`design_taken_down`). `seo` takes both `title` (at most 70 characters) and `description` (at most 160), empty or null for the default; new text goes to B7R’s review as it does in the app.

Key: A key with the `my_store:write` area. Send `Content-Type: application/json`, and `If-Match` with the `ETag` of your last read; `Idempotency-Key` is optional.

Path:

- `id` (string (uuid), required)

Body:

- `visible` (boolean)
- `pinned` (boolean)
- `seo` (object)
  - `title` (string or null, required)
  - `description` (string or null, required)

Answer:

- `product` (object, required)
  - `store_product_id` (string (uuid), required)
  - `product_id` (string (uuid), required)
  - `name` (object, required)
    - `ar` (string, required)
    - `en` (string, required)
  - `image_url` (string or null, required)
  - `retail_price` (string, required)
  - `floor_price` (string or null, required)
  - `visible` (boolean, required)
  - `pinned` (boolean, required)
  - `position` (integer, required)
  - `hidden_reason` (string or null, required)
  - `taken_down` (boolean, required)
  - `archived` (boolean, required)
  - `seo` (object, required)
    - `title` (string or null, required)
    - `description` (string or null, required)

Errors: `unauthorized` (401), `area_forbidden` (403), `account_inactive` (403), `connection_disabled` (403), `https_required` (403), `not_found` (404), `invalid_request` (400), `idempotency_key_required` (400), `request_too_large` (413), `unsupported_media_type` (415), `rate_limited` (429), `internal_error` (500), `upstream_unavailable` (502), `api_unavailable` (503), `request_expired` (503), `service_unavailable` (503), `upstream_timeout` (504), `idempotency_mismatch` (409), `idempotency_in_flight` (409), `verification_required` (403), `feature_not_available` (409), `my_store_rejected` (409). See [Errors](https://docs.b7r.app/errors).

Request:

```bash
curl -X PATCH https://api.b7r.app/v1/my-store/products/{id} \
  -H "Authorization: Bearer $B7R_API_KEY" \
  -H "If-Match: $ETAG" \
  -H "Content-Type: application/json" \
  -d '{
    "pinned": true
  }'
```

```javascript
const res = await fetch("https://api.b7r.app/v1/my-store/products/{id}", {
  method: "PATCH",
  headers: {
    Authorization: `Bearer ${process.env.B7R_API_KEY}`,
    "If-Match": etag, // the ETag header of your last read
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "pinned": true
  }),
});
const data = await res.json();
```

```python
import os, requests

res = requests.patch(
    "https://api.b7r.app/v1/my-store/products/{id}",
    headers={
        "Authorization": f"Bearer {os.environ['B7R_API_KEY']}",
        "If-Match": etag,  # the ETag header of your last read
    },
    json={
        "pinned": True
    },
    timeout=30,
)
data = res.json()
```

Answer (200 OK):

```json
{
  "product": {
    "store_product_id": "3c4d5e6f-7a8b-4c9d-8e1f-2a3b4c5d6e7f",
    "product_id": "4d5e6f7a-8b9c-4d0e-9f2a-3b4c5d6e7f8a",
    "name": {
      "ar": "قميص الخط العربي",
      "en": "Calligraphy shirt"
    },
    "image_url": "https://media.b7r.sa/mockups/shirt.jpg",
    "retail_price": "120.00",
    "floor_price": "84.00",
    "visible": true,
    "pinned": true,
    "position": 0,
    "hidden_reason": null,
    "taken_down": false,
    "archived": false,
    "seo": {
      "title": null,
      "description": null
    }
  }
}
```

## Move a product on your store

`POST /v1/my-store/products/{id}/move`

`to` is `up`, `down` or `top`. The answer’s `position` is the product’s new place. When two changes to the order meet at once, one can answer `503 service_unavailable`: send it again.

Key: A key with the `my_store:write` area. Send `Idempotency-Key` and `Content-Type: application/json`.

Path:

- `id` (string (uuid), required)

Body:

- `to` (string, required): One of `up`, `down`, `top`.

Answer:

- `product` (object, required)
  - `store_product_id` (string (uuid), required)
  - `product_id` (string (uuid), required)
  - `name` (object, required)
    - `ar` (string, required)
    - `en` (string, required)
  - `image_url` (string or null, required)
  - `retail_price` (string, required)
  - `floor_price` (string or null, required)
  - `visible` (boolean, required)
  - `pinned` (boolean, required)
  - `position` (integer, required)
  - `hidden_reason` (string or null, required)
  - `taken_down` (boolean, required)
  - `archived` (boolean, required)
  - `seo` (object, required)
    - `title` (string or null, required)
    - `description` (string or null, required)

Errors: `unauthorized` (401), `area_forbidden` (403), `account_inactive` (403), `connection_disabled` (403), `https_required` (403), `not_found` (404), `invalid_request` (400), `idempotency_key_required` (400), `request_too_large` (413), `unsupported_media_type` (415), `rate_limited` (429), `internal_error` (500), `upstream_unavailable` (502), `api_unavailable` (503), `request_expired` (503), `service_unavailable` (503), `upstream_timeout` (504), `idempotency_mismatch` (409), `idempotency_in_flight` (409), `verification_required` (403), `feature_not_available` (409). See [Errors](https://docs.b7r.app/errors).

Request:

```bash
curl -X POST https://api.b7r.app/v1/my-store/products/{id}/move \
  -H "Authorization: Bearer $B7R_API_KEY" \
  -H "Idempotency-Key: $(uuidgen 2>/dev/null || node -e 'console.log(crypto.randomUUID())')" \
  -H "Content-Type: application/json" \
  -d '{
    "to": "top"
  }'
```

```javascript
const res = await fetch("https://api.b7r.app/v1/my-store/products/{id}/move", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.B7R_API_KEY}`,
    "Idempotency-Key": crypto.randomUUID(),
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "to": "top"
  }),
});
const data = await res.json();
```

```python
import os, requests, uuid

res = requests.post(
    "https://api.b7r.app/v1/my-store/products/{id}/move",
    headers={
        "Authorization": f"Bearer {os.environ['B7R_API_KEY']}",
        "Idempotency-Key": str(uuid.uuid4()),
    },
    json={
        "to": "top"
    },
    timeout=30,
)
data = res.json()
```

Answer (200 OK):

```json
{
  "product": {
    "store_product_id": "3c4d5e6f-7a8b-4c9d-8e1f-2a3b4c5d6e7f",
    "product_id": "4d5e6f7a-8b9c-4d0e-9f2a-3b4c5d6e7f8a",
    "name": {
      "ar": "قميص الخط العربي",
      "en": "Calligraphy shirt"
    },
    "image_url": "https://media.b7r.sa/mockups/shirt.jpg",
    "retail_price": "120.00",
    "floor_price": "84.00",
    "visible": true,
    "pinned": true,
    "position": 0,
    "hidden_reason": null,
    "taken_down": false,
    "archived": false,
    "seo": {
      "title": null,
      "description": null
    }
  }
}
```

One product’s state on the store rides its own read: `GET /v1/products/{id}?include=my_store` needs `my_store:read` beside `products:read`, and is refused with `403 area_forbidden` without it. `my_store` is null when the account has no store or B7R stores are not open to it.
