> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cabrapi.com.br/llms.txt
> Use this file to discover all available pages before exploring further.

# Reordenar Categorias

> Aprenda a reordenar categorias da loja usando o endpoint PUT /stores/{storeId}/categories/reorder.

## 📌 Endpoint

`PUT /stores/{storeId}/categories/reorder`

Reordena as categorias da loja de acordo com a sequencia enviada em `categoryIds`.

***

## 🔐 Autenticação

* Rota privada.
* Envie `Authorization` com sua API Key.

***

## 🧾 Parâmetros de rota

| Parâmetro | Tipo | Obrigatório | Descrição |
| - | - | - | - |
| `storeId` | string | Sim | ID da loja |

***

## 🧍 Body

| Campo | Tipo | Obrigatório | Regras |
| - | - | - | - |
| `categoryIds` | string\[] | Sim | array com UUIDs válidos e únicos das categorias da loja, na ordem final |

***

## ✅ Exemplo de requisição

```bash theme={null}
curl -X PUT "https://api.cabrapi.com.br/v1/stores/STORE_ID/categories/reorder" \
  -H "Authorization: SUA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "categoryIds": [
      "CATEGORY_ID_3",
      "CATEGORY_ID_1",
      "CATEGORY_ID_2"
    ]
  }'
```

***

## 📦 Resposta de sucesso (200)

```json theme={null}
{
  "code": "CATEGORIES_REORDERED"
}
```

***

## ⚠️ Possíveis erros

* `400 INVALID_DATA` → payload inválido, array vazio, IDs duplicados ou elementos que não são UUIDs válidos
* `400 CATEGORY_LIST_INVALID` → um ou mais IDs não pertencem à loja
* `401 API_KEY_NOT_PROVIDED` → header `Authorization` não enviado (ou `TOKEN_NOT_PROVIDED` via Bearer)
* `401 INVALID_API_KEY` → API Key inválida (ou `INVALID_TOKEN` / `TOKEN_EXPIRED` / `SESSION_NOT_FOUND` / `SESSION_EXPIRED` / `UNAUTHENTICATED` via Bearer)
* `403 USER_DISABLED` → usuário desativado ou excluído
* `403 NO_ACTIVE_SUBSCRIPTION` → plano inativo ou expirado (ou `PENDING_2FA` via Bearer)
* `403 STORE_NOT_FOUND` → loja não encontrada ou sem permissão
* `429 RATE_LIMIT_EXCEEDED` → limite de requisições por minuto excedido
* `500 INTERNAL_SERVER_ERROR` → erro interno
* `503 SERVICE_UNAVAILABLE` → serviço ou banco de dados indisponível

***

## 📝 Observações

* O endpoint `GET /stores/{storeId}/categories` retorna as categorias ordenadas por `position`.
* O frontend deve enviar a lista completa de IDs na ordem final para garantir consistência.


## OpenAPI

````yaml PUT /stores/{storeId}/categories/reorder
openapi: 3.1.0
info:
  title: caBRAPI
  version: 1.0.0
servers:
  - url: https://api.cabrapi.com.br/v1
security: []
paths:
  /stores/{storeId}/categories/reorder:
    put:
      tags:
        - Categories
      summary: Reorder categories
      operationId: reorderCategories
      parameters:
        - $ref: '#/components/parameters/StoreId'
      requestBody:
        content:
          application/json:
            schema:
              properties:
                categoryIds:
                  items:
                    format: uuid
                    type: string
                  minItems: 1
                  type: array
                  uniqueItems: true
              required:
                - categoryIds
              type: object
        description: Ordered category IDs.
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                properties:
                  code:
                    example: CATEGORIES_REORDERED
                    type: string
                required:
                  - code
                type: object
          description: Positions updated in provided order.
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: Invalid request.
        '401':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: Missing or invalid API key.
        '403':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: Forbidden (inactive plan or insufficient permissions).
        '429':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: Rate limit exceeded.
        '500':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: Internal server error.
        '503':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
          description: Service unavailable.
      security:
        - ApiKey: []
components:
  parameters:
    StoreId:
      in: path
      name: storeId
      required: true
      schema:
        type: string
        minLength: 1
        maxLength: 50
  schemas:
    Error:
      properties:
        code:
          example: STORE_NOT_FOUND
          type: string
      required:
        - code
      type: object
  securitySchemes:
    ApiKey:
      in: header
      name: Authorization
      type: apiKey
      x-default: YOUR_API_KEY_HERE

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.