{
  "openapi": "3.0.3",
  "info": {
    "title": "ColdLatch integration API",
    "version": "1.0.0",
    "description": "For a company's own ERP or warehouse system: send the stock of each storage unit, read the batch blocks QA approved, and report each block as done or failed. Every call carries a key an administrator made in ColdLatch (Settings, Integrations, Keys for your own systems). The guide with worked examples is at https://coldlatch.com/guides/connect-your-erp-integration-api"
  },
  "servers": [
    {
      "url": "https://coldlatch.com/api/v1"
    }
  ],
  "security": [
    {
      "key": []
    }
  ],
  "tags": [
    {
      "name": "Stock",
      "description": "Needs a key that may send stock."
    },
    {
      "name": "Blocks",
      "description": "Needs a key that may answer for blocks."
    }
  ],
  "paths": {
    "/integration/storage-units": {
      "get": {
        "tags": [
          "Stock"
        ],
        "operationId": "listStorageUnits",
        "summary": "The storage units, to match them to locations in your system",
        "responses": {
          "200": {
            "description": "The company's storage units.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/StorageUnit"
                  }
                }
              }
            }
          },
          "401": {
            "description": "The key is missing, wrong or revoked.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but was not given this group of calls.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "More than 300 calls in a minute from one address.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/integration/storage-units/{id}/stock": {
      "put": {
        "tags": [
          "Stock"
        ],
        "operationId": "replaceStock",
        "summary": "Replace the stock recorded for a storage unit with a new list",
        "description": "The list replaces the one before it: always send everything that is in the unit, up to 500 lines. An empty list means the unit is empty. Sending the same list again is safe.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The storage unit's id, from the list of storage units.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/StockList"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The new list.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object"
                  }
                }
              }
            }
          },
          "400": {
            "description": "The body is not as described. The message names the field.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "No such storage unit in your company.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "The key is missing, wrong or revoked.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but was not given this group of calls.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "More than 300 calls in a minute from one address.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/integration/blocks": {
      "get": {
        "tags": [
          "Blocks"
        ],
        "operationId": "listBlocks",
        "summary": "The blocks waiting for your system",
        "description": "Without a parameter: the blocks QA has approved and nobody has confirmed yet. Only blocks of alerts that are still open are listed, oldest first. Asking once a minute is plenty.",
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "proposed",
                "approved",
                "rejected",
                "succeeded",
                "failed"
              ],
              "default": "approved"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The blocks in that state.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Block"
                  }
                }
              }
            }
          },
          "400": {
            "description": "Unknown status.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "The key is missing, wrong or revoked.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but was not given this group of calls.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "More than 300 calls in a minute from one address.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/integration/blocks/{id}/confirm": {
      "post": {
        "tags": [
          "Blocks"
        ],
        "operationId": "confirmBlock",
        "summary": "The block has been done in your system",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The block's id, from the list of blocks.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ConfirmBlock"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The block, now succeeded.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Block"
                }
              }
            }
          },
          "400": {
            "description": "The body is not as described.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "No such block in your company.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "The block is not approved, is already confirmed, or is one that SAP posts.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "The key is missing, wrong or revoked.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but was not given this group of calls.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "More than 300 calls in a minute from one address.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/integration/blocks/{id}/fail": {
      "post": {
        "tags": [
          "Blocks"
        ],
        "operationId": "failBlock",
        "summary": "The block could not be done; QA is told why",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The block's id, from the list of blocks.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/FailBlock"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The block, now failed. It stays open: call confirm when it has been done after all.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Block"
                }
              }
            }
          },
          "400": {
            "description": "The body is not as described.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "No such block in your company.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "The block is not approved, or is one that SAP posts.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "The key is missing, wrong or revoked.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key is valid but was not given this group of calls.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "More than 300 calls in a minute from one address.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "key": {
        "type": "http",
        "scheme": "bearer",
        "description": "A key that starts with cli_, shown once when an administrator makes it."
      }
    },
    "schemas": {
      "StorageUnit": {
        "type": "object",
        "required": [
          "id",
          "name",
          "plant",
          "storageLocation",
          "status"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string",
            "example": "Vaccine store B"
          },
          "plant": {
            "type": "string",
            "example": "1710"
          },
          "storageLocation": {
            "type": "string",
            "example": "0002"
          },
          "status": {
            "type": "string",
            "example": "active"
          }
        }
      },
      "StockItem": {
        "type": "object",
        "required": [
          "material",
          "batch",
          "quantity",
          "unit"
        ],
        "properties": {
          "material": {
            "type": "string",
            "minLength": 1,
            "maxLength": 40,
            "example": "VAC-MMR-2026"
          },
          "batch": {
            "type": "string",
            "maxLength": 10,
            "description": "An empty string for stock that is not kept by batch.",
            "example": "MMR260411"
          },
          "quantity": {
            "type": "number",
            "exclusiveMinimum": true,
            "minimum": 0,
            "maximum": 9999999999,
            "multipleOf": 0.001,
            "example": 1200
          },
          "unit": {
            "type": "string",
            "minLength": 1,
            "maxLength": 3,
            "example": "EA"
          }
        }
      },
      "StockList": {
        "type": "object",
        "required": [
          "items"
        ],
        "properties": {
          "items": {
            "type": "array",
            "maxItems": 500,
            "items": {
              "$ref": "#/components/schemas/StockItem"
            }
          }
        }
      },
      "Block": {
        "type": "object",
        "required": [
          "id",
          "ref",
          "alertId",
          "status",
          "material",
          "batch",
          "quantity",
          "unit",
          "plant",
          "storageLocation",
          "reference",
          "error"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "ref": {
            "type": "string",
            "example": "TC-000042"
          },
          "alertId": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "enum": [
              "proposed",
              "approved",
              "rejected",
              "succeeded",
              "failed"
            ]
          },
          "material": {
            "type": "string"
          },
          "batch": {
            "type": "string"
          },
          "quantity": {
            "type": "number"
          },
          "unit": {
            "type": "string"
          },
          "plant": {
            "type": "string"
          },
          "storageLocation": {
            "type": "string"
          },
          "reference": {
            "type": "string",
            "nullable": true,
            "description": "The hold or block number your system gave when confirming."
          },
          "error": {
            "type": "string",
            "nullable": true
          }
        }
      },
      "ConfirmBlock": {
        "type": "object",
        "properties": {
          "reference": {
            "type": "string",
            "maxLength": 20,
            "description": "The number of the hold or block in your system. Shown on the alert and printed in the excursion report.",
            "example": "WMS-HOLD-7781"
          }
        }
      },
      "FailBlock": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string",
            "minLength": 1,
            "maxLength": 500,
            "description": "Why the block could not be done, written for a person: QA sees it on the alert.",
            "example": "Batch MMR260411 is not in bin C-14"
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "integer"
          },
          "message": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            ]
          },
          "error": {
            "type": "string"
          }
        }
      }
    }
  }
}
