{
  "openapi": "3.1.0",
  "info": {
    "title": "Blaaiz Platform API - Attach Customer to Collection",
    "version": "1.0.0",
    "description": "Associate a collection transaction with a verified customer.\n\n**Important:** API card collections cannot be updated with this endpoint."
  },
  "tags": [
    {
      "name": "Collection"
    }
  ],
  "servers": [
    {
      "url": "https://api-prod.blaaiz.com"
    },
    {
      "url": "https://api-dev.blaaiz.com"
    }
  ],
  "components": {
    "securitySchemes": {
      "oauth2ClientCredentials": {
        "type": "oauth2",
        "description": "Use your OAuth client credentials to obtain a short-lived Bearer token from POST /oauth/token.",
        "flows": {
          "clientCredentials": {
            "tokenUrl": "/oauth/token",
            "scopes": {
              "collection:create": "Initiate collections."
            }
          }
        }
      }
    },
    "schemas": {
      "AttachCustomerRequest": {
        "type": "object",
        "properties": {
          "customer_id": {
            "type": "string",
            "description": "Unique identifier of the customer. The customer must belong to your business and be VERIFIED."
          },
          "transaction_id": {
            "type": "string",
            "description": "Unique identifier of the collection transaction."
          }
        },
        "required": [
          "customer_id",
          "transaction_id"
        ]
      },
      "AttachCustomerResponse": {
        "type": "object",
        "properties": {
          "message": {
            "type": "string"
          }
        },
        "required": [
          "message"
        ]
      },
      "Error": {
        "type": "object",
        "properties": {
          "message": {
            "type": "string"
          }
        },
        "required": [
          "message"
        ]
      }
    }
  },
  "paths": {
    "/api/external/collection/attach-customer": {
      "post": {
        "summary": "Attach customer to collection",
        "description": "Associate a collection transaction with a verified customer.\n\n**Important:** API card collections cannot be updated with this endpoint. Required scope: `collection:create`.",
        "tags": [
          "Collection"
        ],
        "security": [
          {
            "oauth2ClientCredentials": [
              "collection:create"
            ]
          }
        ],
        "parameters": [
          {
            "name": "Accept",
            "in": "header",
            "schema": {
              "type": "string",
              "default": "application/json"
            },
            "required": false,
            "description": "Content type header."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AttachCustomerRequest"
              },
              "example": {
                "customer_id": "9d4c4ec5-59ea-4130-bf8a-6a5edec401ee",
                "transaction_id": "fb87c0f8-31e3-46f3-b0d3-1ff2618565bc"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Transaction updated successfully.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AttachCustomerResponse"
                },
                "example": {
                  "message": "Transaction updated successfully."
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "api_card_collection": {
                    "value": {
                      "message": "Customer cannot be updated for API card collections."
                    }
                  },
                  "customer_not_verified": {
                    "value": {
                      "message": "Customer is not verified. Ensure you have uploaded identify docs for customer."
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "example": {
                  "message": "Invalid or missing access token"
                }
              }
            }
          }
        }
      }
    }
  }
}