{
  "openapi": "3.0.3",
  "info": {
    "title": "NFE Orbit API",
    "description": "API fiscal da Orbit Cloud para emissao de documentos, NFS-e, DCE, monitor de entrada contra CNPJ, XML, DANFE/DANFSe, manifesto e webhooks.",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "https://api.orbitcloud.com/api/v1",
      "description": "Producao"
    },
    {
      "url": "https://sandbox.orbitcloud.com/api/v1",
      "description": "Homologacao"
    }
  ],
  "tags": [
    {
      "name": "Documentos",
      "description": "Emissao e consulta de documentos fiscais"
    },
    {
      "name": "NFS-e",
      "description": "Nota fiscal de servico, DPS e DANFSe"
    },
    {
      "name": "DCE",
      "description": "Documento de conteudo eletronico"
    },
    {
      "name": "Entrada",
      "description": "Monitoramento de notas emitidas contra o CNPJ"
    },
    {
      "name": "Webhooks",
      "description": "Eventos enviados para sistemas integrados"
    }
  ],
  "paths": {
    "/documents": {
      "post": {
        "tags": [
          "Documentos"
        ],
        "summary": "Emitir documento fiscal",
        "description": "Cria uma solicitacao de emissao para NF-e, NFC-e, CT-e, MDF-e ou DCE. Para NFS-e, use os endpoints de servicos.",
        "operationId": "createDocument",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateDocumentRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Documento criado para processamento",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DocumentResponse"
                }
              }
            }
          },
          "400": {
            "description": "Payload invalido",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      },
      "get": {
        "tags": [
          "Documentos"
        ],
        "summary": "Listar documentos fiscais",
        "operationId": "listDocuments",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "tenant",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Identificador do CNPJ/empresa"
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "draft",
                "processing",
                "authorized",
                "rejected",
                "cancelled"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Lista de documentos",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/DocumentResponse"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/documents/{id}": {
      "get": {
        "tags": [
          "Documentos"
        ],
        "summary": "Consultar documento fiscal",
        "operationId": "getDocument",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Documento fiscal",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DocumentResponse"
                }
              }
            }
          }
        }
      }
    },
    "/documents/{id}/xml": {
      "get": {
        "tags": [
          "Documentos"
        ],
        "summary": "Baixar XML autorizado",
        "operationId": "downloadXml",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "XML do documento",
            "content": {
              "application/xml": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/documents/{id}/danfe": {
      "get": {
        "tags": [
          "Documentos"
        ],
        "summary": "Baixar DANFE em PDF",
        "operationId": "downloadDanfe",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "DANFE em PDF",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          }
        }
      }
    },
    "/inbound/monitor": {
      "get": {
        "tags": [
          "Entrada"
        ],
        "summary": "Monitorar notas emitidas contra o CNPJ",
        "operationId": "listInboundDocuments",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "cnpj",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "from",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          },
          {
            "name": "to",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Notas encontradas contra o CNPJ",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/InboundDocument"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/inbound/{access_key}/manifest": {
      "post": {
        "tags": [
          "Entrada"
        ],
        "summary": "Manifestar destinatario",
        "operationId": "manifestInboundDocument",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "access_key",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ManifestRequest"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Manifesto recebido"
          }
        }
      }
    },
    "/webhooks": {
      "post": {
        "tags": [
          "Webhooks"
        ],
        "summary": "Cadastrar webhook fiscal",
        "operationId": "createWebhook",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/WebhookRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Webhook cadastrado"
          }
        }
      }
    },
    "/services/invoices": {
      "post": {
        "tags": [
          "NFS-e"
        ],
        "summary": "Emitir NFS-e",
        "description": "Cria uma solicitacao de emissao de NFS-e no padrao nacional, com DPS, DANFSe e campos IBS/CBS.",
        "operationId": "createServiceInvoice",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateServiceInvoiceRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "NFS-e criada para processamento",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DocumentResponse"
                }
              }
            }
          },
          "400": {
            "description": "Payload invalido",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    },
    "/services/invoices/{id}/danfse": {
      "get": {
        "tags": [
          "NFS-e"
        ],
        "summary": "Baixar DANFSe em PDF",
        "operationId": "downloadDanfse",
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "DANFSe em PDF",
            "content": {
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT"
      }
    },
    "schemas": {
      "CreateDocumentRequest": {
        "type": "object",
        "required": [
          "tenant",
          "document_type",
          "environment",
          "payload"
        ],
        "properties": {
          "tenant": {
            "type": "string",
            "example": "matriz"
          },
          "document_type": {
            "type": "string",
            "enum": [
              "nfe",
              "nfce",
              "cte",
              "mdfe",
              "dce"
            ],
            "example": "nfe"
          },
          "operation": {
            "type": "string",
            "example": "sale"
          },
          "environment": {
            "type": "string",
            "enum": [
              "sandbox",
              "production"
            ],
            "example": "production"
          },
          "webhook_url": {
            "type": "string",
            "format": "uri",
            "example": "https://cliente.com/fiscal"
          },
          "payload": {
            "type": "object",
            "description": "Dados fiscais conforme o tipo de documento."
          }
        }
      },
      "DocumentResponse": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "example": "doc_01JY8T4K3M4B8NQX6X2C"
          },
          "document_type": {
            "type": "string",
            "example": "nfe"
          },
          "status": {
            "type": "string",
            "example": "authorized"
          },
          "access_key": {
            "type": "string",
            "example": "35260612345678000199550010000000011000000010"
          },
          "xml_url": {
            "type": "string",
            "format": "uri"
          },
          "danfe_url": {
            "type": "string",
            "format": "uri"
          }
        }
      },
      "InboundDocument": {
        "type": "object",
        "properties": {
          "access_key": {
            "type": "string"
          },
          "issuer_cnpj": {
            "type": "string"
          },
          "recipient_cnpj": {
            "type": "string"
          },
          "issue_date": {
            "type": "string",
            "format": "date"
          },
          "manifest_status": {
            "type": "string",
            "enum": [
              "pending",
              "confirmed",
              "unknown",
              "not_performed"
            ]
          },
          "xml_available": {
            "type": "boolean"
          }
        }
      },
      "ManifestRequest": {
        "type": "object",
        "required": [
          "event"
        ],
        "properties": {
          "event": {
            "type": "string",
            "enum": [
              "confirm_operation",
              "unknown_operation",
              "operation_not_performed",
              "acknowledge"
            ]
          },
          "reason": {
            "type": "string"
          }
        }
      },
      "WebhookRequest": {
        "type": "object",
        "required": [
          "url",
          "events"
        ],
        "properties": {
          "url": {
            "type": "string",
            "format": "uri"
          },
          "events": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "document.authorized",
                "document.rejected",
                "document.cancelled",
                "inbound.found",
                "manifest.updated"
              ]
            }
          },
          "secret": {
            "type": "string",
            "description": "Chave usada para assinatura dos webhooks."
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "details": {
            "type": "object"
          }
        }
      },
      "CreateServiceInvoiceRequest": {
        "type": "object",
        "required": [
          "tenant",
          "municipality_code",
          "service_code",
          "environment",
          "payload"
        ],
        "properties": {
          "tenant": {
            "type": "string",
            "example": "matriz"
          },
          "municipality_code": {
            "type": "string",
            "example": "3550308"
          },
          "service_code": {
            "type": "string",
            "example": "0107"
          },
          "environment": {
            "type": "string",
            "enum": [
              "sandbox",
              "production"
            ],
            "example": "production"
          },
          "dps": {
            "type": "object",
            "description": "Declaracao de Prestacao de Servico quando aplicavel."
          },
          "tax_reform": {
            "type": "object",
            "properties": {
              "cst": {
                "type": "string",
                "example": "000"
              },
              "cclass_trib": {
                "type": "string",
                "example": "000001"
              },
              "ibs_cbs_highlight": {
                "type": "boolean",
                "example": true
              }
            }
          },
          "webhook_url": {
            "type": "string",
            "format": "uri",
            "example": "https://cliente.com/fiscal"
          },
          "payload": {
            "type": "object",
            "description": "Dados do tomador, prestador, servico e valores."
          }
        }
      }
    }
  }
}