{
  "arazzo": "1.0.1",
  "info": {
    "title": "3DAPI API workflows",
    "summary": "The multi-step tasks of the 3DAPI API, step by step.",
    "description": "Each workflow names the operations to call in order, what to pass from one to the next, and what success and failure look like. Operation ids refer to the API v2 OpenAPI document.",
    "version": "1.0.0"
  },
  "sourceDescriptions": [
    {
      "name": "dapi",
      "url": "./openapi.json",
      "type": "openapi"
    }
  ],
  "workflows": [
    {
      "workflowId": "submit_product",
      "summary": "Submit a product for review",
      "description": "Uploads a design file and creates a private product from it. 3DAPI then reviews the design, which a person does, so do not poll for it: wait for the `product.approved` or `product.rejected` webhook (or check `review.status` later), then run `publish_product`.\n\nVariants, images and attachments can be sent in the same `create_product` call; this workflow keeps the minimum.",
      "x-audience": [
        "designer"
      ],
      "inputs": {
        "type": "object",
        "required": [
          "name",
          "file_name",
          "content_type",
          "size_bytes",
          "materials"
        ],
        "properties": {
          "name": {
            "type": "string",
            "description": "Product name."
          },
          "file_name": {
            "type": "string",
            "description": "Name of the design file, for example `tracker.3mf`."
          },
          "content_type": {
            "type": "string",
            "description": "MIME type of the design file: `model/3mf`, `model/stl`, `model/obj` or `application/octet-stream`."
          },
          "size_bytes": {
            "type": "integer",
            "description": "Size of the design file in bytes, up to 150 MB."
          },
          "materials": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Catalog material ids (`mat_...`) the design may be printed in. `list_materials` lists them."
          },
          "idempotency_key": {
            "type": "string",
            "description": "A unique string for this attempt, for example a UUID. Send the same value when you retry, so the write happens once."
          }
        }
      },
      "steps": [
        {
          "stepId": "upload_design",
          "description": "Reserve an upload for the design file. Then send the file bytes to `upload_url` with the returned `method` and `headers`. That transfer goes straight to storage, not to this API, so it is not a step here; do it before the next step.",
          "operationId": "create_upload",
          "requestBody": {
            "contentType": "application/json",
            "payload": {
              "purpose": "design_file",
              "file_name": "$inputs.file_name",
              "content_type": "$inputs.content_type",
              "size_bytes": "$inputs.size_bytes"
            }
          },
          "successCriteria": [
            {
              "condition": "$statusCode == 201"
            }
          ],
          "outputs": {
            "upload_id": "$response.body#/id",
            "upload_url": "$response.body#/upload_url",
            "method": "$response.body#/method",
            "headers": "$response.body#/headers"
          }
        },
        {
          "stepId": "create_product",
          "description": "Create the private product with the uploaded file as its design. It starts with `review.status: pending`. A full plan is refused with `plan_limit_reached`, whose `details.fix_url` opens the upgrade page; a file that never reached `upload_url` is refused with `upload_missing`.",
          "operationId": "create_product",
          "parameters": [
            {
              "name": "Idempotency-Key",
              "in": "header",
              "value": "$inputs.idempotency_key"
            }
          ],
          "requestBody": {
            "contentType": "application/json",
            "payload": {
              "name": "$inputs.name",
              "designs": [
                {
                  "key": "main",
                  "file": {
                    "upload": "$steps.upload_design.outputs.upload_id"
                  },
                  "materials": {
                    "mode": "single",
                    "allowed": "$inputs.materials"
                  }
                }
              ]
            }
          },
          "successCriteria": [
            {
              "condition": "$statusCode == 201"
            }
          ],
          "onFailure": [
            {
              "name": "retry_server_error",
              "type": "retry",
              "retryAfter": 5,
              "retryLimit": 3,
              "criteria": [
                {
                  "condition": "$statusCode >= 500"
                }
              ]
            },
            {
              "name": "plan_limit_reached",
              "type": "end",
              "criteria": [
                {
                  "condition": "$statusCode == 403"
                }
              ]
            }
          ],
          "outputs": {
            "product_id": "$response.body#/id",
            "review_status": "$response.body#/review/status"
          }
        }
      ],
      "outputs": {
        "product_id": "$steps.create_product.outputs.product_id",
        "review_status": "$steps.create_product.outputs.review_status"
      }
    },
    {
      "workflowId": "publish_product",
      "summary": "Publish a product",
      "description": "Checks that nothing blocks publishing, then publishes. When something does, the first step ends the workflow and `blockers` says what to fix, in order: account blockers (business registration, store settings) are fixed in the dashboard, product blockers (category, compliance documents) through the API.",
      "x-audience": [
        "designer"
      ],
      "inputs": {
        "type": "object",
        "required": [
          "product_id"
        ],
        "properties": {
          "product_id": {
            "type": "string",
            "description": "The product to publish (`prd_...`)."
          }
        }
      },
      "steps": [
        {
          "stepId": "check_product",
          "description": "Read the product. `publishing.can_publish` is true once its designs are approved and nothing else blocks it; otherwise `publishing.blockers` lists each blocker with a `code` and what to do.",
          "operationId": "get_product",
          "parameters": [
            {
              "name": "id",
              "in": "path",
              "value": "$inputs.product_id"
            }
          ],
          "successCriteria": [
            {
              "condition": "$statusCode == 200"
            },
            {
              "condition": "$response.body#/publishing/can_publish == true"
            }
          ],
          "outputs": {
            "review_status": "$response.body#/review/status",
            "blockers": "$response.body#/publishing/blockers"
          }
        },
        {
          "stepId": "publish",
          "description": "Publish. Refused with `plan_limit_reached` when your plan limit of public products is reached, or `cannot_publish` (with `details.blockers`) if something changed since the check.",
          "operationId": "publish_product",
          "parameters": [
            {
              "name": "id",
              "in": "path",
              "value": "$inputs.product_id"
            }
          ],
          "successCriteria": [
            {
              "condition": "$statusCode == 200"
            }
          ],
          "onFailure": [
            {
              "name": "plan_limit_reached",
              "type": "end",
              "criteria": [
                {
                  "condition": "$statusCode == 403"
                }
              ]
            },
            {
              "name": "cannot_publish",
              "type": "end",
              "criteria": [
                {
                  "condition": "$statusCode == 409"
                }
              ]
            }
          ],
          "outputs": {
            "is_public": "$response.body#/publishing/is_public"
          }
        }
      ],
      "outputs": {
        "is_public": "$steps.publish.outputs.is_public",
        "blockers": "$steps.check_product.outputs.blockers"
      }
    },
    {
      "workflowId": "place_order",
      "summary": "Place an order",
      "description": "Places an order at cost (production price, shipping and VAT) paid from your wallet, with any shortfall charged to your saved card, for example for a sale on your own website. Send an `Idempotency-Key` and reuse it on every retry: an order is created at most once. Follow the order with the `order.*` webhooks. To print your own file on a line instead of the variant's design, see Order with a custom file.",
      "x-audience": [
        "designer"
      ],
      "inputs": {
        "type": "object",
        "required": [
          "items",
          "customer",
          "shipping_address",
          "idempotency_key"
        ],
        "properties": {
          "items": {
            "type": "array",
            "description": "What to order: `{ \"variant\": \"var_...\", \"quantity\": 1 }` per line. Each variant must be yours, active and approved.",
            "items": {
              "type": "object"
            }
          },
          "customer": {
            "type": "object",
            "description": "The recipient: `name`, `email` and optionally `phone`."
          },
          "shipping_address": {
            "type": "object",
            "description": "Where to ship: `line1`, `city`, `country_code` (ISO alpha-2) and optionally `line2`, `state`, `postal_code`."
          },
          "reference": {
            "type": "string",
            "description": "Your own reference for the order, for example your order number."
          },
          "idempotency_key": {
            "type": "string",
            "description": "A unique string for this attempt, for example a UUID. Send the same value when you retry, so the write happens once."
          }
        }
      },
      "steps": [
        {
          "stepId": "create_order",
          "description": "Create and pay the order. It comes back `paid` and goes to production. `payment_failed` (402) means no order was created: add or update the saved card in the dashboard, then retry with the same `Idempotency-Key`. `variant_not_orderable` (422) names a variant that is unknown, inactive or not approved.",
          "operationId": "create_order",
          "parameters": [
            {
              "name": "Idempotency-Key",
              "in": "header",
              "value": "$inputs.idempotency_key"
            }
          ],
          "requestBody": {
            "contentType": "application/json",
            "payload": {
              "items": "$inputs.items",
              "customer": "$inputs.customer",
              "shipping_address": "$inputs.shipping_address",
              "reference": "$inputs.reference"
            }
          },
          "successCriteria": [
            {
              "condition": "$statusCode == 201"
            }
          ],
          "onFailure": [
            {
              "name": "retry_server_error",
              "type": "retry",
              "retryAfter": 5,
              "retryLimit": 3,
              "criteria": [
                {
                  "condition": "$statusCode >= 500"
                }
              ]
            },
            {
              "name": "payment_failed",
              "type": "end",
              "criteria": [
                {
                  "condition": "$statusCode == 402"
                }
              ]
            },
            {
              "name": "variant_not_orderable",
              "type": "end",
              "criteria": [
                {
                  "condition": "$statusCode == 422"
                }
              ]
            }
          ],
          "outputs": {
            "order_id": "$response.body#/id",
            "number": "$response.body#/number",
            "status": "$response.body#/status",
            "total": "$response.body#/charges/total"
          }
        }
      ],
      "outputs": {
        "order_id": "$steps.create_order.outputs.order_id",
        "number": "$steps.create_order.outputs.number",
        "total": "$steps.create_order.outputs.total"
      }
    },
    {
      "workflowId": "order_with_custom_file",
      "summary": "Order with a custom file",
      "description": "Prints your own .3mf or .stl on an order line instead of the variant's design, for example a keychain with a different name for every customer. Custom files are turned on per account: ask contact@dapi.digital. The variant must be a single design, and its production price is what the line costs, so the file should weigh about the same as the design it replaces. Files are not reviewed or re-sliced: they go straight to production as sent.",
      "x-audience": [
        "designer"
      ],
      "inputs": {
        "type": "object",
        "required": [
          "variant",
          "file_name",
          "content_type",
          "size_bytes",
          "customer",
          "shipping_address",
          "idempotency_key"
        ],
        "properties": {
          "variant": {
            "type": "string",
            "description": "The variant to print (`var_...`): yours, active, approved and a single design."
          },
          "file_name": {
            "type": "string",
            "description": "Name of the file to print, ending in `.3mf` or `.stl`, for example `keychain-anna.3mf`."
          },
          "content_type": {
            "type": "string",
            "description": "MIME type of the file: `model/3mf` or `model/stl`."
          },
          "size_bytes": {
            "type": "integer",
            "description": "Size of the file in bytes, up to 1 GiB."
          },
          "customer": {
            "type": "object",
            "description": "The recipient: `name`, `email` and optionally `phone`."
          },
          "shipping_address": {
            "type": "object",
            "description": "Where to ship: `line1`, `city`, `country_code` (ISO alpha-2) and optionally `line2`, `state`, `postal_code`."
          },
          "idempotency_key": {
            "type": "string",
            "description": "A unique string for this attempt, for example a UUID. Send the same value when you retry, so the write happens once."
          }
        }
      },
      "steps": [
        {
          "stepId": "upload_file",
          "description": "Reserve an upload for the file to print, with purpose `order_file`. Then send the file bytes to `upload_url` with the returned `method` and `headers`. That transfer goes straight to storage, not to this API, so it is not a step here; do it before the next step.",
          "operationId": "create_upload",
          "requestBody": {
            "contentType": "application/json",
            "payload": {
              "purpose": "order_file",
              "file_name": "$inputs.file_name",
              "content_type": "$inputs.content_type",
              "size_bytes": "$inputs.size_bytes"
            }
          },
          "successCriteria": [
            {
              "condition": "$statusCode == 201"
            }
          ],
          "outputs": {
            "upload_id": "$response.body#/id"
          }
        },
        {
          "stepId": "create_order",
          "description": "Create and pay the order, the line naming the upload in `file`. Its `items[].custom_file` shows the file. `custom_files_not_enabled` (403) means custom files are not on for your account. `variant_not_orderable` (422) also covers a variant made of several designs; an upload that is unknown, expired, already used or not a real .3mf or .stl is refused with its own 422 code. `payment_failed` (402) means no order was created.",
          "operationId": "create_order",
          "parameters": [
            {
              "name": "Idempotency-Key",
              "in": "header",
              "value": "$inputs.idempotency_key"
            }
          ],
          "requestBody": {
            "contentType": "application/json",
            "payload": {
              "items": [
                {
                  "variant": "$inputs.variant",
                  "quantity": 1,
                  "file": {
                    "upload": "$steps.upload_file.outputs.upload_id"
                  }
                }
              ],
              "customer": "$inputs.customer",
              "shipping_address": "$inputs.shipping_address"
            }
          },
          "successCriteria": [
            {
              "condition": "$statusCode == 201"
            }
          ],
          "onFailure": [
            {
              "name": "retry_server_error",
              "type": "retry",
              "retryAfter": 5,
              "retryLimit": 3,
              "criteria": [
                {
                  "condition": "$statusCode >= 500"
                }
              ]
            },
            {
              "name": "custom_files_not_enabled",
              "type": "end",
              "criteria": [
                {
                  "condition": "$statusCode == 403"
                }
              ]
            },
            {
              "name": "payment_failed",
              "type": "end",
              "criteria": [
                {
                  "condition": "$statusCode == 402"
                }
              ]
            },
            {
              "name": "not_orderable",
              "type": "end",
              "criteria": [
                {
                  "condition": "$statusCode == 422"
                }
              ]
            }
          ],
          "outputs": {
            "order_id": "$response.body#/id",
            "number": "$response.body#/number",
            "total": "$response.body#/charges/total"
          }
        }
      ],
      "outputs": {
        "order_id": "$steps.create_order.outputs.order_id",
        "number": "$steps.create_order.outputs.number",
        "total": "$steps.create_order.outputs.total"
      }
    },
    {
      "workflowId": "buy_stock",
      "summary": "Buy stock",
      "description": "Buys batches of a stock for one of its regions, paid from your wallet only: there is no card top-up, so a short balance buys nothing. Auto-reorder spends from the same wallet, so keep enough balance for both.",
      "x-audience": [
        "designer"
      ],
      "inputs": {
        "type": "object",
        "required": [
          "stock_id",
          "region_id",
          "batches",
          "idempotency_key"
        ],
        "properties": {
          "stock_id": {
            "type": "string",
            "description": "The stock to buy (`stk_...`)."
          },
          "region_id": {
            "type": "string",
            "description": "Where to produce it (`reg_...`), one of the stock regions in `restock[].region.id` of `get_stock`."
          },
          "batches": {
            "type": "integer",
            "minimum": 1,
            "description": "How many batches; each holds `units_per_batch` units."
          },
          "idempotency_key": {
            "type": "string",
            "description": "A unique string for this attempt, for example a UUID. Send the same value when you retry, so the write happens once."
          }
        }
      },
      "steps": [
        {
          "stepId": "check_stock",
          "description": "Read the stock. Only an approved stock has a price and regions. A batch costs `batch_price`.",
          "operationId": "get_stock",
          "parameters": [
            {
              "name": "id",
              "in": "path",
              "value": "$inputs.stock_id"
            }
          ],
          "successCriteria": [
            {
              "condition": "$statusCode == 200"
            },
            {
              "condition": "$response.body#/review/status == 'approved'"
            }
          ],
          "outputs": {
            "batch_price": "$response.body#/batch_price",
            "units_per_batch": "$response.body#/units_per_batch",
            "regions": "$response.body#/restock"
          }
        },
        {
          "stepId": "check_balance",
          "description": "Read the wallet. The purchase needs `batch_price` times `batches` in `balance`; top up in the dashboard when it is short.",
          "operationId": "get_wallet",
          "successCriteria": [
            {
              "condition": "$statusCode == 200"
            }
          ],
          "outputs": {
            "balance": "$response.body#/balance"
          }
        },
        {
          "stepId": "purchase",
          "description": "Buy. `insufficient_balance` (402) comes with `details.required` and `details.balance`; nothing was bought. `region_not_available` (422) means the region is not one of the stock regions.",
          "operationId": "create_stock_purchase",
          "parameters": [
            {
              "name": "Idempotency-Key",
              "in": "header",
              "value": "$inputs.idempotency_key"
            }
          ],
          "requestBody": {
            "contentType": "application/json",
            "payload": {
              "items": [
                {
                  "stock": "$inputs.stock_id",
                  "region": "$inputs.region_id",
                  "batches": "$inputs.batches"
                }
              ]
            }
          },
          "successCriteria": [
            {
              "condition": "$statusCode == 201"
            }
          ],
          "onFailure": [
            {
              "name": "retry_server_error",
              "type": "retry",
              "retryAfter": 5,
              "retryLimit": 3,
              "criteria": [
                {
                  "condition": "$statusCode >= 500"
                }
              ]
            },
            {
              "name": "insufficient_balance",
              "type": "end",
              "criteria": [
                {
                  "condition": "$statusCode == 402"
                }
              ]
            },
            {
              "name": "region_not_available",
              "type": "end",
              "criteria": [
                {
                  "condition": "$statusCode == 422"
                }
              ]
            }
          ],
          "outputs": {
            "purchase_reference": "$response.body#/purchase_reference",
            "total": "$response.body#/total",
            "batches": "$response.body#/batches"
          }
        }
      ],
      "outputs": {
        "purchase_reference": "$steps.purchase.outputs.purchase_reference",
        "total": "$steps.purchase.outputs.total"
      }
    },
    {
      "workflowId": "review_quality_check",
      "summary": "Review a quality check",
      "description": "Rules on the products a production partner photographed. Find tickets waiting for you with `list_qc_tickets?needs_your_action=true` or the `qc_ticket.needs_your_action` webhook, and look at each product's photos before deciding. Accepting every product approves the ticket and lets the order ship; a refusal goes to 3DAPI, which rules on it.",
      "x-audience": [
        "designer"
      ],
      "inputs": {
        "type": "object",
        "required": [
          "ticket_id",
          "verdicts"
        ],
        "properties": {
          "ticket_id": {
            "type": "string",
            "description": "The quality check to rule on (`qct_...`)."
          },
          "verdicts": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "description": "One verdict per product in review: `{ \"item\": \"qci_...\", \"verdict\": \"accept\" }`, or `{ \"item\": \"qci_...\", \"verdict\": \"refuse\", \"reason\": \"...\", \"photos\": [\"qcp_...\"] }` pointing at the photos that show the problem."
          }
        }
      },
      "steps": [
        {
          "stepId": "check_ticket",
          "description": "Read the ticket: it is waiting for you when `needs_your_action` is true. The products to rule on are the `items` with `status: in_review`, each with its `photos`.",
          "operationId": "get_qc_ticket",
          "parameters": [
            {
              "name": "id",
              "in": "path",
              "value": "$inputs.ticket_id"
            }
          ],
          "successCriteria": [
            {
              "condition": "$statusCode == 200"
            },
            {
              "condition": "$response.body#/needs_your_action == true"
            }
          ],
          "outputs": {
            "items": "$response.body#/items",
            "status": "$response.body#/status"
          }
        },
        {
          "stepId": "submit_review",
          "description": "Send every verdict at once: all are recorded or none is. `not_awaiting_review` (409) means the ticket or a product is no longer in review; `photo_not_on_item` (422) means a refusal points at a photo of another product or round.",
          "operationId": "review_qc_ticket",
          "parameters": [
            {
              "name": "id",
              "in": "path",
              "value": "$inputs.ticket_id"
            }
          ],
          "requestBody": {
            "contentType": "application/json",
            "payload": {
              "items": "$inputs.verdicts"
            }
          },
          "successCriteria": [
            {
              "condition": "$statusCode == 200"
            }
          ],
          "onFailure": [
            {
              "name": "not_awaiting_review",
              "type": "end",
              "criteria": [
                {
                  "condition": "$statusCode == 409"
                }
              ]
            },
            {
              "name": "photo_not_on_item",
              "type": "end",
              "criteria": [
                {
                  "condition": "$statusCode == 422"
                }
              ]
            }
          ],
          "outputs": {
            "status": "$response.body#/status",
            "blocks_shipping": "$response.body#/blocks_shipping"
          }
        }
      ],
      "outputs": {
        "status": "$steps.submit_review.outputs.status"
      }
    },
    {
      "workflowId": "quote_model_file",
      "summary": "Quote a model file",
      "description": "Uploads a model file, creates a quote and waits for the price. Slicing is automatic and usually takes seconds to a few minutes. Before your account is approved, quotes are limited per round and per day; `get_integrator_onboarding` shows the allowance.",
      "x-audience": [
        "integrator"
      ],
      "inputs": {
        "type": "object",
        "required": [
          "file_name",
          "content_type",
          "size_bytes"
        ],
        "properties": {
          "file_name": {
            "type": "string",
            "description": "Name of the model file, for example `bracket.stl`."
          },
          "content_type": {
            "type": "string",
            "description": "MIME type of the file, for example `model/stl`, `model/3mf` or `model/step`."
          },
          "size_bytes": {
            "type": "integer",
            "description": "Size of the file in bytes, up to 250 MiB."
          },
          "name": {
            "type": "string",
            "description": "A name for the quote; defaults to the file name."
          }
        }
      },
      "steps": [
        {
          "stepId": "upload_model",
          "description": "Reserve an upload for the model file. Then send the file bytes to `upload_url` with the returned `method` and `headers`. That transfer goes straight to storage, not to this API, so it is not a step here; do it before the next step.",
          "operationId": "create_upload",
          "requestBody": {
            "contentType": "application/json",
            "payload": {
              "purpose": "quote_file",
              "file_name": "$inputs.file_name",
              "content_type": "$inputs.content_type",
              "size_bytes": "$inputs.size_bytes"
            }
          },
          "successCriteria": [
            {
              "condition": "$statusCode == 201"
            }
          ],
          "outputs": {
            "upload_id": "$response.body#/id"
          }
        },
        {
          "stepId": "create_quote",
          "description": "Start pricing. `upload_limit_reached` (409) means this round is used up: request approval next. `approval_in_review` (409) means quoting resumes after the review. `daily_quote_limit_reached` (429) resets at midnight UTC.",
          "operationId": "create_quote",
          "requestBody": {
            "contentType": "application/json",
            "payload": {
              "file": {
                "upload": "$steps.upload_model.outputs.upload_id"
              },
              "name": "$inputs.name"
            }
          },
          "successCriteria": [
            {
              "condition": "$statusCode == 201"
            }
          ],
          "onFailure": [
            {
              "name": "quota_or_review",
              "type": "end",
              "criteria": [
                {
                  "condition": "$statusCode == 409"
                }
              ]
            },
            {
              "name": "daily_quote_limit_reached",
              "type": "end",
              "criteria": [
                {
                  "condition": "$statusCode == 429"
                }
              ]
            }
          ],
          "outputs": {
            "quote_id": "$response.body#/id"
          }
        },
        {
          "stepId": "wait_for_price",
          "description": "Poll the quote every few seconds until `status` is `ready` (it has a `price`) or `failed` (`failure_reason` says why; a failed quote is given back to your allowance).",
          "operationId": "get_quote",
          "parameters": [
            {
              "name": "id",
              "in": "path",
              "value": "$steps.create_quote.outputs.quote_id"
            }
          ],
          "successCriteria": [
            {
              "condition": "$statusCode == 200"
            },
            {
              "condition": "$response.body#/status == 'ready'"
            }
          ],
          "onFailure": [
            {
              "name": "still_processing",
              "type": "retry",
              "retryAfter": 5,
              "retryLimit": 120,
              "criteria": [
                {
                  "condition": "$response.body#/status == 'processing'"
                }
              ]
            },
            {
              "name": "quote_failed",
              "type": "end",
              "criteria": [
                {
                  "condition": "$response.body#/status == 'failed'"
                }
              ]
            }
          ],
          "outputs": {
            "status": "$response.body#/status",
            "price": "$response.body#/price",
            "failure_reason": "$response.body#/failure_reason"
          }
        }
      ],
      "outputs": {
        "quote_id": "$steps.create_quote.outputs.quote_id",
        "price": "$steps.wait_for_price.outputs.price"
      }
    },
    {
      "workflowId": "set_up_order_materials",
      "summary": "Choose the materials to print a quote in",
      "description": "Every extruder slot your file prints with needs a catalog material, and the print farm loads each one into its slot. When the quote is `ready`, `suggested_materials` lists those slots with the nearest catalog material to the colour and filament type in your file. Then either:\n\n- **Use the suggestions**: order with `use_suggested_materials: true`. Check `match` first: `approximate` means the catalog has nothing close to that colour (or the file gave none).\n- **Choose your own**: list the catalog (`color_hex` and `filament_type` help you match) and send `materials` as `[{ \"slot\": 2, \"material\": \"mat_...\" }]`, one entry for every slot in `suggested_materials`, no more and no fewer. A plain list of ids also works when the slots are 1, 2, 3... with no gaps.\n\nThis recipe orders in `wallet` mode; `checkout` mode takes the same `materials` and `use_suggested_materials` per line.",
      "x-audience": [
        "integrator"
      ],
      "inputs": {
        "type": "object",
        "required": [
          "quote_id",
          "use_suggested_materials",
          "quantity",
          "shipping_address",
          "customer",
          "idempotency_key"
        ],
        "properties": {
          "quote_id": {
            "type": "string",
            "description": "The quote to print (`qte_...`), from `quote_model_file`."
          },
          "use_suggested_materials": {
            "type": "boolean",
            "description": "True to print in the suggested materials; false to send your own in `materials`."
          },
          "materials": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "description": "Only when `use_suggested_materials` is false: `{ \"slot\": 1, \"material\": \"mat_...\" }` for every slot listed in the quote `suggested_materials`."
          },
          "quantity": {
            "type": "integer",
            "description": "How many units to print."
          },
          "shipping_address": {
            "type": "object",
            "description": "Where to ship: `line1`, `city`, `country_code` (ISO alpha-2) and optionally `line2`, `state`, `postal_code`."
          },
          "customer": {
            "type": "object",
            "description": "The recipient: `name`, `email` and optionally `phone`."
          },
          "idempotency_key": {
            "type": "string",
            "description": "A unique string for this attempt, for example a UUID. Send the same value when you retry, so the write happens once."
          }
        }
      },
      "steps": [
        {
          "stepId": "read_suggestions",
          "description": "Read the quote. Once it is `ready`, `suggested_materials` has one entry per slot the file prints with: the `slot`, the `file_color` and `file_filament_type` your file gives it, the suggested `material` and how close the `match` is. It is null on quotes created before suggestions existed: send `materials` for those.",
          "operationId": "get_quote",
          "parameters": [
            {
              "name": "id",
              "in": "path",
              "value": "$inputs.quote_id"
            }
          ],
          "successCriteria": [
            {
              "condition": "$statusCode == 200"
            },
            {
              "condition": "$response.body#/status == 'ready'"
            }
          ],
          "onSuccess": [
            {
              "name": "choose_own_materials",
              "type": "goto",
              "stepId": "list_catalog",
              "criteria": [
                {
                  "condition": "$inputs.use_suggested_materials == false"
                }
              ]
            }
          ],
          "onFailure": [
            {
              "name": "still_processing",
              "type": "retry",
              "retryAfter": 5,
              "retryLimit": 120,
              "criteria": [
                {
                  "condition": "$response.body#/status == 'processing'"
                }
              ]
            },
            {
              "name": "quote_failed",
              "type": "end",
              "criteria": [
                {
                  "condition": "$response.body#/status == 'failed'"
                }
              ]
            }
          ],
          "outputs": {
            "suggested_materials": "$response.body#/suggested_materials"
          }
        },
        {
          "stepId": "order_with_suggestions",
          "description": "Order in the suggested materials. `suggestions_unavailable` (422) means the quote has none: order with your own `materials` instead.",
          "operationId": "create_integrator_order",
          "parameters": [
            {
              "name": "Idempotency-Key",
              "in": "header",
              "value": "$inputs.idempotency_key"
            }
          ],
          "requestBody": {
            "contentType": "application/json",
            "payload": {
              "mode": "wallet",
              "items": [
                {
                  "quote": "$inputs.quote_id",
                  "quantity": "$inputs.quantity",
                  "use_suggested_materials": true
                }
              ],
              "shipping_address": "$inputs.shipping_address",
              "customer": "$inputs.customer"
            }
          },
          "successCriteria": [
            {
              "condition": "$statusCode == 201"
            }
          ],
          "onSuccess": [
            {
              "name": "ordered",
              "type": "end"
            }
          ],
          "onFailure": [
            {
              "name": "retry_server_error",
              "type": "retry",
              "retryAfter": 5,
              "retryLimit": 3,
              "criteria": [
                {
                  "condition": "$statusCode >= 500"
                }
              ]
            },
            {
              "name": "payment_failed",
              "type": "end",
              "criteria": [
                {
                  "condition": "$statusCode == 402"
                }
              ]
            },
            {
              "name": "material_slots_mismatch_or_not_orderable",
              "type": "end",
              "criteria": [
                {
                  "condition": "$statusCode == 422"
                }
              ]
            }
          ],
          "outputs": {
            "order_id": "$response.body#/id",
            "number": "$response.body#/number",
            "material_slots": "$response.body#/items/0/material_slots",
            "total": "$response.body#/charges/total"
          }
        },
        {
          "stepId": "list_catalog",
          "description": "List the catalog to pick a material per slot. Each material has `color_hex` and `filament_type` to compare with the `file_color` and `file_filament_type` of each slot.",
          "operationId": "list_materials",
          "successCriteria": [
            {
              "condition": "$statusCode == 200"
            }
          ],
          "outputs": {
            "materials": "$response.body#/data"
          }
        },
        {
          "stepId": "order_with_chosen_materials",
          "description": "Order with one material per slot. `material_slots_mismatch` (422) means the slots sent are not the ones the file prints with: `details.expected_slots` lists them. `material_not_allowed` (422) names a material that is not in the catalog.",
          "operationId": "create_integrator_order",
          "parameters": [
            {
              "name": "Idempotency-Key",
              "in": "header",
              "value": "$inputs.idempotency_key"
            }
          ],
          "requestBody": {
            "contentType": "application/json",
            "payload": {
              "mode": "wallet",
              "items": [
                {
                  "quote": "$inputs.quote_id",
                  "quantity": "$inputs.quantity",
                  "materials": "$inputs.materials"
                }
              ],
              "shipping_address": "$inputs.shipping_address",
              "customer": "$inputs.customer"
            }
          },
          "successCriteria": [
            {
              "condition": "$statusCode == 201"
            }
          ],
          "onFailure": [
            {
              "name": "retry_server_error",
              "type": "retry",
              "retryAfter": 5,
              "retryLimit": 3,
              "criteria": [
                {
                  "condition": "$statusCode >= 500"
                }
              ]
            },
            {
              "name": "payment_failed",
              "type": "end",
              "criteria": [
                {
                  "condition": "$statusCode == 402"
                }
              ]
            },
            {
              "name": "material_slots_mismatch_or_not_orderable",
              "type": "end",
              "criteria": [
                {
                  "condition": "$statusCode == 422"
                }
              ]
            }
          ],
          "outputs": {
            "order_id": "$response.body#/id",
            "number": "$response.body#/number",
            "material_slots": "$response.body#/items/0/material_slots",
            "total": "$response.body#/charges/total"
          }
        }
      ]
    },
    {
      "workflowId": "estimate_order_shipping",
      "summary": "Get the shipping cost of an order",
      "description": "Prices shipping for an order before you place it, from the same items you would send to `create_integrator_order`: the quotes, how many of each and any extras, which change the weight. It runs the calculation the order charges with and creates nothing, so you can show your customer the shipping before they buy.\n\nThe parcel is priced at the tier of its heaviest item, plus a charge for each other item (extra-small items travel free). VAT is not included: `checkout` mode adds it for buyers in the EU and UK. A rate card change between the estimate and the order changes the price, so estimate close to ordering.",
      "x-audience": [
        "integrator"
      ],
      "inputs": {
        "type": "object",
        "required": [
          "country",
          "items"
        ],
        "properties": {
          "country": {
            "type": "string",
            "description": "Destination country, ISO alpha-2 (for example `DE`)."
          },
          "items": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "description": "The order lines: `{ \"quote\": \"qte_...\", \"quantity\": 2 }`, with `extras: [{ \"extra\": \"xtr_...\", \"quantity_per_unit\": 1 }]` when the units ship with extras. Every quote must be `ready`."
          }
        }
      },
      "steps": [
        {
          "stepId": "estimate",
          "description": "`quote_not_ready` (422) means a quote is still processing or failed. `shipping_destination_not_served` (422) means 3DAPI does not deliver to that country (Russia, Belarus, Iran or Syria); every other country is served, and `get_shipping_rates` lists the zones. `tier` and `zone` are null when the order cannot be weighed, and the total is then the flat delivery price.",
          "operationId": "estimate_integrator_order_shipping",
          "requestBody": {
            "contentType": "application/json",
            "payload": {
              "country": "$inputs.country",
              "items": "$inputs.items"
            }
          },
          "successCriteria": [
            {
              "condition": "$statusCode == 200"
            }
          ],
          "onFailure": [
            {
              "name": "quote_not_found",
              "type": "end",
              "criteria": [
                {
                  "condition": "$statusCode == 404"
                }
              ]
            },
            {
              "name": "not_ready_or_not_served",
              "type": "end",
              "criteria": [
                {
                  "condition": "$statusCode == 422"
                }
              ]
            }
          ],
          "outputs": {
            "total": "$response.body#/total",
            "tier": "$response.body#/tier",
            "zone": "$response.body#/zone",
            "additional_items": "$response.body#/additional_items"
          }
        }
      ],
      "outputs": {
        "total": "$steps.estimate.outputs.total",
        "tier": "$steps.estimate.outputs.tier"
      }
    },
    {
      "workflowId": "request_integrator_approval",
      "summary": "Submit sample files for review",
      "description": "Your integrator account is approved once 10 files are approved. Quote files with `quote_model_file` until `files_to_submit` quotes are `ready`, then run this. People review the request file by file, which usually takes 24 to 48 hours, so do not poll: you get an email when it is done, and `get_integrator_onboarding` then shows the outcome. After a review with rejections, quote corrected files and run this again; approved files stay approved. What gets a file approved (print settings, colours, geometry) is in the File requirements guide: https://public-api.dapi.digital/docs/guides/file-requirements.",
      "x-audience": [
        "integrator"
      ],
      "inputs": {
        "type": "object",
        "properties": {}
      },
      "steps": [
        {
          "stepId": "check_onboarding",
          "description": "Read where the account stands. A request can be sent while `status` is `collecting` or `changes_requested`; `files_to_submit` is how many ready quotes it needs.",
          "operationId": "get_integrator_onboarding",
          "successCriteria": [
            {
              "condition": "$statusCode == 200"
            },
            {
              "condition": "$response.body#/status == 'collecting' || $response.body#/status == 'changes_requested'"
            }
          ],
          "outputs": {
            "status": "$response.body#/status",
            "files_to_submit": "$response.body#/files_to_submit",
            "approved_files": "$response.body#/approved_files"
          }
        },
        {
          "stepId": "send_request",
          "description": "Send the request. Without `quotes`, your latest eligible quotes are picked; to choose them, send `quotes` with exactly `files_to_submit` ids. `not_enough_ready_quotes` (422) gives `details.required` and `details.available`.",
          "operationId": "create_approval_request",
          "requestBody": {
            "contentType": "application/json",
            "payload": {}
          },
          "successCriteria": [
            {
              "condition": "$statusCode == 201"
            }
          ],
          "onFailure": [
            {
              "name": "not_enough_ready_quotes",
              "type": "end",
              "criteria": [
                {
                  "condition": "$statusCode == 422"
                }
              ]
            },
            {
              "name": "already_approved_or_in_review",
              "type": "end",
              "criteria": [
                {
                  "condition": "$statusCode == 409"
                }
              ]
            }
          ],
          "outputs": {
            "request_id": "$response.body#/id",
            "status": "$response.body#/status"
          }
        }
      ],
      "outputs": {
        "request_id": "$steps.send_request.outputs.request_id"
      }
    }
  ]
}
