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

# Attach an NF-e issued through Cubbo's Brazilian invoicing provider

> Brazil only. Registers on the replenishment an NF-e (Nota Fiscal eletrônica, the Brazilian
fiscal invoice) that was already authorized through the invoicing provider Cubbo integrates for
your store, identified by its 44-digit access key. Cubbo stores the reference as pre-approved and
then confirms the document with the provider in the background, downloading its XML and PDF.

- Exactly one invoice per request (the `invoices` array must contain a single item).
- `purpose` says what the document covers: `REPLENISHMENT_INVOICE` for the NF-e of entry of the
  goods, `REPLENISHMENT_ADJUSTMENT_INVOICE` for an adjustment note. A replenishment can hold only
  one active invoice per purpose; cancelled invoices do not count, so a cancelled one can be
  replaced.
- If the access key is already registered in Cubbo, no new invoice is created: the existing one
  is re-synchronized with the provider and the response lists its key under `update_invoice_ids`.
- A previously recorded invoice issuing error on the replenishment is cleared.
- For `REPLENISHMENT_INVOICE`, Cubbo derives the expected quantities per lot from the invoice,
  which makes the variance report available for the replenishment.




## OpenAPI

````yaml /openapi.yaml post /replenishments/{replenishment_id}/attach-invoice
openapi: 3.1.0
info:
  title: Cubbo Clients API
  version: '1.0'
  summary: >-
    Orders, inventory, replenishments, returns, shipping and webhooks for Cubbo
    fulfillment.
  description: >
    The Cubbo Clients API connects your store, ERP or marketplace with Cubbo's
    fulfillment network.

    All endpoints except `POST /auth/token` require a bearer token; see the
    Authentication guide.

    Request and response bodies are JSON. Errors are JSON objects with an
    `error` key.
  contact:
    name: Cubbo integrations
    email: integraciones@cubbo.com
servers:
  - url: https://api.cubbo.com/v1
    description: Production
security:
  - bearerAuth: []
tags:
  - name: Authentication
    description: Exchange client credentials for a bearer token.
  - name: Orders
    description: Create, update, hold, cancel and read sales orders.
  - name: Shipping labels
    description: Read the shipping labels generated for an order.
  - name: Inventory
    description: Products and stock per store.
  - name: Lots
    description: Lot-level inventory for products with expiration or batch tracking.
  - name: Reports
    description: Bulk reports for reconciliation.
  - name: Replenishments
    description: Inbound shipments to the warehouse.
  - name: Returns
    description: Returns and exchanges.
  - name: Stores
    description: Store provisioning and settings.
  - name: Shipping methods
    description: Available shipping methods, coverage and quotes.
  - name: Click and collect
    description: Pickup points and in-store pickup orders.
paths:
  /replenishments/{replenishment_id}/attach-invoice:
    post:
      tags:
        - Replenishments
      summary: Attach an NF-e issued through Cubbo's Brazilian invoicing provider
      description: >
        Brazil only. Registers on the replenishment an NF-e (Nota Fiscal
        eletrônica, the Brazilian

        fiscal invoice) that was already authorized through the invoicing
        provider Cubbo integrates for

        your store, identified by its 44-digit access key. Cubbo stores the
        reference as pre-approved and

        then confirms the document with the provider in the background,
        downloading its XML and PDF.


        - Exactly one invoice per request (the `invoices` array must contain a
        single item).

        - `purpose` says what the document covers: `REPLENISHMENT_INVOICE` for
        the NF-e of entry of the
          goods, `REPLENISHMENT_ADJUSTMENT_INVOICE` for an adjustment note. A replenishment can hold only
          one active invoice per purpose; cancelled invoices do not count, so a cancelled one can be
          replaced.
        - If the access key is already registered in Cubbo, no new invoice is
        created: the existing one
          is re-synchronized with the provider and the response lists its key under `update_invoice_ids`.
        - A previously recorded invoice issuing error on the replenishment is
        cleared.

        - For `REPLENISHMENT_INVOICE`, Cubbo derives the expected quantities per
        lot from the invoice,
          which makes the variance report available for the replenishment.
      operationId: attachReplenishmentInvoice
      parameters:
        - name: replenishment_id
          in: path
          required: true
          description: Cubbo id of the replenishment.
          schema:
            type: integer
          example: 55001
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ReplenishmentAttachInvoiceRequest'
            example:
              invoice_type: WEBMANIA
              invoices:
                - key: '00000000000000000000000000000000000000000000'
                  identifier: '123456'
                  purpose: REPLENISHMENT_INVOICE
                  operation_type: ENTRADA
                  operation_nature: Remessa para armazenagem
      responses:
        '200':
          description: >
            Invoice registered. `new_invoice_ids` holds the ids of the invoices
            created. When the key was

            already known, `new_invoice_ids` is empty and `update_invoice_ids`
            lists the existing keys

            (comma-separated string) that were re-synchronized instead.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReplenishmentAttachInvoiceResponse'
              examples:
                created:
                  value:
                    new_invoice_ids:
                      - 8801
                alreadyKnown:
                  value:
                    new_invoice_ids: []
                    update_invoice_ids: '00000000000000000000000000000000000000000000'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '422':
          description: Validation or business error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                missingParam:
                  value:
                    error: Parameter invoices is required
                badKey:
                  value:
                    error: Parameter key must contain numbers only
                badPurpose:
                  value:
                    error: >-
                      Parameter purpose must be within ["REPLENISHMENT_INVOICE",
                      "REPLENISHMENT_ADJUSTMENT_INVOICE"]
                unsupportedType:
                  value:
                    error: only WEBMANIA is supported for now
                notFound:
                  value:
                    error: Couldn't find Replenishment with 'id'=55001
                tooManyInvoices:
                  value:
                    error: only one invoice is expected per request
                identifierExists:
                  value:
                    error: 'some identifiers provided already exist: ["123456"]'
                purposeExists:
                  value:
                    error: >-
                      some invoices with same replenishment and purpose already
                      exist: ["REPLENISHMENT_INVOICE"]
                providerError:
                  value:
                    error: 'WebmaniaError: NF-e not found'
        '500':
          $ref: '#/components/responses/InternalServerError'
      security:
        - bearerAuth: []
components:
  schemas:
    ReplenishmentAttachInvoiceRequest:
      type: object
      required:
        - invoices
      properties:
        invoice_type:
          type: string
          description: >-
            Invoicing provider that authorized the document. Only `WEBMANIA` is
            accepted today.
          enum:
            - WEBMANIA
          default: WEBMANIA
          example: WEBMANIA
        invoices:
          type: array
          description: Exactly one invoice.
          minItems: 1
          maxItems: 1
          items:
            $ref: '#/components/schemas/ReplenishmentInvoice'
    ReplenishmentAttachInvoiceResponse:
      type: object
      properties:
        new_invoice_ids:
          type: array
          description: >-
            Ids of the invoices created; empty when the key was already
            registered.
          items:
            type: integer
          example:
            - 8801
        update_invoice_ids:
          type: string
          description: >-
            Present only when the key was already registered; comma-separated
            list of the existing keys that were re-synchronized.
          example: '00000000000000000000000000000000000000000000'
    Error:
      type: object
      description: Error body returned by every failed request.
      required:
        - error
      properties:
        error:
          type: string
          description: >-
            Human-readable description of the failure. For `401` responses it is
            always `Unauthorized`.
          example: Parameter store_id is required
        message:
          type: string
          description: >-
            Present on `401` responses only; the reason the request was
            rejected.
          example: invalid token
        code:
          type:
            - string
            - 'null'
          description: >-
            Stable machine-readable code, present on some order, return and
            replenishment errors.
          example: ORDER_ALREADY_EXISTS
        context:
          type:
            - object
            - 'null'
          description: >-
            Extra data about the failure when available, for example the id of
            the conflicting order.
          additionalProperties: true
          example:
            order_id: 987654
    ReplenishmentInvoice:
      type: object
      description: >-
        An NF-e authorized through the invoicing provider Cubbo integrates for
        your store.
      required:
        - key
        - identifier
        - purpose
        - operation_type
        - operation_nature
      properties:
        key:
          type: string
          description: 44-digit NF-e access key (digits only).
          pattern: ^[0-9]{44}$
          example: '00000000000000000000000000000000000000000000'
        identifier:
          type: string
          description: >-
            Your identifier for the document (typically the NF-e number). Must
            not be in use by another active invoice.
          example: '123456'
        purpose:
          type: string
          description: What the document covers.
          enum:
            - REPLENISHMENT_INVOICE
            - REPLENISHMENT_ADJUSTMENT_INVOICE
          example: REPLENISHMENT_INVOICE
        operation_type:
          type: string
          description: >-
            Direction of the operation as printed on the NF-e (`ENTRADA` =
            incoming, `SAIDA` = outgoing).
          enum:
            - SAIDA
            - ENTRADA
          example: ENTRADA
        operation_nature:
          type: string
          description: Nature of the operation (natureza da operação) printed on the NF-e.
          example: Remessa para armazenagem
  responses:
    Unauthorized:
      description: >-
        Missing or invalid token, wrong credentials, or no access to the
        requested store.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          examples:
            invalidToken:
              value:
                error: Unauthorized
                message: invalid token
            noHeader:
              value:
                error: Unauthorized
                message: no authorization header found
            storeNotAllowed:
              value:
                error: Unauthorized
                message: not allowed to show? this Store
    InternalServerError:
      description: >-
        Unexpected error. Retry with backoff; if it persists, send the timestamp
        to Cubbo support.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error: 'unexpected error, timestamp: 1760000000'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >-
        Token returned by `POST /auth/token`, sent as `Authorization: Bearer
        <token>`.

````

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