{
  "info": {
    "name": "Spreadu Print Lab API",
    "description": "Generated from the reviewed OpenAPI spec. Start with a test key and follow the Test your integration guide. Reset and expiry requests change sandbox state; run requests individually.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "variable": [
    {
      "key": "apiBaseUrl",
      "value": "https://api.spreadu.com/api/print-lab/v1",
      "type": "string"
    },
    {
      "key": "reference",
      "value": "<reference-from-createSandboxExport>",
      "type": "string"
    },
    {
      "key": "revision",
      "value": "1",
      "type": "string"
    },
    {
      "key": "webhookId",
      "value": "<webhook-id>",
      "type": "string"
    },
    {
      "key": "webhookUrl",
      "value": "https://<your-tunnel-host>/spreadu",
      "type": "string"
    },
    {
      "key": "orderNumber",
      "value": "",
      "type": "string"
    },
    {
      "key": "after",
      "value": "",
      "type": "string"
    },
    {
      "key": "idempotencyKey",
      "value": "",
      "type": "string"
    },
    {
      "key": "replayIdempotencyKey",
      "value": "",
      "type": "string"
    }
  ],
  "item": [
    {
      "name": "listEvents",
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{apiKey}}"
          }
        ],
        "url": "{{apiBaseUrl}}/events",
        "description": "Read the oldest retained events\n\nTest mode: use a spreadu_lab_test_ key.\n\nSend listEvents first. Every response saves nextCursor as after, also for an empty page, so listEventsAfterCursor continues where the last page ended."
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const body = pm.response.json();",
              "if (body.reference) pm.collectionVariables.set(\"reference\", body.reference);",
              "if (Number.isInteger(body.revision)) pm.collectionVariables.set(\"revision\", String(body.revision));",
              "if (body.id && body.url) pm.collectionVariables.set(\"webhookId\", body.id);",
              "if (body.nextCursor !== undefined) pm.collectionVariables.set(\"after\", body.nextCursor);"
            ]
          }
        }
      ]
    },
    {
      "name": "listEventsAfterCursor",
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{apiKey}}"
          }
        ],
        "url": "{{apiBaseUrl}}/events?after={{after}}",
        "description": "Read the events after the saved cursor\n\nTest mode: use a spreadu_lab_test_ key.\n\nSend listEvents first. Every response saves nextCursor as after, also for an empty page, so listEventsAfterCursor continues where the last page ended."
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const body = pm.response.json();",
              "if (body.reference) pm.collectionVariables.set(\"reference\", body.reference);",
              "if (Number.isInteger(body.revision)) pm.collectionVariables.set(\"revision\", String(body.revision));",
              "if (body.id && body.url) pm.collectionVariables.set(\"webhookId\", body.id);",
              "if (body.nextCursor !== undefined) pm.collectionVariables.set(\"after\", body.nextCursor);"
            ]
          }
        }
      ]
    },
    {
      "name": "listExports",
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{apiKey}}"
          }
        ],
        "url": "{{apiBaseUrl}}/exports",
        "description": "List the lab's exports\n\nTest mode: use a spreadu_lab_test_ key."
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const body = pm.response.json();",
              "if (body.reference) pm.collectionVariables.set(\"reference\", body.reference);",
              "if (Number.isInteger(body.revision)) pm.collectionVariables.set(\"revision\", String(body.revision));",
              "if (body.id && body.url) pm.collectionVariables.set(\"webhookId\", body.id);"
            ]
          }
        }
      ]
    },
    {
      "name": "getExport",
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{apiKey}}"
          }
        ],
        "url": "{{apiBaseUrl}}/exports/{{reference}}",
        "description": "Read an export and its revisions\n\nTest mode: use a spreadu_lab_test_ key."
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const body = pm.response.json();",
              "if (body.reference) pm.collectionVariables.set(\"reference\", body.reference);",
              "if (Number.isInteger(body.revision)) pm.collectionVariables.set(\"revision\", String(body.revision));",
              "if (body.id && body.url) pm.collectionVariables.set(\"webhookId\", body.id);"
            ]
          }
        }
      ]
    },
    {
      "name": "confirmExport",
      "request": {
        "method": "PUT",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{apiKey}}"
          },
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": "{{apiBaseUrl}}/exports/{{reference}}/confirmation",
        "description": "Confirm the lab's order and lock its export\n\nTest mode: use a spreadu_lab_test_ key.\n\nSet orderNumber to the order number first. It is empty on purpose, and the server refuses an empty one.",
        "body": {
          "mode": "raw",
          "raw": "{\n  \"externalOrderId\": null,\n  \"externalOrderLineId\": null,\n  \"orderNumber\": \"{{orderNumber}}\",\n  \"revision\": {{revision}}\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        }
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const body = pm.response.json();",
              "if (body.reference) pm.collectionVariables.set(\"reference\", body.reference);",
              "if (Number.isInteger(body.revision)) pm.collectionVariables.set(\"revision\", String(body.revision));",
              "if (body.id && body.url) pm.collectionVariables.set(\"webhookId\", body.id);"
            ]
          }
        }
      ]
    },
    {
      "name": "createDownloadUrls",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{apiKey}}"
          },
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": "{{apiBaseUrl}}/exports/{{reference}}/download-urls",
        "description": "Issue download URLs for an exact export revision\n\nTest mode: use a spreadu_lab_test_ key.",
        "body": {
          "mode": "raw",
          "raw": "{\n  \"revision\": {{revision}}\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        }
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const body = pm.response.json();",
              "if (body.reference) pm.collectionVariables.set(\"reference\", body.reference);",
              "if (Number.isInteger(body.revision)) pm.collectionVariables.set(\"revision\", String(body.revision));",
              "if (body.id && body.url) pm.collectionVariables.set(\"webhookId\", body.id);"
            ]
          }
        }
      ]
    },
    {
      "name": "unlockExport",
      "request": {
        "method": "DELETE",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{apiKey}}"
          }
        ],
        "url": "{{apiBaseUrl}}/exports/{{reference}}/lock",
        "description": "Unlock the album for photographer changes\n\nTest mode: use a spreadu_lab_test_ key."
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const body = pm.response.json();",
              "if (body.reference) pm.collectionVariables.set(\"reference\", body.reference);",
              "if (Number.isInteger(body.revision)) pm.collectionVariables.set(\"revision\", String(body.revision));",
              "if (body.id && body.url) pm.collectionVariables.set(\"webhookId\", body.id);"
            ]
          }
        }
      ]
    },
    {
      "name": "recordExportReceipt",
      "request": {
        "method": "PUT",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{apiKey}}"
          },
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": "{{apiBaseUrl}}/exports/{{reference}}/receipt",
        "description": "Record that the lab received a revision's files\n\nTest mode: use a spreadu_lab_test_ key.",
        "body": {
          "mode": "raw",
          "raw": "{\n  \"revision\": {{revision}}\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        }
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const body = pm.response.json();",
              "if (body.reference) pm.collectionVariables.set(\"reference\", body.reference);",
              "if (Number.isInteger(body.revision)) pm.collectionVariables.set(\"revision\", String(body.revision));",
              "if (body.id && body.url) pm.collectionVariables.set(\"webhookId\", body.id);"
            ]
          }
        }
      ]
    },
    {
      "name": "getMe",
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{apiKey}}"
          }
        ],
        "url": "{{apiBaseUrl}}/me",
        "description": "Read the lab, key and enabled modules\n\nTest mode: use a spreadu_lab_test_ key."
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const body = pm.response.json();",
              "if (body.reference) pm.collectionVariables.set(\"reference\", body.reference);",
              "if (Number.isInteger(body.revision)) pm.collectionVariables.set(\"revision\", String(body.revision));",
              "if (body.id && body.url) pm.collectionVariables.set(\"webhookId\", body.id);"
            ]
          }
        }
      ]
    },
    {
      "name": "createSandboxExport",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{apiKey}}"
          },
          {
            "key": "Content-Type",
            "value": "application/json"
          },
          {
            "key": "Idempotency-Key",
            "value": "{{idempotencyKey}}"
          }
        ],
        "url": "{{apiBaseUrl}}/sandbox/exports",
        "description": "Create a synthetic export\n\nTest mode: use a spreadu_lab_test_ key.\n\nEvery send uses a new Idempotency-Key and saves it as idempotencyKey. To replay a command on purpose, copy that saved key into replayIdempotencyKey, send the same request again, then clear replayIdempotencyKey. Any variable scope works in Postman. In Bruno, set it in the test environment: the script reads the other scopes only where the installed Bruno can read them from a script, and otherwise sends a new key.",
        "body": {
          "mode": "raw",
          "raw": "{\n  \"scenario\": \"spreads-jpg\"\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        }
      },
      "event": [
        {
          "listen": "prerequest",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const replay = pm.variables.get(\"replayIdempotencyKey\");",
              "pm.collectionVariables.set(\"idempotencyKey\", replay || pm.variables.replaceIn(\"{{$guid}}\"));"
            ]
          }
        },
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const body = pm.response.json();",
              "if (body.reference) pm.collectionVariables.set(\"reference\", body.reference);",
              "if (Number.isInteger(body.revision)) pm.collectionVariables.set(\"revision\", String(body.revision));",
              "if (body.id && body.url) pm.collectionVariables.set(\"webhookId\", body.id);"
            ]
          }
        }
      ]
    },
    {
      "name": "expireSandboxExport",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{apiKey}}"
          },
          {
            "key": "Idempotency-Key",
            "value": "{{idempotencyKey}}"
          }
        ],
        "url": "{{apiBaseUrl}}/sandbox/exports/{{reference}}/expire",
        "description": "Expire the current revision now\n\nTest mode: use a spreadu_lab_test_ key.\n\nEvery send uses a new Idempotency-Key and saves it as idempotencyKey. To replay a command on purpose, copy that saved key into replayIdempotencyKey, send the same request again, then clear replayIdempotencyKey. Any variable scope works in Postman. In Bruno, set it in the test environment: the script reads the other scopes only where the installed Bruno can read them from a script, and otherwise sends a new key."
      },
      "event": [
        {
          "listen": "prerequest",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const replay = pm.variables.get(\"replayIdempotencyKey\");",
              "pm.collectionVariables.set(\"idempotencyKey\", replay || pm.variables.replaceIn(\"{{$guid}}\"));"
            ]
          }
        },
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const body = pm.response.json();",
              "if (body.reference) pm.collectionVariables.set(\"reference\", body.reference);",
              "if (Number.isInteger(body.revision)) pm.collectionVariables.set(\"revision\", String(body.revision));",
              "if (body.id && body.url) pm.collectionVariables.set(\"webhookId\", body.id);"
            ]
          }
        }
      ]
    },
    {
      "name": "warnSandboxExpiry",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{apiKey}}"
          },
          {
            "key": "Idempotency-Key",
            "value": "{{idempotencyKey}}"
          }
        ],
        "url": "{{apiBaseUrl}}/sandbox/exports/{{reference}}/expiring",
        "description": "Emit a retention warning\n\nTest mode: use a spreadu_lab_test_ key.\n\nEvery send uses a new Idempotency-Key and saves it as idempotencyKey. To replay a command on purpose, copy that saved key into replayIdempotencyKey, send the same request again, then clear replayIdempotencyKey. Any variable scope works in Postman. In Bruno, set it in the test environment: the script reads the other scopes only where the installed Bruno can read them from a script, and otherwise sends a new key."
      },
      "event": [
        {
          "listen": "prerequest",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const replay = pm.variables.get(\"replayIdempotencyKey\");",
              "pm.collectionVariables.set(\"idempotencyKey\", replay || pm.variables.replaceIn(\"{{$guid}}\"));"
            ]
          }
        },
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const body = pm.response.json();",
              "if (body.reference) pm.collectionVariables.set(\"reference\", body.reference);",
              "if (Number.isInteger(body.revision)) pm.collectionVariables.set(\"revision\", String(body.revision));",
              "if (body.id && body.url) pm.collectionVariables.set(\"webhookId\", body.id);"
            ]
          }
        }
      ]
    },
    {
      "name": "setSandboxOrder",
      "request": {
        "method": "PUT",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{apiKey}}"
          },
          {
            "key": "Content-Type",
            "value": "application/json"
          },
          {
            "key": "Idempotency-Key",
            "value": "{{idempotencyKey}}"
          }
        ],
        "url": "{{apiBaseUrl}}/sandbox/exports/{{reference}}/order",
        "description": "Set photographer order details\n\nTest mode: use a spreadu_lab_test_ key.\n\nSet orderNumber to the order number first. It is empty on purpose, and the server refuses an empty one.\n\nEvery send uses a new Idempotency-Key and saves it as idempotencyKey. To replay a command on purpose, copy that saved key into replayIdempotencyKey, send the same request again, then clear replayIdempotencyKey. Any variable scope works in Postman. In Bruno, set it in the test environment: the script reads the other scopes only where the installed Bruno can read them from a script, and otherwise sends a new key.",
        "body": {
          "mode": "raw",
          "raw": "{\n  \"externalOrderId\": null,\n  \"orderNumber\": \"{{orderNumber}}\",\n  \"orderedCopies\": 2\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        }
      },
      "event": [
        {
          "listen": "prerequest",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const replay = pm.variables.get(\"replayIdempotencyKey\");",
              "pm.collectionVariables.set(\"idempotencyKey\", replay || pm.variables.replaceIn(\"{{$guid}}\"));"
            ]
          }
        },
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const body = pm.response.json();",
              "if (body.reference) pm.collectionVariables.set(\"reference\", body.reference);",
              "if (Number.isInteger(body.revision)) pm.collectionVariables.set(\"revision\", String(body.revision));",
              "if (body.id && body.url) pm.collectionVariables.set(\"webhookId\", body.id);"
            ]
          }
        }
      ]
    },
    {
      "name": "createSandboxRevision",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{apiKey}}"
          },
          {
            "key": "Idempotency-Key",
            "value": "{{idempotencyKey}}"
          }
        ],
        "url": "{{apiBaseUrl}}/sandbox/exports/{{reference}}/revisions",
        "description": "Correct and re-export an available revision\n\nTest mode: use a spreadu_lab_test_ key.\n\nEvery send uses a new Idempotency-Key and saves it as idempotencyKey. To replay a command on purpose, copy that saved key into replayIdempotencyKey, send the same request again, then clear replayIdempotencyKey. Any variable scope works in Postman. In Bruno, set it in the test environment: the script reads the other scopes only where the installed Bruno can read them from a script, and otherwise sends a new key."
      },
      "event": [
        {
          "listen": "prerequest",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const replay = pm.variables.get(\"replayIdempotencyKey\");",
              "pm.collectionVariables.set(\"idempotencyKey\", replay || pm.variables.replaceIn(\"{{$guid}}\"));"
            ]
          }
        },
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const body = pm.response.json();",
              "if (body.reference) pm.collectionVariables.set(\"reference\", body.reference);",
              "if (Number.isInteger(body.revision)) pm.collectionVariables.set(\"revision\", String(body.revision));",
              "if (body.id && body.url) pm.collectionVariables.set(\"webhookId\", body.id);"
            ]
          }
        }
      ]
    },
    {
      "name": "withdrawSandboxExport",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{apiKey}}"
          },
          {
            "key": "Idempotency-Key",
            "value": "{{idempotencyKey}}"
          }
        ],
        "url": "{{apiBaseUrl}}/sandbox/exports/{{reference}}/withdraw",
        "description": "Withdraw the current export\n\nTest mode: use a spreadu_lab_test_ key.\n\nEvery send uses a new Idempotency-Key and saves it as idempotencyKey. To replay a command on purpose, copy that saved key into replayIdempotencyKey, send the same request again, then clear replayIdempotencyKey. Any variable scope works in Postman. In Bruno, set it in the test environment: the script reads the other scopes only where the installed Bruno can read them from a script, and otherwise sends a new key."
      },
      "event": [
        {
          "listen": "prerequest",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const replay = pm.variables.get(\"replayIdempotencyKey\");",
              "pm.collectionVariables.set(\"idempotencyKey\", replay || pm.variables.replaceIn(\"{{$guid}}\"));"
            ]
          }
        },
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const body = pm.response.json();",
              "if (body.reference) pm.collectionVariables.set(\"reference\", body.reference);",
              "if (Number.isInteger(body.revision)) pm.collectionVariables.set(\"revision\", String(body.revision));",
              "if (body.id && body.url) pm.collectionVariables.set(\"webhookId\", body.id);"
            ]
          }
        }
      ]
    },
    {
      "name": "resetSandbox",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{apiKey}}"
          },
          {
            "key": "Content-Type",
            "value": "application/json"
          },
          {
            "key": "Idempotency-Key",
            "value": "{{idempotencyKey}}"
          }
        ],
        "url": "{{apiBaseUrl}}/sandbox/reset",
        "description": "Reset exports and integration evidence, keeping keys and webhooks\n\nTest mode: use a spreadu_lab_test_ key.\n\nEvery send uses a new Idempotency-Key and saves it as idempotencyKey. To replay a command on purpose, copy that saved key into replayIdempotencyKey, send the same request again, then clear replayIdempotencyKey. Any variable scope works in Postman. In Bruno, set it in the test environment: the script reads the other scopes only where the installed Bruno can read them from a script, and otherwise sends a new key.",
        "body": {
          "mode": "raw",
          "raw": "{}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        }
      },
      "event": [
        {
          "listen": "prerequest",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const replay = pm.variables.get(\"replayIdempotencyKey\");",
              "pm.collectionVariables.set(\"idempotencyKey\", replay || pm.variables.replaceIn(\"{{$guid}}\"));"
            ]
          }
        },
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const body = pm.response.json();",
              "if (body.reference) pm.collectionVariables.set(\"reference\", body.reference);",
              "if (Number.isInteger(body.revision)) pm.collectionVariables.set(\"revision\", String(body.revision));",
              "if (body.id && body.url) pm.collectionVariables.set(\"webhookId\", body.id);"
            ]
          }
        }
      ]
    },
    {
      "name": "listWebhooks",
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{apiKey}}"
          }
        ],
        "url": "{{apiBaseUrl}}/webhooks",
        "description": "List the webhook endpoints this key created\n\nTest mode: use a spreadu_lab_test_ key."
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const body = pm.response.json();",
              "if (body.reference) pm.collectionVariables.set(\"reference\", body.reference);",
              "if (Number.isInteger(body.revision)) pm.collectionVariables.set(\"revision\", String(body.revision));",
              "if (body.id && body.url) pm.collectionVariables.set(\"webhookId\", body.id);"
            ]
          }
        }
      ]
    },
    {
      "name": "createWebhook",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{apiKey}}"
          },
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": "{{apiBaseUrl}}/webhooks",
        "description": "Add a webhook endpoint and receive its signing secret once\n\nTest mode: use a spreadu_lab_test_ key.",
        "body": {
          "mode": "raw",
          "raw": "{\n  \"eventTypes\": [\n    \"*\"\n  ],\n  \"label\": \"Integration test\",\n  \"url\": \"{{webhookUrl}}\"\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        }
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const body = pm.response.json();",
              "if (body.reference) pm.collectionVariables.set(\"reference\", body.reference);",
              "if (Number.isInteger(body.revision)) pm.collectionVariables.set(\"revision\", String(body.revision));",
              "if (body.id && body.url) pm.collectionVariables.set(\"webhookId\", body.id);"
            ]
          }
        }
      ]
    },
    {
      "name": "deleteWebhook",
      "request": {
        "method": "DELETE",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{apiKey}}"
          }
        ],
        "url": "{{apiBaseUrl}}/webhooks/{{webhookId}}",
        "description": "Delete a webhook endpoint and its delivery log\n\nTest mode: use a spreadu_lab_test_ key."
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const body = pm.response.json();",
              "if (body.reference) pm.collectionVariables.set(\"reference\", body.reference);",
              "if (Number.isInteger(body.revision)) pm.collectionVariables.set(\"revision\", String(body.revision));",
              "if (body.id && body.url) pm.collectionVariables.set(\"webhookId\", body.id);"
            ]
          }
        }
      ]
    },
    {
      "name": "updateWebhook",
      "request": {
        "method": "PATCH",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{apiKey}}"
          },
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": "{{apiBaseUrl}}/webhooks/{{webhookId}}",
        "description": "Change a webhook endpoint's label, URL, events or enabled state\n\nTest mode: use a spreadu_lab_test_ key.",
        "body": {
          "mode": "raw",
          "raw": "{\n  \"enabled\": true\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        }
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const body = pm.response.json();",
              "if (body.reference) pm.collectionVariables.set(\"reference\", body.reference);",
              "if (Number.isInteger(body.revision)) pm.collectionVariables.set(\"revision\", String(body.revision));",
              "if (body.id && body.url) pm.collectionVariables.set(\"webhookId\", body.id);"
            ]
          }
        }
      ]
    },
    {
      "name": "rotateWebhookSecret",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{apiKey}}"
          }
        ],
        "url": "{{apiBaseUrl}}/webhooks/{{webhookId}}/secret",
        "description": "Issue a new signing secret; the previous one works for 24 hours\n\nTest mode: use a spreadu_lab_test_ key."
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const body = pm.response.json();",
              "if (body.reference) pm.collectionVariables.set(\"reference\", body.reference);",
              "if (Number.isInteger(body.revision)) pm.collectionVariables.set(\"revision\", String(body.revision));",
              "if (body.id && body.url) pm.collectionVariables.set(\"webhookId\", body.id);"
            ]
          }
        }
      ]
    },
    {
      "name": "testWebhook",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Authorization",
            "value": "Bearer {{apiKey}}"
          }
        ],
        "url": "{{apiBaseUrl}}/webhooks/{{webhookId}}/test",
        "description": "Send a signed ping to an enabled webhook endpoint\n\nTest mode: use a spreadu_lab_test_ key."
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const body = pm.response.json();",
              "if (body.reference) pm.collectionVariables.set(\"reference\", body.reference);",
              "if (Number.isInteger(body.revision)) pm.collectionVariables.set(\"revision\", String(body.revision));",
              "if (body.id && body.url) pm.collectionVariables.set(\"webhookId\", body.id);"
            ]
          }
        }
      ]
    }
  ]
}
