> For the complete documentation index, see [llms.txt](https://docs.qiro.fi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.qiro.fi/developer-section/openapi-spec/facility-closures/prepare-the-next-facility-closure-transaction.md).

# Prepare the next facility closure transaction

Refreshes current obligations and returns the next unsigned transaction. Call this endpoint after a `TOKEN_APPROVAL` transaction confirms, or to retry an expired preparation. The `FACILITY_CLOSURE` action uses the fixed creation-time maximum while refreshing current obligations. The partner signs and broadcasts using the designated wallet.

```json
{"openapi":"3.1.0","info":{"title":"Qiro Partner Instant Settlement API","version":"1.0.0-draft"},"tags":[{"name":"Facility closures","description":"Preview, prepare, and track full repayment and closure of a facility."}],"servers":[{"url":"/","description":"Qiro API host supplied to the partner during onboarding."}],"security":[{"oauth2":["closures:write"]}],"components":{"securitySchemes":{"oauth2":{"type":"oauth2","flows":{"clientCredentials":{"tokenUrl":"/oauth/token","scopes":{"facilities:read":"Read facilities owned by the authenticated partner.","drawdowns:read":"Read partner drawdown resources.","drawdowns:write":"Create and prepare partner drawdowns.","repayments:read":"Read dues quotes and repayment resources.","repayments:write":"Create and prepare repayments.","closures:read":"Read facility closure dues and closure resources.","closures:write":"Create and prepare facility closures."}}}}},"parameters":{"ClosureId":{"name":"closure_id","in":"path","required":true,"description":"Stable Qiro identifier for one facility closure workflow.","schema":{"type":"string","pattern":"^fcl_[A-Za-z0-9]+$"}},"OptionalCorrelationId":{"name":"X-Correlation-ID","in":"header","required":false,"description":"Optional end-to-end request identifier. The SDK supplies one automatically; Qiro generates and echoes one when absent.","schema":{"type":"string","minLength":1,"maxLength":128}}},"headers":{"CorrelationId":{"description":"Echo of the request correlation identifier.","schema":{"type":"string","minLength":1,"maxLength":128}}},"schemas":{"FacilityClosurePreparation":{"type":"object","additionalProperties":false,"required":["closure_id","status","action","sequence","amount_base_units","maximum_closure_base_units","expires_at","transaction"],"properties":{"closure_id":{"type":"string","pattern":"^fcl_[A-Za-z0-9]+$"},"status":{"$ref":"#/components/schemas/FacilityClosureStatus"},"action":{"type":"string","enum":["TOKEN_APPROVAL","FACILITY_CLOSURE"]},"sequence":{"type":"integer","minimum":1},"amount_base_units":{"$ref":"#/components/schemas/UnsignedIntegerString"},"maximum_closure_base_units":{"$ref":"#/components/schemas/UnsignedIntegerString"},"expires_at":{"type":"string","format":"date-time"},"transaction":{"$ref":"#/components/schemas/UnsignedTransaction"}}},"FacilityClosureStatus":{"type":"string","enum":["READY_FOR_SUBMISSION","SUBMITTING","CONFIRMING","CLOSED","FAILED"]},"UnsignedIntegerString":{"type":"string","pattern":"^(0|[1-9]\\d*)$"},"UnsignedTransaction":{"type":"object","additionalProperties":false,"required":["chain_id","to","data","value"],"properties":{"chain_id":{"type":"integer","minimum":1},"to":{"$ref":"#/components/schemas/EvmAddress"},"data":{"type":"string","pattern":"^0x(?:[a-fA-F0-9]{2})*$"},"value":{"$ref":"#/components/schemas/UnsignedIntegerString"}}},"EvmAddress":{"type":"string","pattern":"^0x[a-fA-F0-9]{40}$"},"ErrorResponse":{"type":"object","additionalProperties":false,"required":["error"],"properties":{"error":{"type":"object","additionalProperties":false,"required":["code","message"],"properties":{"code":{"type":"string","description":"Stable machine-readable error code."},"message":{"type":"string","description":"Safe human-readable explanation."},"request_id":{"type":"string"},"correlation_id":{"type":"string"},"retryable":{"type":"boolean"},"details":{"type":"object","additionalProperties":true},"issues":{"type":"array","items":{"type":"string"}}}}}}},"responses":{"BadRequest":{"description":"Invalid schema, field format, or correlation identifier.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"Unauthorized":{"description":"The bearer token is missing, invalid, or expired.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"Forbidden":{"description":"The authenticated partner does not own the resource or lacks the required scope.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"ResourceNotFound":{"description":"The requested workflow resource was not found for the authenticated partner.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"ResourceConflict":{"description":"Idempotency, workflow state, or verified facility identity conflicts with the request.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"EligibilityRejected":{"description":"The request is valid but rejected by facility, policy, liquidity, or contract rules.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"ServiceUnavailable":{"description":"Contract, RPC, subgraph, or reconciliation infrastructure is temporarily unavailable.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}},"paths":{"/v1/facility-closures/{closure_id}/prepare":{"post":{"tags":["Facility closures"],"operationId":"prepareFacilityClosure","summary":"Prepare the next facility closure transaction","description":"Refreshes current obligations and returns the next unsigned transaction. Call this endpoint\nafter a `TOKEN_APPROVAL` transaction confirms, or to retry an expired preparation. The\n`FACILITY_CLOSURE` action uses the fixed creation-time maximum while refreshing current\nobligations. The partner signs and broadcasts using the designated wallet.\n","parameters":[{"$ref":"#/components/parameters/ClosureId"},{"$ref":"#/components/parameters/OptionalCorrelationId"}],"responses":{"200":{"description":"Next unsigned transaction in the facility closure flow.","headers":{"X-Correlation-ID":{"$ref":"#/components/headers/CorrelationId"}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/FacilityClosurePreparation"}}}},"400":{"$ref":"#/components/responses/BadRequest"},"401":{"$ref":"#/components/responses/Unauthorized"},"403":{"$ref":"#/components/responses/Forbidden"},"404":{"$ref":"#/components/responses/ResourceNotFound"},"409":{"$ref":"#/components/responses/ResourceConflict"},"422":{"$ref":"#/components/responses/EligibilityRejected"},"503":{"$ref":"#/components/responses/ServiceUnavailable"}}}}}}
```
