# Keeta Open Delivery API

Version: v.1.0.7

## Servers

```
https://open.mykeeta.com/api/open/opendelivery
```

## Security

### OAuth2

OAuth2 should be the standard authentication method between parties.
- For the
**ORDERS**
 and
**MERCHANT**
 endpoints,
**Keeta**
 is responsible for credentials and token generation.
- For the
**LOGISTICS**
 endpoints, the
**Logistics Service**
 will be responsible for managing these infos.

> Webhooks are an exception and have their own authentication method, not using OAuth.

As of the time of this release only one scope will be used for all endpoints: `od.all`.
### Generating a Client Credentials Token
To generate a client credentials token, the merchant **Software Service** must retrieve the **clientId** and **clientSecret** from a **Keeta** or **Logistics Service** company and access the [/oauth/token](#operation/getToken) endpoint.
> **Keeta** provide one `clientId` and `clientSecret` credentials for  **Software Service**. Each **Software Service** is assigned only one client_id and client_secret.

### Usage
The **accessToken** field will contain the token used to authenticate against the **Open Delivery** APIs. Once you’ve obtained this token, you can provide it in the “Authorization” header of requests you make to endpoints that require client credentials scopes.
The **expiresIn** field indicates the lifetime of the access token, provided in seconds. This should be cached and re-used across requests until (or shortly before) expiration, not re-generated per request.

```
curl 
 -H 'authorization: Bearer <TOKEN>' 
 https://{baseURL}/v1/events:polling
```
> Refresh Token is not available at this version.

Type: oauth2
Token URL: oauth/token
Scopes:
- `od.all`: Access to all **Open Delivery** APIs

### apiKey

The apiKey is a key that should be generated by the endpoint's host and passed to its clients. Each client of the endpoint can have its own key. The creation and content of the key is of responsibility of the endpoint's host.
> As of the time of this release, only the **[GET /v1/merchant](#operation/getMerchant)** endpoint can require authentication via apiKey.

Type: apiKey
In: header
Name: X-API-KEY

### Sig

To enhance overall security, Keeta requires **Software services** to include a signature in the header when making requests to Keeta. The signature should be generated as follows: SHA256 hash of the request body, using the client secret as the key.

Type: apiKey
In: header
Name: X-App-Signature

## Download OpenAPI description

 - [Keeta Open Delivery API](https://api-docs.mykeeta.com/_bundle/apis/@opendelivery/opendelivery.yaml)

## Autenticação

 - [POST /oauth/token](https://api-docs.mykeeta.com/apis/opendelivery/authentication/gettoken.md): Host: **Keeta**. Lembre-se: o token só dá acesso a dados de merchants que autorizaram sua aplicação. **Corpo (`application/json`) — varia conforme o `grant_type`:** | Campo | Tipo | `app_level_token`
 - [GET /oauth/authorization/url](https://api-docs.mykeeta.com/apis/opendelivery/authentication/getauthorizationurl.md): Host: **Keeta**. Gera o link que o merchant abre para autorizar sua aplicação. | Parâmetro | Onde | Obrigatório | Descrição | | --- | --- | --- | --- | | `clientId` | query | sim | Client ID da aplic
 - [GET /oauth/authorized/{authId}/merchantInfo](https://api-docs.mykeeta.com/apis/opendelivery/authentication/getmerchantinfo.md): Host: **Keeta**. Retorna, paginadas, as lojas incluídas em uma autorização. Uso típico: tela de vínculo (mapeamento) de lojas no seu sistema. | Parâmetro | Onde | Descrição | | --- | --- | --- | | `a
 - [POST /webhook/authorization](https://api-docs.mykeeta.com/apis/opendelivery/authentication/receiveauthorizationwebhook.md): **Este endpoint é implementado por você** (Host: **Software Service**). A Keeta chama quando um merchant adiciona ou cancela a autorização de uma loja. **Configuração:** no Dev Portal, seção de webhoo
## Merchant

 - [PUT /v1/merchantOnboarding](https://api-docs.mykeeta.com/apis/opendelivery/merchantendpoints/putmerchantonboarding.md): Host: **Keeta**. Vincula o ID do merchant no seu sistema ao ID da Keeta e registra suas URLs. | Parâmetro | Onde | Descrição | | --- | --- | --- | | `merchantId` | query (obrig.) | **ID do merchant n
 - [GET /v1/merchant](https://api-docs.mykeeta.com/apis/opendelivery/merchantendpoints/getmerchant.md): Host: **Software Service**. A Keeta chama este endpoint para obter dados básicos, serviços e cardápio completo. Pode exigir `apiKey` (decisão sua). > Todo item precisa ter preço de **delivery** ou de
 - [POST /v1/merchantUpdate/{merchantId}](https://api-docs.mykeeta.com/apis/opendelivery/merchantendpoints/merchantupdate.md): Host: **Keeta**. `merchantId` = ID no seu sistema. Três formas de uso: | Corpo enviado | Efeito | | --- | --- | | Vazio | A Keeta chama seu `GET /v1/merchant` e recarrega tudo | | Só `merchantStatus`
 - [GET /v1/merchant/{id}/status](https://api-docs.mykeeta.com/apis/opendelivery/merchantendpoints/merchantstatus.md): Host: **Keeta**. `id` = ID do merchant no seu sistema. Retorna `status` (`AVAILABLE`/`UNAVAILABLE`), `services[]` (com `serviceType`, `serviceHours.weekHours`, `serviceHours.holidayHours` — horários e
 - [POST /v1/merchant/image/upload](https://api-docs.mykeeta.com/apis/opendelivery/merchantendpoints/imageupload.md): Host: **Keeta**. Envia uma imagem e recebe a URL para usar na sincronização do cardápio. | Item | Detalhe | | --- | --- | | Query | `merchantId` (obrig.) | | Corpo | `imageData` (bytes da imagem), `i
## Pedidos - Polling

 - [GET /v1/events:polling](https://api-docs.mykeeta.com/apis/opendelivery/orderspolling/pollingevents.md): Host: **Keeta**. Pré-requisito: lojas registradas com [PUT /v1/merchantOnboarding](/apis/opendelivery/merchantendpoints/putmerchantonboarding). | Parâmetro | Onde | Descrição | | --- | --- | --- | |
 - [POST /v1/events/acknowledgment](https://api-docs.mykeeta.com/apis/opendelivery/orderspolling/pollingacknowledgment.md): Host: **Keeta**. Corpo: lista de objetos com `id` (eventId), `orderId` e `eventType`. Resposta `202`. Erros: `400`, `401`, `403`, `404`, `503`. ```json [ { "id": "evt-8f2a1c", "orderId": "783441058
## Pedidos - Webhook

 - [POST /v1/newEvent](https://api-docs.mykeeta.com/apis/opendelivery/orderswebhook/newevent.md): Host: **Software Service** (implementado por você). URL típica: `https://{seu-dominio}/api/open/opendelivery/v1/newEvent` (ou a registrada em `ordersWebhookURL`). Headers: `X-App-Id`, `X-App-MerchantI
## Pedidos - Order API

 - [GET /v1/orders/{orderId}](https://api-docs.mykeeta.com/apis/opendelivery/orderapi/orderdetails.md): Host: **Keeta**. Principais campos da resposta `200`: | Campo | Descrição | | --- | --- | | `id`, `displayId` | ID do pedido e código exibido ao cliente | | `type` | `DELIVERY`, `TAKEOUT`, `INDOOR` (
 - [POST /v1/orders/{orderId}/confirm](https://api-docs.mykeeta.com/apis/opendelivery/orderapi/confirmorder.md): Host: **Keeta**. | Campo | Obrig. | Descrição | | --- | --- | --- | | `createdAt` | sim | Data/hora UTC da criação do pedido | | `orderExternalCode` | sim | Código do pedido no seu sistema | | `reaso
 - [POST /v1/orders/{orderId}/readyForPickup](https://api-docs.mykeeta.com/apis/opendelivery/orderapi/orderready.md): Host: **Keeta**. Sem corpo. `202` → espere `READY_FOR_PICKUP`. Erros: `400`, `401`, `403`, `404`, `422` (estado inválido ou repetido), `503`.
 - [POST /v1/orders/{orderId}/requestCancellation](https://api-docs.mykeeta.com/apis/opendelivery/orderapi/requestcancellation.md): Host: **Keeta**. | Campo | Obrig. | Descrição | | --- | --- | --- | | `reason` | sim | Texto livre | | `code` | sim | Ver Códigos de cancelamento (v1.0.7+) no Guia de Desenvolvimento | | `mode` | sim
 - [POST /v1/orders/{orderId}/acceptRefund](https://api-docs.mykeeta.com/apis/opendelivery/orderapi/acceptrefund.md): Host: **Keeta**. Sem corpo. `204` → espere `REFUNDED`.
 - [POST /v1/orders/{orderId}/rejectRefund](https://api-docs.mykeeta.com/apis/opendelivery/orderapi/rejectrefund.md): Host: **Keeta**. | Campo | Obrig. | Valores | | --- | --- | --- | | `reason` | sim | Texto livre | | `code` | sim | `DISH_ALREADY_DONE` (prato já preparado), `OUT_FOR_DELIVERY` (já saiu para entrega)
 - [POST /v1/batchDecrypt](https://api-docs.mykeeta.com/apis/opendelivery/orderapi/batchdecrypt.md): Somente pedidos com entrega própria ou 3PL. Até **50 itens por chamada**. Requisição: ```json { "cipherInfos": [ { "cipherText": "ENC_#MQesaE=#1#" }, { "cipherText": "ENC_#Xp91ab=#1#" } ] } ``` Respo
## Pedidos - Merchant Fulfill

 - [Quando usar](https://api-docs.mykeeta.com/apis/opendelivery/merchantfulfillapi/quando-usar.md): ### Quando usar Use estes endpoints **somente quando a logística é do merchant** (entrega própria ou 3PL contratado por ele), nunca quando a Keeta entrega. Valem **após o aceite** do pedido; pedidos c
 - [POST /v1/orders/{orderId}/dispatch](https://api-docs.mykeeta.com/apis/opendelivery/merchantfulfillapi/dispatchorder.md): Host: **Keeta**. Use somente quando a logística é do merchant (entrega própria ou 3PL contratado por ele), após o aceite do pedido. Corpo opcional `deliveryTrackingInfo`: | Bloco | Campos | | --- | -
 - [POST /v1/orders/{orderId}/delivered](https://api-docs.mykeeta.com/apis/opendelivery/merchantfulfillapi/orderdelivered.md): Host: **Keeta**. Sem corpo. Opcional; use apenas em entrega do merchant e se a Keeta esperar (`sendDelivered`). `202` → espere `DELIVERED`.
 - [POST /v1/orders/{orderId}/tracking](https://api-docs.mykeeta.com/apis/opendelivery/merchantfulfillapi/senddeliveryupdates.md): Host: **Keeta**. Use em entrega do merchant. Mesmo bloco `deliveryTrackingInfo` de [Pedido despachado](/apis/opendelivery/merchantfulfillapi/dispatchorder) (aqui obrigatório), com dois acréscimos: - `
