{
  "info": {
    "name": "Veriframe Conversion API",
    "description": "Convert a CCTV export to MP4, request by request.\n\n1. Open the collection's Variables tab and paste your API key into `api_key` (create one under API keys in your Veriframe account).\n2. Run the requests from the top. \"Create a job\" saves the job token into `job_token`, so every later request already points at your job.\n\nGuide: https://veriframe.co.uk/api-guide  Reference: https://veriframe.co.uk/api",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "variable": [
    {
      "key": "base_url",
      "value": "https://veriframe.co.uk"
    },
    {
      "key": "api_key",
      "value": ""
    },
    {
      "key": "job_token",
      "value": ""
    },
    {
      "key": "ref",
      "value": ""
    },
    {
      "key": "callback_secret",
      "value": ""
    }
  ],
  "item": [
    {
      "name": "1. Create a job",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          }
        ],
        "url": {
          "raw": "{{base_url}}/job",
          "host": [
            "{{base_url}}"
          ],
          "path": [
            "job"
          ]
        },
        "description": "Creates a job and returns its token ONCE. The token is saved into the `job_token` variable. Add \"callback_url\" to be told when the job changes; the response then includes a callback_secret.",
        "auth": {
          "type": "bearer",
          "bearer": [
            {
              "key": "token",
              "value": "{{api_key}}",
              "type": "string"
            }
          ]
        },
        "body": {
          "mode": "raw",
          "raw": "{\n  \"label\": \"claim 4471\"\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        }
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const j = pm.response.json();",
              "pm.test('job created', () => pm.response.to.have.status(201));",
              "pm.collectionVariables.set('job_token', j.job_token);",
              "pm.collectionVariables.set('ref', j.ref);",
              "if (j.callback_secret) pm.collectionVariables.set('callback_secret', j.callback_secret);"
            ]
          }
        }
      ]
    },
    {
      "name": "2a. Give it a link",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          }
        ],
        "url": {
          "raw": "{{base_url}}/job/{{job_token}}/source",
          "host": [
            "{{base_url}}"
          ],
          "path": [
            "job",
            "{{job_token}}",
            "source"
          ]
        },
        "description": "Use this OR 2b. We fetch the export from a link that downloads without a sign-in or password.",
        "auth": {
          "type": "noauth"
        },
        "body": {
          "mode": "raw",
          "raw": "{\n  \"source_url\": \"https://your-storage.example/export.zip\"\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        }
      }
    },
    {
      "name": "2b. Upload a file (one chunk, up to 64 MB)",
      "request": {
        "method": "PUT",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "key": "X-Upload-Offset",
            "value": "0"
          },
          {
            "key": "X-Upload-Name",
            "value": "export.zip"
          },
          {
            "key": "Content-Type",
            "value": "application/octet-stream"
          }
        ],
        "url": {
          "raw": "{{base_url}}/job/{{job_token}}/upload",
          "host": [
            "{{base_url}}"
          ],
          "path": [
            "job",
            "{{job_token}}",
            "upload"
          ]
        },
        "description": "Use this OR 2a. Choose the file in the Body tab. A larger file is sent as several of these requests, each with the offset of its first byte.",
        "auth": {
          "type": "noauth"
        },
        "body": {
          "mode": "file",
          "file": {
            "src": ""
          }
        }
      }
    },
    {
      "name": "2c. Finish the upload",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          }
        ],
        "url": {
          "raw": "{{base_url}}/job/{{job_token}}/upload/done",
          "host": [
            "{{base_url}}"
          ],
          "path": [
            "job",
            "{{job_token}}",
            "upload",
            "done"
          ]
        },
        "description": "Only after 2b. Set \"total\" to the size of the file in bytes. A 409 lists what is missing.",
        "auth": {
          "type": "noauth"
        },
        "body": {
          "mode": "raw",
          "raw": "{\n  \"total\": 0\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        }
      }
    },
    {
      "name": "3. Check the status",
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          }
        ],
        "url": {
          "raw": "{{base_url}}/job/{{job_token}}/status",
          "host": [
            "{{base_url}}"
          ],
          "path": [
            "job",
            "{{job_token}}",
            "status"
          ]
        },
        "description": "Repeat every 5 to 10 seconds until state is \"ready\" or \"failed\".",
        "auth": {
          "type": "noauth"
        }
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.test('answered', () => pm.response.to.have.status(200));",
              "console.log('state: ' + pm.response.json().state);"
            ]
          }
        }
      ]
    },
    {
      "name": "4a. Download the zip",
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          }
        ],
        "url": {
          "raw": "{{base_url}}/job/{{job_token}}/download",
          "host": [
            "{{base_url}}"
          ],
          "path": [
            "job",
            "{{job_token}}",
            "download"
          ]
        },
        "description": "A 202 means the zip is still being packed: send the request again. On 200, use Send and Download to save the file.",
        "auth": {
          "type": "noauth"
        }
      }
    },
    {
      "name": "4b. Download the certificate",
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          }
        ],
        "url": {
          "raw": "{{base_url}}/job/{{job_token}}/certificate",
          "host": [
            "{{base_url}}"
          ],
          "path": [
            "job",
            "{{job_token}}",
            "certificate"
          ]
        },
        "description": "The conversion certificate, as a PDF.",
        "auth": {
          "type": "noauth"
        }
      }
    },
    {
      "name": "4c. Send to a storage folder",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          }
        ],
        "url": {
          "raw": "{{base_url}}/job/{{job_token}}/send",
          "host": [
            "{{base_url}}"
          ],
          "path": [
            "job",
            "{{job_token}}",
            "send"
          ]
        },
        "description": "Optional, instead of downloading. \"link\" is a Box or Dropbox upload link (a File Request). For Dropbox add \"sender_name\" and \"sender_email\".",
        "auth": {
          "type": "noauth"
        },
        "body": {
          "mode": "raw",
          "raw": "{\n  \"link\": \"https://app.box.com/f/...\",\n  \"accept_terms\": true\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        }
      }
    },
    {
      "name": "5. Delete the job now",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          }
        ],
        "url": {
          "raw": "{{base_url}}/job/{{job_token}}/delete",
          "host": [
            "{{base_url}}"
          ],
          "path": [
            "job",
            "{{job_token}}",
            "delete"
          ]
        },
        "description": "Optional. Otherwise the footage is deleted on the timer.",
        "auth": {
          "type": "noauth"
        }
      }
    },
    {
      "name": "List your jobs",
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          }
        ],
        "url": {
          "raw": "{{base_url}}/jobs?limit=50",
          "host": [
            "{{base_url}}"
          ],
          "path": [
            "jobs"
          ],
          "query": [
            {
              "key": "limit",
              "value": "50"
            }
          ]
        },
        "description": "Newest first. Filter with state= or label=; page with before=.",
        "auth": {
          "type": "bearer",
          "bearer": [
            {
              "key": "token",
              "value": "{{api_key}}",
              "type": "string"
            }
          ]
        }
      }
    },
    {
      "name": "Check your balance",
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          }
        ],
        "url": {
          "raw": "{{base_url}}/account",
          "host": [
            "{{base_url}}"
          ],
          "path": [
            "account"
          ]
        },
        "description": "Credits remaining, and whether a new job would be accepted.",
        "auth": {
          "type": "bearer",
          "bearer": [
            {
              "key": "token",
              "value": "{{api_key}}",
              "type": "string"
            }
          ]
        }
      }
    }
  ]
}
