{
  "info": {
    "name": "Addressfinder Portal API: Bulk Verification",
    "description": "Bulk verification of addresses, emails and phone numbers through the Addressfinder Portal API.\n\nBefore you start, set two collection variables (Variables tab), as current values so they stay on your machine:\n- `apiKey`: your project's API key (Portal, Keys). It identifies the project, and usage is billed to it.\n- `token`: an API token, from https://portal.addressfinder.net/portal/user_api_tokens. It identifies you.\n\nThen run the requests in order:\n1. Create job (1a for email, 1b for addresses)\n2. Upload the CSV\n3. Commit job\n4. Get job status, until `status` is `completed`\n5. Download results\n\nCreate job saves `jobUuid`, `uploadUrl` and `type` for the requests that follow.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "auth": {
    "type": "bearer",
    "bearer": [
      {
        "key": "token",
        "value": "{{token}}",
        "type": "string"
      }
    ]
  },
  "variable": [
    {
      "key": "portalURL",
      "value": "https://portal.addressfinder.net"
    },
    {
      "key": "apiKey",
      "value": ""
    },
    {
      "key": "token",
      "value": ""
    },
    {
      "key": "type",
      "value": "email"
    },
    {
      "key": "jobUuid",
      "value": ""
    },
    {
      "key": "uploadUrl",
      "value": ""
    }
  ],
  "item": [
    {
      "name": "1a Create job (email)",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "if (pm.response.code === 201) {",
              "  const json = pm.response.json();",
              "  if (json.uuid) {",
              "    pm.collectionVariables.set('jobUuid', json.uuid);",
              "    console.log('Saved jobUuid =', json.uuid);",
              "  }",
              "  if (json.upload_url) {",
              "    pm.collectionVariables.set('uploadUrl', json.upload_url);",
              "    console.log('Saved uploadUrl');",
              "  }",
              "  pm.collectionVariables.set('type', 'email');",
              "  console.log('Set type = email for the rest of the flow');",
              "}"
            ]
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": {
          "raw": "{{portalURL}}/api/v1/bulk/email/jobs?key={{apiKey}}",
          "host": [
            "{{portalURL}}"
          ],
          "path": [
            "api",
            "v1",
            "bulk",
            "email",
            "jobs"
          ],
          "query": [
            {
              "key": "key",
              "value": "{{apiKey}}"
            }
          ]
        },
        "auth": {
          "type": "bearer",
          "bearer": [
            {
              "key": "token",
              "value": "{{token}}",
              "type": "string"
            }
          ]
        },
        "description": "Creates an email job and returns a presigned `upload_url`. Saves `jobUuid` and `uploadUrl`, and sets `type` to `email` for the following requests.\n\nFields: `filename`, `column_index` (from 1, default 1), `has_header` (default false), `header_row`.\n\nFor phone, change `email` to `phone` in the URL and add `default_country_code`, `allowed_country_codes` and `mobile_only` as needed.",
        "body": {
          "mode": "raw",
          "raw": "{\n  \"filename\": \"contacts.csv\",\n  \"has_header\": true,\n  \"column_index\": 1,\n  \"header_row\": [\"email\"]\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        }
      }
    },
    {
      "name": "1b Create job (address)",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "if (pm.response.code === 201) {",
              "  const json = pm.response.json();",
              "  if (json.uuid) {",
              "    pm.collectionVariables.set('jobUuid', json.uuid);",
              "    console.log('Saved jobUuid =', json.uuid);",
              "  }",
              "  if (json.upload_url) {",
              "    pm.collectionVariables.set('uploadUrl', json.upload_url);",
              "    console.log('Saved uploadUrl');",
              "  }",
              "  pm.collectionVariables.set('type', 'address');",
              "  console.log('Set type = address for the rest of the flow');",
              "}"
            ]
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "url": {
          "raw": "{{portalURL}}/api/v1/bulk/address/jobs?key={{apiKey}}",
          "host": [
            "{{portalURL}}"
          ],
          "path": [
            "api",
            "v1",
            "bulk",
            "address",
            "jobs"
          ],
          "query": [
            {
              "key": "key",
              "value": "{{apiKey}}"
            }
          ]
        },
        "auth": {
          "type": "bearer",
          "bearer": [
            {
              "key": "token",
              "value": "{{token}}",
              "type": "string"
            }
          ]
        },
        "description": "Creates an address job and returns a presigned `upload_url`. Saves `jobUuid` and `uploadUrl`, and sets `type` to `address` for the following requests.\n\nAddress fields: `country_code` (required, `au` or `nz`), `gnaf` or `paf` (`1`, an AU job needs one), `gps`, `extended`, `census`.\n\nThe body is a New Zealand example. For Australia, set `\"country_code\": \"au\"` and add `\"gnaf\": 1` or `\"paf\": 1`.",
        "body": {
          "mode": "raw",
          "raw": "{\n  \"filename\": \"addresses.csv\",\n  \"has_header\": true,\n  \"column_index\": 1,\n  \"header_row\": [\"address\"],\n  \"country_code\": \"nz\",\n  \"gps\": 1,\n  \"extended\": 1\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        }
      }
    },
    {
      "name": "2a Upload the CSV (email sample)",
      "request": {
        "method": "PUT",
        "header": [
          {
            "key": "Content-Type",
            "value": "text/csv"
          }
        ],
        "url": {
          "raw": "{{uploadUrl}}",
          "host": [
            "{{uploadUrl}}"
          ],
          "path": []
        },
        "auth": {
          "type": "noauth"
        },
        "description": "PUTs the whole CSV to the presigned `uploadUrl`. Don't split the file: the Portal does that.\n\nThis goes straight to storage, so it sends no `Authorization` header and no `key`. To send your own file: Body, binary, select the CSV. The URL is valid for one hour.",
        "body": {
          "mode": "raw",
          "raw": "email\nperson1@fakedomainz.com\nperson2@fakedomainz.com\n",
          "options": {
            "raw": {
              "language": "text"
            }
          }
        }
      }
    },
    {
      "name": "2b Upload the CSV (address sample)",
      "request": {
        "method": "PUT",
        "header": [
          {
            "key": "Content-Type",
            "value": "text/csv"
          }
        ],
        "url": {
          "raw": "{{uploadUrl}}",
          "host": [
            "{{uploadUrl}}"
          ],
          "path": []
        },
        "auth": {
          "type": "noauth"
        },
        "description": "Same as 2a, with an address sample matching 1b.",
        "body": {
          "mode": "raw",
          "raw": "address\n\"1 Queen Street, Auckland\"\n\"100 Lambton Quay, Wellington\"\n\"123 Nonexistent Road, Nowhere\"\n",
          "options": {
            "raw": {
              "language": "text"
            }
          }
        }
      }
    },
    {
      "name": "3 Commit job",
      "request": {
        "method": "POST",
        "header": [],
        "url": {
          "raw": "{{portalURL}}/api/v1/bulk/{{type}}/jobs/{{jobUuid}}/commit?key={{apiKey}}",
          "host": [
            "{{portalURL}}"
          ],
          "path": [
            "api",
            "v1",
            "bulk",
            "{{type}}",
            "jobs",
            "{{jobUuid}}",
            "commit"
          ],
          "query": [
            {
              "key": "key",
              "value": "{{apiKey}}"
            }
          ]
        },
        "auth": {
          "type": "bearer",
          "bearer": [
            {
              "key": "token",
              "value": "{{token}}",
              "type": "string"
            }
          ]
        },
        "description": "Tells the Portal the upload is complete, so it splits the file and starts verifying. Returns `202 Accepted`."
      }
    },
    {
      "name": "4 Get job status",
      "request": {
        "method": "GET",
        "header": [],
        "url": {
          "raw": "{{portalURL}}/api/v1/bulk/{{type}}/jobs/{{jobUuid}}?key={{apiKey}}",
          "host": [
            "{{portalURL}}"
          ],
          "path": [
            "api",
            "v1",
            "bulk",
            "{{type}}",
            "jobs",
            "{{jobUuid}}"
          ],
          "query": [
            {
              "key": "key",
              "value": "{{apiKey}}"
            }
          ]
        },
        "auth": {
          "type": "bearer",
          "bearer": [
            {
              "key": "token",
              "value": "{{token}}",
              "type": "string"
            }
          ]
        },
        "description": "Poll until `status` is `completed`. Statuses: `pending`, `splitting`, `uploaded`, `processing`, `completed`, `failed` (see `error_message`) and `cancelled`."
      }
    },
    {
      "name": "5 Download results",
      "request": {
        "method": "GET",
        "header": [],
        "url": {
          "raw": "{{portalURL}}/api/v1/bulk/{{type}}/jobs/{{jobUuid}}/download?key={{apiKey}}",
          "host": [
            "{{portalURL}}"
          ],
          "path": [
            "api",
            "v1",
            "bulk",
            "{{type}}",
            "jobs",
            "{{jobUuid}}",
            "download"
          ],
          "query": [
            {
              "key": "key",
              "value": "{{apiKey}}"
            }
          ]
        },
        "auth": {
          "type": "bearer",
          "bearer": [
            {
              "key": "token",
              "value": "{{token}}",
              "type": "string"
            }
          ]
        },
        "description": "Once the job is `completed`, redirects (`302`) to the results CSV: your columns followed by the result columns. Returns `409 Conflict` while the job is still running."
      }
    },
    {
      "name": "6 Download partial results",
      "request": {
        "method": "GET",
        "header": [],
        "url": {
          "raw": "{{portalURL}}/api/v1/bulk/{{type}}/jobs/{{jobUuid}}/download?key={{apiKey}}&partial=true",
          "host": [
            "{{portalURL}}"
          ],
          "path": [
            "api",
            "v1",
            "bulk",
            "{{type}}",
            "jobs",
            "{{jobUuid}}",
            "download"
          ],
          "query": [
            {
              "key": "key",
              "value": "{{apiKey}}"
            },
            {
              "key": "partial",
              "value": "true"
            }
          ]
        },
        "auth": {
          "type": "bearer",
          "bearer": [
            {
              "key": "token",
              "value": "{{token}}",
              "type": "string"
            }
          ]
        },
        "description": "Downloads the rows verified so far. Each partial download is the start of the final file, so it's safe to call repeatedly. Returns `409 Conflict` until the first rows are done."
      }
    },
    {
      "name": "List jobs",
      "request": {
        "method": "GET",
        "header": [],
        "url": {
          "raw": "{{portalURL}}/api/v1/bulk/{{type}}/jobs?limit=20&key={{apiKey}}",
          "host": [
            "{{portalURL}}"
          ],
          "path": [
            "api",
            "v1",
            "bulk",
            "{{type}}",
            "jobs"
          ],
          "query": [
            {
              "key": "limit",
              "value": "20"
            },
            {
              "key": "key",
              "value": "{{apiKey}}"
            }
          ]
        },
        "auth": {
          "type": "bearer",
          "bearer": [
            {
              "key": "token",
              "value": "{{token}}",
              "type": "string"
            }
          ]
        },
        "description": "Lists the project's most recent jobs of `{{type}}`, newest first. `limit` defaults to 50."
      }
    },
    {
      "name": "Delete job",
      "request": {
        "method": "DELETE",
        "header": [],
        "url": {
          "raw": "{{portalURL}}/api/v1/bulk/{{type}}/jobs/{{jobUuid}}?key={{apiKey}}",
          "host": [
            "{{portalURL}}"
          ],
          "path": [
            "api",
            "v1",
            "bulk",
            "{{type}}",
            "jobs",
            "{{jobUuid}}"
          ],
          "query": [
            {
              "key": "key",
              "value": "{{apiKey}}"
            }
          ]
        },
        "auth": {
          "type": "bearer",
          "bearer": [
            {
              "key": "token",
              "value": "{{token}}",
              "type": "string"
            }
          ]
        },
        "description": "Cancels the job. Rows not yet verified stop processing."
      }
    }
  ]
}
