{
  "openapi": "3.1.0",
  "info": {
    "title": "Connect",
    "version": "0.2.0",
    "description": "API independente do Connect para integração de qualquer sistema ao WhatsApp. IDs reservados não comprovam entrega."
  },
  "servers": [
    {
      "url": "http://127.0.0.1:3417"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "schemas": {
      "Message": {
        "type": "object",
        "required": [
          "phone",
          "type"
        ],
        "properties": {
          "phone": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "enum": [
              "text",
              "image",
              "audio",
              "video",
              "document",
              "sticker"
            ]
          },
          "text": {
            "type": "string",
            "maxLength": 16000
          },
          "base64": {
            "type": "string",
            "description": "Máximo 32 MiB decodificados"
          },
          "mimetype": {
            "type": "string"
          },
          "caption": {
            "type": "string"
          },
          "fileName": {
            "type": "string"
          },
          "ptt": {
            "type": "boolean"
          }
        }
      },
      "Accepted": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "whatsappId": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "reused": {
            "type": "boolean"
          }
        }
      }
    }
  },
  "paths": {
    "/api/projects": {
      "get": {
        "summary": "Listar projects",
        "description": "Exige chave administrativa.",
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "400": {
            "description": "Entrada inválida"
          },
          "401": {
            "description": "Autenticação necessária"
          },
          "403": {
            "description": "Acesso negado"
          }
        },
        "parameters": []
      },
      "post": {
        "summary": "Criar projects",
        "description": "Exige chave administrativa.",
        "responses": {
          "201": {
            "description": "Sucesso"
          },
          "400": {
            "description": "Entrada inválida"
          },
          "401": {
            "description": "Autenticação necessária"
          },
          "403": {
            "description": "Acesso negado"
          }
        },
        "parameters": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 2,
                    "maxLength": 70
                  },
                  "projectId": {
                    "type": [
                      "string",
                      "null"
                    ]
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/projects/{id}": {
      "patch": {
        "summary": "Atualizar projects",
        "description": "Exige chave administrativa.",
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "400": {
            "description": "Entrada inválida"
          },
          "401": {
            "description": "Autenticação necessária"
          },
          "403": {
            "description": "Acesso negado"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 2,
                    "maxLength": 70
                  },
                  "projectId": {
                    "type": [
                      "string",
                      "null"
                    ]
                  }
                }
              }
            }
          }
        }
      },
      "delete": {
        "summary": "Excluir projects",
        "description": "Exige chave administrativa.",
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "400": {
            "description": "Entrada inválida"
          },
          "401": {
            "description": "Autenticação necessária"
          },
          "403": {
            "description": "Acesso negado"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/instances": {
      "get": {
        "summary": "Listar instances",
        "description": "Exige chave administrativa.",
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "400": {
            "description": "Entrada inválida"
          },
          "401": {
            "description": "Autenticação necessária"
          },
          "403": {
            "description": "Acesso negado"
          }
        },
        "parameters": []
      },
      "post": {
        "summary": "Criar instances",
        "description": "Exige chave administrativa.",
        "responses": {
          "201": {
            "description": "Sucesso"
          },
          "400": {
            "description": "Entrada inválida"
          },
          "401": {
            "description": "Autenticação necessária"
          },
          "403": {
            "description": "Acesso negado"
          }
        },
        "parameters": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 2,
                    "maxLength": 70
                  },
                  "projectId": {
                    "type": [
                      "string",
                      "null"
                    ]
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/instances/{id}": {
      "patch": {
        "summary": "Atualizar instances",
        "description": "Exige chave administrativa.",
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "400": {
            "description": "Entrada inválida"
          },
          "401": {
            "description": "Autenticação necessária"
          },
          "403": {
            "description": "Acesso negado"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 2,
                    "maxLength": 70
                  },
                  "projectId": {
                    "type": [
                      "string",
                      "null"
                    ]
                  }
                }
              }
            }
          }
        }
      },
      "delete": {
        "summary": "Excluir instances",
        "description": "Exige chave administrativa.",
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "400": {
            "description": "Entrada inválida"
          },
          "401": {
            "description": "Autenticação necessária"
          },
          "403": {
            "description": "Acesso negado"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      },
      "get": {
        "summary": "Consultar instância",
        "description": "Autenticação com chave administrativa, da instância ou de integração.",
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "400": {
            "description": "Entrada inválida"
          },
          "401": {
            "description": "Autenticação necessária"
          },
          "403": {
            "description": "Acesso negado"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/instances/{id}/connect": {
      "post": {
        "summary": "connect",
        "description": "Exige chave administrativa.",
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "400": {
            "description": "Entrada inválida"
          },
          "401": {
            "description": "Autenticação necessária"
          },
          "403": {
            "description": "Acesso negado"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/instances/{id}/disconnect": {
      "post": {
        "summary": "disconnect",
        "description": "Exige chave administrativa.",
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "400": {
            "description": "Entrada inválida"
          },
          "401": {
            "description": "Autenticação necessária"
          },
          "403": {
            "description": "Acesso negado"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/instances/{id}/reset": {
      "post": {
        "summary": "reset",
        "description": "Exige chave administrativa.",
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "400": {
            "description": "Entrada inválida"
          },
          "401": {
            "description": "Autenticação necessária"
          },
          "403": {
            "description": "Acesso negado"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/instances/{id}/token": {
      "post": {
        "summary": "token",
        "description": "Exige chave administrativa.",
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "400": {
            "description": "Entrada inválida"
          },
          "401": {
            "description": "Autenticação necessária"
          },
          "403": {
            "description": "Acesso negado"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/instances/{id}/webhook/test": {
      "post": {
        "summary": "webhook/test",
        "description": "Exige chave administrativa.",
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "400": {
            "description": "Entrada inválida"
          },
          "401": {
            "description": "Autenticação necessária"
          },
          "403": {
            "description": "Acesso negado"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/instances/{id}/credentials": {
      "get": {
        "summary": "Consultar credentials",
        "description": "Exige chave administrativa.",
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "400": {
            "description": "Entrada inválida"
          },
          "401": {
            "description": "Autenticação necessária"
          },
          "403": {
            "description": "Acesso negado"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/instances/{id}/apps": {
      "get": {
        "summary": "Consultar apps",
        "description": "Exige chave administrativa.",
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "400": {
            "description": "Entrada inválida"
          },
          "401": {
            "description": "Autenticação necessária"
          },
          "403": {
            "description": "Acesso negado"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      },
      "post": {
        "summary": "Criar chave de sistema",
        "description": "Exige chave administrativa.",
        "responses": {
          "201": {
            "description": "Sucesso"
          },
          "400": {
            "description": "Entrada inválida"
          },
          "401": {
            "description": "Autenticação necessária"
          },
          "403": {
            "description": "Acesso negado"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "name"
                ],
                "properties": {
                  "name": {
                    "type": "string",
                    "minLength": 2,
                    "maxLength": 70
                  },
                  "projectId": {
                    "type": [
                      "string",
                      "null"
                    ]
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/instances/{id}/messages": {
      "get": {
        "summary": "Consultar messages",
        "description": "Autenticação com chave administrativa, da instância ou de integração.",
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "400": {
            "description": "Entrada inválida"
          },
          "401": {
            "description": "Autenticação necessária"
          },
          "403": {
            "description": "Acesso negado"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      },
      "post": {
        "summary": "Enfileirar mensagem",
        "description": "Autenticação com chave administrativa, da instância ou de integração.",
        "responses": {
          "202": {
            "description": "Sucesso",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Accepted"
                }
              }
            }
          },
          "400": {
            "description": "Entrada inválida"
          },
          "401": {
            "description": "Autenticação necessária"
          },
          "403": {
            "description": "Acesso negado"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "schema": {
              "type": "string",
              "maxLength": 128
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Message"
              }
            }
          }
        }
      }
    },
    "/api/instances/{id}/events": {
      "get": {
        "summary": "Consultar events",
        "description": "Autenticação com chave administrativa, da instância ou de integração.",
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "400": {
            "description": "Entrada inválida"
          },
          "401": {
            "description": "Autenticação necessária"
          },
          "403": {
            "description": "Acesso negado"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/instances/{id}/incoming": {
      "get": {
        "summary": "Consultar incoming",
        "description": "Autenticação com chave administrativa, da instância ou de integração.",
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "400": {
            "description": "Entrada inválida"
          },
          "401": {
            "description": "Autenticação necessária"
          },
          "403": {
            "description": "Acesso negado"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/instances/{id}/apps/{appId}": {
      "delete": {
        "summary": "Revogar chave",
        "description": "Exige chave administrativa.",
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "400": {
            "description": "Entrada inválida"
          },
          "401": {
            "description": "Autenticação necessária"
          },
          "403": {
            "description": "Acesso negado"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "appId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/instances/{id}/messages/{messageId}": {
      "get": {
        "summary": "Consultar ou cancelar item",
        "description": "Autenticação com chave administrativa, da instância ou de integração.",
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "400": {
            "description": "Entrada inválida"
          },
          "401": {
            "description": "Autenticação necessária"
          },
          "403": {
            "description": "Acesso negado"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "messageId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      },
      "delete": {
        "summary": "Consultar ou cancelar item",
        "description": "Autenticação com chave administrativa, da instância ou de integração.",
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "400": {
            "description": "Entrada inválida"
          },
          "401": {
            "description": "Autenticação necessária"
          },
          "403": {
            "description": "Acesso negado"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "messageId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/instances/{id}/media/{mediaId}": {
      "get": {
        "summary": "Download de mídia",
        "description": "Autenticação com chave administrativa, da instância ou de integração.",
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "400": {
            "description": "Entrada inválida"
          },
          "401": {
            "description": "Autenticação necessária"
          },
          "403": {
            "description": "Acesso negado"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "mediaId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/instances/{id}/webhook": {
      "put": {
        "summary": "Configurar webhook",
        "description": "Exige chave administrativa.",
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "400": {
            "description": "Entrada inválida"
          },
          "401": {
            "description": "Autenticação necessária"
          },
          "403": {
            "description": "Acesso negado"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "url": {
                    "type": "string",
                    "description": "URL HTTPS pública ou string vazia"
                  },
                  "received": {
                    "type": "string",
                    "description": "URL HTTPS pública ou string vazia"
                  },
                  "delivery": {
                    "type": "string",
                    "description": "URL HTTPS pública ou string vazia"
                  },
                  "status": {
                    "type": "string",
                    "description": "URL HTTPS pública ou string vazia"
                  },
                  "connected": {
                    "type": "string",
                    "description": "URL HTTPS pública ou string vazia"
                  },
                  "disconnected": {
                    "type": "string",
                    "description": "URL HTTPS pública ou string vazia"
                  },
                  "presence": {
                    "type": "string",
                    "description": "URL HTTPS pública ou string vazia"
                  },
                  "format": {
                    "type": "string",
                    "enum": [
                      "connect",
                      "legacy"
                    ],
                    "default": "connect"
                  },
                  "settings": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                      "ignoreDelivery": {
                        "type": "boolean"
                      },
                      "ignoreReceived": {
                        "type": "boolean"
                      },
                      "ignoreStatus": {
                        "type": "boolean"
                      },
                      "ignorePresence": {
                        "type": "boolean"
                      },
                      "ignoreConnected": {
                        "type": "boolean"
                      },
                      "ignoreDisconnected": {
                        "type": "boolean"
                      },
                      "notifyFromMe": {
                        "type": "boolean"
                      },
                      "ignoreGroups": {
                        "type": "boolean"
                      },
                      "ignorePrivate": {
                        "type": "boolean"
                      },
                      "ignoreText": {
                        "type": "boolean"
                      },
                      "ignoreImage": {
                        "type": "boolean"
                      },
                      "ignoreVideo": {
                        "type": "boolean"
                      },
                      "ignoreAudio": {
                        "type": "boolean"
                      },
                      "ignoreDocument": {
                        "type": "boolean"
                      },
                      "autoRejectCalls": {
                        "type": "boolean"
                      },
                      "autoReadMessages": {
                        "type": "boolean"
                      },
                      "autoReadStatus": {
                        "type": "boolean"
                      },
                      "protectAnnouncementGroups": {
                        "type": "boolean"
                      },
                      "disableOfflineQueue": {
                        "type": "boolean"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/instances/{id}/settings": {
      "put": {
        "summary": "Configurar settings",
        "description": "Exige chave administrativa.",
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "400": {
            "description": "Entrada inválida"
          },
          "401": {
            "description": "Autenticação necessária"
          },
          "403": {
            "description": "Acesso negado"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "ignoreDelivery": {
                    "type": "boolean"
                  },
                  "ignoreReceived": {
                    "type": "boolean"
                  },
                  "ignoreStatus": {
                    "type": "boolean"
                  },
                  "ignorePresence": {
                    "type": "boolean"
                  },
                  "ignoreConnected": {
                    "type": "boolean"
                  },
                  "ignoreDisconnected": {
                    "type": "boolean"
                  },
                  "notifyFromMe": {
                    "type": "boolean"
                  },
                  "ignoreGroups": {
                    "type": "boolean"
                  },
                  "ignorePrivate": {
                    "type": "boolean"
                  },
                  "ignoreText": {
                    "type": "boolean"
                  },
                  "ignoreImage": {
                    "type": "boolean"
                  },
                  "ignoreVideo": {
                    "type": "boolean"
                  },
                  "ignoreAudio": {
                    "type": "boolean"
                  },
                  "ignoreDocument": {
                    "type": "boolean"
                  },
                  "autoRejectCalls": {
                    "type": "boolean"
                  },
                  "autoReadMessages": {
                    "type": "boolean"
                  },
                  "autoReadStatus": {
                    "type": "boolean"
                  },
                  "protectAnnouncementGroups": {
                    "type": "boolean"
                  },
                  "disableOfflineQueue": {
                    "type": "boolean"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/instances/{id}/events/{eventId}/retry": {
      "post": {
        "summary": "Reprocessar webhook esgotado",
        "description": "Exige chave administrativa.",
        "responses": {
          "202": {
            "description": "Sucesso"
          },
          "400": {
            "description": "Entrada inválida"
          },
          "401": {
            "description": "Autenticação necessária"
          },
          "403": {
            "description": "Acesso negado"
          }
        },
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "eventId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/stats": {
      "get": {
        "summary": "stats",
        "description": "Exige chave administrativa.",
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "400": {
            "description": "Entrada inválida"
          },
          "401": {
            "description": "Autenticação necessária"
          },
          "403": {
            "description": "Acesso negado"
          }
        },
        "parameters": [
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "projectId",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "instanceId",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/diagnostics": {
      "get": {
        "summary": "diagnostics",
        "description": "Exige chave administrativa.",
        "responses": {
          "200": {
            "description": "Sucesso"
          },
          "400": {
            "description": "Entrada inválida"
          },
          "401": {
            "description": "Autenticação necessária"
          },
          "403": {
            "description": "Acesso negado"
          }
        },
        "parameters": []
      }
    }
  }
}
