{
  "info": {
    "_postman_id": "b00c1a9e-0000-4a10-9c3f-upicbooking001",
    "name": "U-PIC - Booking API",
    "description": "U-PIC Booking API (Partners v1) - partner integration collection.\n\nRun the requests top to bottom. Auth, Quote, Book and Claim each capture the identifier the next step needs (token -> quote_uuid -> manifest_uuid -> claim_id), so no manual copying is required. A quote can only be booked once, so the multi-parcel Book has its own Quote just before it, and saves its booking as manifest_uuid_multi. Change Tracking Number and Remove Insurance act on that multi-parcel booking, because the single-parcel one has a claim on it by then.\n\nAUTH -> CREATE -> QUOTE -> (CLIENT CARRIERS, optional) -> BOOK -> QUOTE + BOOK (multi-parcel) -> CLAIM -> ATTACH -> CLAIM STATUS -> SETTLEMENTS -> BOOKING LOOKUP -> CHANGE TRACKING NUMBER -> REMOVE INSURANCE -> RECONCILE\n\nBefore you start, set two collection variables:\n  api_key                 the key U-PIC issued you.\n                          ask U-PIC for a TEST client key first; it runs against this same\n                          base URL, there is no separate sandbox host.\n  sub_client_identifier   the seller you are onboarding, read by both Create and Quote.\n\nTwo requests need one more thing from you: Claim Attachments needs a file chosen in its Body tab, and Reconciliation Report - By Invoice needs invoice_id set to one of your invoice numbers.\n\nBook generates a fresh tracking_number each time it runs, so re-running the collection does not collide with a booking you already made. Claim is filed against that tracking number.\n\nHEALTH needs no key and confirms the API is reachable. HEALTH and CLIENT CARRIERS are shared with the Standard API, so they sit at the root of https://api.u-pic.com, not under /partners/v1.\n\nTokens do not expire. Authenticate once and reuse the token; calling /auth again issues a new token and invalidates the previous one.\n\nTRACKING NUMBERS - one parcel per tracking number:\n  Single parcel  ->  \"tracking_numbers\": [\"1Z999...\"]\n                     insured for the quote's total_insured_value.\n  Multiple       ->  \"tracking_numbers\": [{\"tracking_number\": \"...\", \"insured_value\": 100.00}, ...]\n                     values must sum EXACTLY to the quote's total_insured_value.\n  Two or more PLAIN strings are rejected with 400 MULTIPLE_TRACKING_NOT_SUPPORTED.\n\nEach parcel is insured, billed, and claimed independently. Claim a parcel by its tracking_number.\n\nFull reference: the U-PIC Booking API Guide.\nQuestions: techsupport@u-pic.com",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "auth": {
    "type": "bearer",
    "bearer": [
      {
        "key": "token",
        "value": "{{token}}",
        "type": "string"
      }
    ]
  },
  "variable": [
    {
      "key": "api_key",
      "value": "REPLACE_WITH_YOUR_API_KEY",
      "type": "string"
    },
    {
      "key": "sub_client_identifier",
      "value": "SELLER-4471",
      "type": "string"
    },
    {
      "key": "tracking_number",
      "value": "",
      "type": "string"
    },
    {
      "key": "tracking_a",
      "value": "",
      "type": "string"
    },
    {
      "key": "tracking_b",
      "value": "",
      "type": "string"
    },
    {
      "key": "token",
      "value": "",
      "type": "string"
    },
    {
      "key": "quote_uuid",
      "value": "",
      "type": "string"
    },
    {
      "key": "client_carrier_id",
      "value": "",
      "type": "string"
    },
    {
      "key": "manifest_uuid",
      "value": "",
      "type": "string"
    },
    {
      "key": "manifest_uuid_multi",
      "value": "",
      "type": "string"
    },
    {
      "key": "claim_id",
      "value": "",
      "type": "string"
    },
    {
      "key": "ship_date",
      "value": "",
      "type": "string"
    },
    {
      "key": "date_from",
      "value": "",
      "type": "string"
    },
    {
      "key": "date_to",
      "value": "",
      "type": "string"
    },
    {
      "key": "tracking_number_new",
      "value": "",
      "type": "string"
    },
    {
      "key": "invoice_id",
      "value": "",
      "type": "string"
    }
  ],
  "item": [
    {
      "name": "Auth",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const json = pm.response.json();",
              "if (json && json.token) {",
              "  pm.collectionVariables.set(\"token\", json.token);",
              "  console.log(\"Saved token for client \" + (json.client_id || \"?\"));",
              "}"
            ]
          }
        }
      ],
      "request": {
        "auth": {
          "type": "noauth"
        },
        "method": "POST",
        "header": [],
        "body": {
          "mode": "raw",
          "raw": "{\r\n    \"api_key\": \"{{api_key}}\"\r\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "https://api.u-pic.com/auth",
          "protocol": "https",
          "host": [
            "api",
            "u-pic",
            "com"
          ],
          "path": [
            "auth"
          ]
        }
      },
      "response": []
    },
    {
      "name": "Health",
      "request": {
        "auth": {
          "type": "noauth"
        },
        "method": "GET",
        "header": [],
        "description": "Confirms the API is reachable. No key or token needed. Shared with U-PIC's Standard API, so it sits at the root (https://api.u-pic.com/health), not under /partners/v1.",
        "url": {
          "raw": "https://api.u-pic.com/health",
          "protocol": "https",
          "host": [
            "api",
            "u-pic",
            "com"
          ],
          "path": [
            "health"
          ]
        }
      },
      "response": []
    },
    {
      "name": "Create",
      "request": {
        "method": "POST",
        "header": [],
        "body": {
          "mode": "raw",
          "raw": "{\r\n  \"sub_client_identifier\": \"{{sub_client_identifier}}\",\r\n  \"company_name\": \"123 Company\",\r\n  \"contact_name\": \"Pat Lee\",\r\n  \"email\": \"ops@123co.com\",\r\n  \"phone\": \"555-555-0100\",\r\n  \"address_1\": \"100 Main St\",\r\n  \"address_2\": \"Suite 4\",\r\n  \"city\": \"Orlando\",\r\n  \"state\": \"FL\",\r\n  \"zip\": \"32801\",\r\n  \"country\": \"US\"\r\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "https://api.u-pic.com/partners/v1/create",
          "protocol": "https",
          "host": [
            "api",
            "u-pic",
            "com"
          ],
          "path": [
            "partners",
            "v1",
            "create"
          ]
        },
        "auth": {
          "type": "bearer",
          "bearer": [
            {
              "key": "token",
              "value": "{{token}}",
              "type": "string"
            }
          ]
        },
        "description": "Registers a sub-client (your seller) once. Its sub_client_identifier is then sent on every Quote for that seller.\n\nEvery field except sub_client_identifier is optional. state is a 2 letter code within country.\n\nNo rate is sent: every sub-client is priced at the rate configured on your U-PIC account. Older integrations that still send rate_type / rate_value are accepted and those values are ignored. If your account has no rate set up yet, this returns 409 CLIENT_RATE_NOT_SET.\n\npayment_token and payment_link are only returned when U-PIC collects payment details directly from your sub-clients. Forward the link to that seller only, and do not log it.\n\nRe-sending an identifier that already exists returns 409 DUPLICATE_SUB_CLIENT and changes nothing. Use Subclient Update to correct a seller's details."
      },
      "response": []
    },
    {
      "name": "Subclient List",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "// One page of your sub-clients. Keep paging while has_more is true.",
              "if (pm.response.code === 200) {",
              "    const b = pm.response.json();",
              "    console.log(b.total_count + ' sub-client(s), page ' + b.page + ' of ' + b.total_pages);",
              "    (b.subclients || []).forEach(function (s) {",
              "        console.log(s.sub_client_identifier + ' ' + (s.company_name || '') + ' ' + s.status +",
              "            ' payment details: ' + (s.payment_details_provided ? s.payment_method : 'not provided'));",
              "    });",
              "}"
            ]
          }
        }
      ],
      "request": {
        "method": "GET",
        "header": [],
        "url": {
          "raw": "https://api.u-pic.com/partners/v1/subclients?page=1",
          "protocol": "https",
          "host": [
            "api",
            "u-pic",
            "com"
          ],
          "path": [
            "partners",
            "v1",
            "subclients"
          ],
          "query": [
            {
              "key": "search",
              "value": "",
              "disabled": true
            },
            {
              "key": "status",
              "value": "active",
              "disabled": true
            },
            {
              "key": "payment_details_provided",
              "value": "false",
              "disabled": true
            },
            {
              "key": "page",
              "value": "1"
            }
          ]
        },
        "auth": {
          "type": "bearer",
          "bearer": [
            {
              "key": "token",
              "value": "{{token}}",
              "type": "string"
            }
          ]
        },
        "description": "Lists the sub-clients you have created, 500 per page, ordered by company name.\n\nOptional filters (enable them in Params): search looks sub-clients up by company name (see 'Subclient Lookup - By Company Name'), status is active, inactive or deactivated, and payment_details_provided is true or false.\n\nEach record carries the contact and address U-PIC has on file, the status, whether the seller has given U-PIC their own payment details, and payment_method (check or ach). The details behind the method are never returned.\n\nWhile has_more is true, send the next page with the same filters."
      },
      "response": []
    },
    {
      "name": "Subclient Lookup",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "if (pm.response.code === 200) {",
              "    const s = pm.response.json();",
              "    console.log(s.sub_client_identifier + ' is ' + s.status);",
              "    console.log('payment details: ' + (s.payment_details_provided ? s.payment_method : 'not provided'));",
              "} else if (pm.response.code === 404) {",
              "    console.log('No sub-client with that identifier on this account. Run Create first.');",
              "}"
            ]
          }
        }
      ],
      "request": {
        "method": "GET",
        "header": [],
        "url": {
          "raw": "https://api.u-pic.com/partners/v1/subclients/{{sub_client_identifier}}",
          "protocol": "https",
          "host": [
            "api",
            "u-pic",
            "com"
          ],
          "path": [
            "partners",
            "v1",
            "subclients",
            "{{sub_client_identifier}}"
          ]
        },
        "auth": {
          "type": "bearer",
          "bearer": [
            {
              "key": "token",
              "value": "{{token}}",
              "type": "string"
            }
          ]
        },
        "description": "Reads one sub-client by the sub_client_identifier you sent to Create. Company names are not unique, so to find a seller by name use Subclient List with search.\n\npayment_link is only included when U-PIC collects payment details from your sub-clients and this seller has not provided them yet, so you can send it again."
      },
      "response": []
    },
    {
      "name": "Subclient Lookup - By Company Name",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "// Every sub-client whose company name contains the search text.",
              "if (pm.response.code === 200) {",
              "    const b = pm.response.json();",
              "    console.log(b.total_count + ' match(es)');",
              "    (b.subclients || []).forEach(function (s) {",
              "        console.log(s.sub_client_identifier + ' ' + (s.company_name || ''));",
              "    });",
              "}"
            ]
          }
        }
      ],
      "request": {
        "method": "GET",
        "header": [],
        "url": {
          "raw": "https://api.u-pic.com/partners/v1/subclients?search=123 Company",
          "protocol": "https",
          "host": [
            "api",
            "u-pic",
            "com"
          ],
          "path": [
            "partners",
            "v1",
            "subclients"
          ],
          "query": [
            {
              "key": "search",
              "value": "123 Company"
            }
          ]
        },
        "auth": {
          "type": "bearer",
          "bearer": [
            {
              "key": "token",
              "value": "{{token}}",
              "type": "string"
            }
          ]
        },
        "description": "Looks sub-clients up by company name. Returns every sub-client whose company name contains the search text, not case sensitive, so search=123 finds \"123 Company\". Company names are not unique, so this can return more than one sub-client.\n\nSame response as Subclient List, and status, payment_details_provided and page can be added to narrow it."
      },
      "response": []
    },
    {
      "name": "Subclient Update",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "// The sub-client comes back in the same shape Subclient Lookup returns.",
              "if (pm.response.code === 200) {",
              "    console.log('updated: ' + JSON.stringify(pm.response.json().address));",
              "} else if (pm.response.code === 409) {",
              "    console.log('Locked: the seller has given U-PIC their own payment details. Contact techsupport@u-pic.com.');",
              "} else if (pm.response.code === 400) {",
              "    console.log(pm.response.json().errcode + ': ' + pm.response.json().error);",
              "}"
            ]
          }
        }
      ],
      "request": {
        "method": "PATCH",
        "header": [],
        "body": {
          "mode": "raw",
          "raw": "{\r\n  \"address_1\": \"200 Oak Ave\",\r\n  \"address_2\": null,\r\n  \"city\": \"Tampa\",\r\n  \"state\": \"FL\",\r\n  \"country\": \"US\"\r\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "https://api.u-pic.com/partners/v1/subclients/{{sub_client_identifier}}",
          "protocol": "https",
          "host": [
            "api",
            "u-pic",
            "com"
          ],
          "path": [
            "partners",
            "v1",
            "subclients",
            "{{sub_client_identifier}}"
          ]
        },
        "auth": {
          "type": "bearer",
          "bearer": [
            {
              "key": "token",
              "value": "{{token}}",
              "type": "string"
            }
          ]
        },
        "description": "Corrects a sub-client's contact and address details. Send only the fields you are changing; a field sent as null or an empty string is cleared.\n\nUpdatable: company_name, contact_name, email, phone, address_1, address_2, city, state, zip, country, and status (active or inactive). Anything else returns 400 UNKNOWN_FIELD and nothing changes.\n\nOnce the seller has given U-PIC their own payment details, this returns 409 SUB_CLIENT_LOCKED, because the address on file is where their claim payments go. The lock covers contact and address only, so status can still be set.\n\nSet status to inactive to stop insuring a seller: Quote then returns 400 SUB_CLIENT_INACTIVE. Bookings already made stay insured. A sub-client U-PIC has deactivated cannot be changed here (409 SUB_CLIENT_DEACTIVATED)."
      },
      "response": []
    },
    {
      "name": "Quote",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const json = pm.response.json();",
              "if (json && json.quote_uuid) {",
              "  pm.collectionVariables.set(\"quote_uuid\", json.quote_uuid);",
              "}"
            ]
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [],
        "description": "Prices an order at the rate configured on your U-PIC account, or the sub-client's own rate where your account is set up that way, and returns a quote_uuid. The premium is locked at quote time.\n\nperishable is optional. It affects the price only when your account has perishable carriers set up: a quote sent with \"perishable\": true is then priced at the perishable rate on those carriers. Otherwise the order is priced at your standard rate and the flag is simply recorded. Please note: sending it does not add perishable coverage unless you have an endorsement in place for perishable goods. The perishable value in the response repeats what you sent. To add perishable coverage, contact techsupport@u-pic.com.",
        "body": {
          "mode": "raw",
          "raw": "{\r\n  \"sub_client_identifier\": \"{{sub_client_identifier}}\",\r\n  \"total_insured_value\": 150.00,\r\n  \"destination_country\": \"US\",\r\n  \"perishable\": false\r\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "https://api.u-pic.com/partners/v1/quote",
          "protocol": "https",
          "host": [
            "api",
            "u-pic",
            "com"
          ],
          "path": [
            "partners",
            "v1",
            "quote"
          ]
        },
        "auth": {
          "type": "bearer",
          "bearer": [
            {
              "key": "token",
              "value": "{{token}}",
              "type": "string"
            }
          ]
        }
      },
      "response": []
    },
    {
      "name": "Client Carriers",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "// Optional step. Saves the first carrier's client_carrier_id, for a Book that",
              "// names its carrier exactly. Every carrier listed can be booked. Book below still",
              "// sends a carrier name, which works as before.",
              "const json = pm.response.json();",
              "const first = Array.isArray(json) && json.length ? json[0] : null;",
              "if (first) {",
              "  pm.collectionVariables.set(\"client_carrier_id\", first.client_carrier_id);",
              "  console.log(\"client_carrier_id \" + first.client_carrier_id + \" (\" + first.description + \")\");",
              "}"
            ]
          }
        }
      ],
      "request": {
        "method": "GET",
        "header": [],
        "description": "Optional, between Quote and Book. Lists the carriers you can book with. To book with an exact carrier instead of a name, send one's client_carrier_id (not carrier_id) on Book as order_metadata.client_carrier_id; carrier can then be left out, and if both are sent the id wins. The id must be on that list (400 WRONG_CARRIER) and must suit the quote: a perishable carrier on a perishable quote and a standard one on a standard quote, whenever your account has carriers of that kind (400 CARRIER_PERISHABLE_MISMATCH). description is the name order_metadata.carrier matches against. Your premium comes from the quote, not cost_per_dvu. Shared with the Standard API, so it sits at the root, not under /partners/v1.",
        "url": {
          "raw": "https://api.u-pic.com/client/carriers",
          "protocol": "https",
          "host": [
            "api",
            "u-pic",
            "com"
          ],
          "path": [
            "client",
            "carriers"
          ]
        },
        "auth": {
          "type": "bearer",
          "bearer": [
            {
              "key": "token",
              "value": "{{token}}",
              "type": "string"
            }
          ]
        }
      },
      "response": []
    },
    {
      "name": "Book (Manifest)",
      "event": [
        {
          "listen": "prerequest",
          "script": {
            "type": "text/javascript",
            "exec": [
              "// A fresh tracking number and today's ship date, set before every run.",
              "// Re-sending a tracking number that is already booked returns 409 DUPLICATE_TRACKING,",
              "// and ship_date is the coverage date claims are checked against, so neither should be a stale literal.",
              "const digits = Array.from({length: 18}, () => Math.floor(Math.random() * 10)).join(\"\");",
              "pm.collectionVariables.set(\"tracking_number\", \"9400\" + digits);",
              "pm.collectionVariables.set(\"ship_date\", new Date().toISOString().slice(0, 10));"
            ]
          }
        },
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const json = pm.response.json();",
              "if (json && json.manifest_uuid) {",
              "  pm.collectionVariables.set(\"manifest_uuid\", json.manifest_uuid);",
              "}"
            ]
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"quote_uuid\": \"{{quote_uuid}}\",\n    \"order_metadata\": {\n        \"shipper_name\": \"123 Company Warehouse\",\n        \"consignee_name\": \"John Does\",\n        \"consignee_address\": \"123 Wood Ave\",\n        \"consignee_email\": \"jane.doe@example.com\",\n        \"ship_date\": \"{{ship_date}}\",\n        \"carrier\": \"UPS\",\n        \"destination_country\": \"US\",\n        \"destination_postal\": \"93063\",\n        \"external_order_ref\": \"ORD-122222\"\n    },\n    \"tracking_numbers\": [\n        \"{{tracking_number}}\"\n    ]\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "https://api.u-pic.com/partners/v1/book",
          "protocol": "https",
          "host": [
            "api",
            "u-pic",
            "com"
          ],
          "path": [
            "partners",
            "v1",
            "book"
          ]
        },
        "auth": {
          "type": "bearer",
          "bearer": [
            {
              "key": "token",
              "value": "{{token}}",
              "type": "string"
            }
          ]
        },
        "description": "Books ONE parcel against the quote. A single tracking number is sent as a plain string, and the parcel is insured for the quote's whole total_insured_value.\n\nThe tracking number and ship_date are set fresh before each run ({{tracking_number}}, {{ship_date}}), so the collection can be re-run without hitting 409 DUPLICATE_TRACKING and never books against a stale date. ship_date is the coverage date claims are checked against; invoicing is based on when the booking is made (booked_at). The Claim request files against this same parcel.\n\nA quote can only be booked once. Run Quote again before booking anything else.\n\norder_metadata.carrier is the carrier name, matched against the carriers you can book with now. Optional: send order_metadata.client_carrier_id instead ({{client_carrier_id}}, saved by Client Carriers) to name the carrier exactly; carrier can then be left out. "
      },
      "response": []
    },
    {
      "name": "Quote - Multi-Parcel",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const json = pm.response.json();",
              "if (json && json.quote_uuid) {",
              "  pm.collectionVariables.set(\"quote_uuid\", json.quote_uuid);",
              "}"
            ]
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [],
        "description": "A second quote, for the multi-parcel Book below. A quote can only be booked once, and Book (Manifest) has just booked the first one, so re-using it would return 400 INVALID_QUOTE.\n\nSame request as Quote. It overwrites {{quote_uuid}} with the new, unbooked quote. total_insured_value is 150.00, which the multi-parcel Book divides as 100.00 + 50.00.",
        "body": {
          "mode": "raw",
          "raw": "{\r\n  \"sub_client_identifier\": \"{{sub_client_identifier}}\",\r\n  \"total_insured_value\": 150.00,\r\n  \"destination_country\": \"US\",\r\n  \"perishable\": false\r\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "https://api.u-pic.com/partners/v1/quote",
          "protocol": "https",
          "host": [
            "api",
            "u-pic",
            "com"
          ],
          "path": [
            "partners",
            "v1",
            "quote"
          ]
        },
        "auth": {
          "type": "bearer",
          "bearer": [
            {
              "key": "token",
              "value": "{{token}}",
              "type": "string"
            }
          ]
        }
      },
      "response": []
    },
    {
      "name": "Book (Manifest) - Multi-Parcel",
      "event": [
        {
          "listen": "prerequest",
          "script": {
            "type": "text/javascript",
            "exec": [
              "// Two fresh tracking numbers, independent of the single-parcel booking above.",
              "const gen = () => \"9400\" + Array.from({length: 18}, () => Math.floor(Math.random() * 10)).join(\"\");",
              "pm.collectionVariables.set(\"tracking_a\", gen());",
              "pm.collectionVariables.set(\"tracking_b\", gen());",
              "pm.collectionVariables.set(\"ship_date\", new Date().toISOString().slice(0, 10));"
            ]
          }
        },
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "// Saved as manifest_uuid_multi, so {{manifest_uuid}} keeps the single-parcel",
              "// booking that Claim and Claim Status - By Booking use. Change Tracking Number",
              "// and Remove Insurance act on this multi-parcel booking.",
              "const json = pm.response.json();",
              "if (json && json.manifest_uuid) {",
              "  pm.collectionVariables.set(\"manifest_uuid_multi\", json.manifest_uuid);",
              "  console.log('multi-parcel booking ' + json.manifest_uuid +",
              "      ' with ' + json.tracking_count + ' parcels');",
              "}"
            ]
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"quote_uuid\": \"{{quote_uuid}}\",\n    \"order_metadata\": {\n        \"shipper_name\": \"123 Company Warehouse\",\n        \"consignee_name\": \"John Does\",\n        \"consignee_address\": \"123 Wood Ave\",\n        \"consignee_email\": \"jane.doe@example.com\",\n        \"ship_date\": \"{{ship_date}}\",\n        \"carrier\": \"UPS\",\n        \"destination_country\": \"US\",\n        \"destination_postal\": \"93063\",\n        \"external_order_ref\": \"ORD-133333\"\n    },\n    \"tracking_numbers\": [\n        { \"tracking_number\": \"{{tracking_a}}\", \"insured_value\": 100.00 },\n        { \"tracking_number\": \"{{tracking_b}}\", \"insured_value\": 50.00 }\n    ]\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "https://api.u-pic.com/partners/v1/book",
          "protocol": "https",
          "host": [
            "api",
            "u-pic",
            "com"
          ],
          "path": [
            "partners",
            "v1",
            "book"
          ]
        },
        "description": "Books TWO parcels under one quote, each with its own insured_value.\n\nThe per-parcel amounts must sum EXACTLY to the quote's total_insured_value (150.00 = 100.00 + 50.00), or the request is rejected with 400 INSURED_VALUE_MISMATCH.\n\nEach parcel becomes an independently insured shipment: its own coverage limit, its own share of the premium (at $0.65 per DVU, 1.30 splits as 0.65 / 0.65, one DVU each), and its own claim. Claim a parcel by its tracking_number -- manifest_uuid is ambiguous for a multi-parcel booking and returns 400 AMBIGUOUS_IDENTIFIER.\n\nBooks against the {{quote_uuid}} from Quote - Multi-Parcel, just above. A quote can only be booked once, so the quote the single-parcel Book used would return 400 INVALID_QUOTE.\n\nThe booking is saved as {{manifest_uuid_multi}}, which Change Tracking Number and Remove Insurance use.\n\nSending two or more PLAIN tracking numbers (no insured_value) returns 400 MULTIPLE_TRACKING_NOT_SUPPORTED.",
        "auth": {
          "type": "bearer",
          "bearer": [
            {
              "key": "token",
              "value": "{{token}}",
              "type": "string"
            }
          ]
        }
      },
      "response": []
    },
    {
      "name": "Claim",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const json = pm.response.json();",
              "if (json && json.claim_id) {",
              "  pm.collectionVariables.set(\"claim_id\", json.claim_id);",
              "}"
            ]
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [],
        "body": {
          "mode": "raw",
          "raw": "{\r\n  \"identifier\": {\r\n    \"type\": \"tracking_number\",\r\n    \"value\": \"{{tracking_number}}\"\r\n  },\r\n  \"claim_details\": {\r\n    \"type\": \"loss\",\r\n    \"description\": \"Customer reported package not delivered. Tracking shows delivered but customer never received.\",\r\n    \"amount\": 150.00\r\n  }\r\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "https://api.u-pic.com/partners/v1/claim",
          "protocol": "https",
          "host": [
            "api",
            "u-pic",
            "com"
          ],
          "path": [
            "partners",
            "v1",
            "claim"
          ]
        },
        "auth": {
          "type": "bearer",
          "bearer": [
            {
              "key": "token",
              "value": "{{token}}",
              "type": "string"
            }
          ]
        },
        "description": "Opens a claim against ONE booked parcel.\n\nThe parcel is identified by tracking_number rather than by {{manifest_uuid}}, because manifest_uuid names the booking rather than a parcel. On a booking with two or more parcels, claiming by manifest_uuid returns 400 AMBIGUOUS_IDENTIFIER. A tracking number is unambiguous either way, while manifest_uuid is only safe on a single-parcel booking.\n\nclaim_details.type is one of loss, damage, shortage. description is required.\n\nA claim records the booking for claims on the spot. 409 MANIFEST_NOT_SYNCED means that failed, most often because the carrier name sent at Book did not match one of your carriers. Retry once after a short wait, then contact techsupport@u-pic.com. A booking with an unmatched carrier name stays held, and cannot be claimed, until U-PIC corrects it, so copy carrier names from Client Carriers or send client_carrier_id."
      },
      "response": []
    },
    {
      "name": "Claim Attachments",
      "request": {
        "method": "POST",
        "header": [],
        "body": {
          "mode": "formdata",
          "formdata": [
            {
              "key": "file",
              "type": "file",
              "value": null
            }
          ]
        },
        "url": {
          "raw": "https://api.u-pic.com/partners/v1/claim/{{claim_id}}/attachments",
          "protocol": "https",
          "host": [
            "api",
            "u-pic",
            "com"
          ],
          "path": [
            "partners",
            "v1",
            "claim",
            "{{claim_id}}",
            "attachments"
          ]
        },
        "auth": {
          "type": "bearer",
          "bearer": [
            {
              "key": "token",
              "value": "{{token}}",
              "type": "string"
            }
          ]
        }
      },
      "response": []
    },
    {
      "name": "Claim Status",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "// Each claim comes back in the same shape as GET /claims/{id} on the",
              "// serverless API: status, claimant, claim, shipment.",
              "function show(c) {",
              "    const s = c.status || {};",
              "    console.log('claim ' + s.claim_id + ' is ' + s.claim_status +",
              "        (s.paid_date && s.paid_date.formatted",
              "            ? ', paid ' + s.claim_amount_paid + ' on ' + s.paid_date.formatted : ''));",
              "}",
              "if (pm.response.code === 200) {",
              "    const body = pm.response.json();",
              "    (body.claims || [body]).forEach(show);",
              "} else if (pm.response.code === 404) {",
              "    console.log('Not found on this account.');",
              "}"
            ]
          }
        }
      ],
      "request": {
        "method": "GET",
        "header": [],
        "url": {
          "raw": "https://api.u-pic.com/partners/v1/claim/{{claim_id}}",
          "protocol": "https",
          "host": [
            "api",
            "u-pic",
            "com"
          ],
          "path": [
            "partners",
            "v1",
            "claim",
            "{{claim_id}}"
          ]
        },
        "auth": {
          "type": "bearer",
          "bearer": [
            {
              "key": "token",
              "value": "{{token}}",
              "type": "string"
            }
          ]
        },
        "description": "Reads a claim back by the claim_id that Claim returned.\n\nEach claim comes back in the same shape as GET /claims/{id} on the serverless API: status (claim_status, claim_amount, claim_amount_paid, paid_date), claimant, claim and shipment.\n\nRun Claim first: {{claim_id}} is captured by that request's test script."
      },
      "response": []
    },
    {
      "name": "Claim Status - By Booking",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "// Each claim comes back in the same shape as GET /claims/{id} on the",
              "// serverless API: status, claimant, claim, shipment.",
              "function show(c) {",
              "    const s = c.status || {};",
              "    console.log('claim ' + s.claim_id + ' is ' + s.claim_status +",
              "        (s.paid_date && s.paid_date.formatted",
              "            ? ', paid ' + s.claim_amount_paid + ' on ' + s.paid_date.formatted : ''));",
              "}",
              "if (pm.response.code === 200) {",
              "    const body = pm.response.json();",
              "    (body.claims || [body]).forEach(show);",
              "} else if (pm.response.code === 404) {",
              "    console.log('Not found on this account.');",
              "}"
            ]
          }
        }
      ],
      "request": {
        "method": "GET",
        "header": [],
        "url": {
          "raw": "https://api.u-pic.com/partners/v1/claim?manifest_uuid={{manifest_uuid}}",
          "protocol": "https",
          "host": [
            "api",
            "u-pic",
            "com"
          ],
          "path": [
            "partners",
            "v1",
            "claim"
          ],
          "query": [
            {
              "key": "manifest_uuid",
              "value": "{{manifest_uuid}}"
            }
          ]
        },
        "auth": {
          "type": "bearer",
          "bearer": [
            {
              "key": "token",
              "value": "{{token}}",
              "type": "string"
            }
          ]
        },
        "description": "Every claim on every parcel of a booking, as a list: {manifest_uuid, count, claims: [...]}.\n\nUse ?tracking_number= instead for the claims on one parcel. Send exactly one of the two.\n\nNo claims is a 200 with an empty list, not an error."
      },
      "response": []
    },
    {
      "name": "Affidavit Request",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "// 201: the email to the buyer is queued. 400 ALREADY_FILLED / TOO_SOON: see the error codes.",
              "if (pm.response.code === 201) {",
              "    const body = pm.response.json();",
              "    console.log('affidavit request ' + body.affidavit_request_id + ' ' + body.status + ', link expires ' + body.expires_at);",
              "} else {",
              "    console.log(pm.response.json());",
              "}"
            ]
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"email\": \"buyer@example.com\"\n}"
        },
        "url": {
          "raw": "https://api.u-pic.com/partners/v1/claim/{{claim_id}}/affidavits",
          "protocol": "https",
          "host": [
            "api",
            "u-pic",
            "com"
          ],
          "path": [
            "partners",
            "v1",
            "claim",
            "{{claim_id}}",
            "affidavits"
          ]
        },
        "auth": {
          "type": "bearer",
          "bearer": [
            {
              "key": "token",
              "value": "{{token}}",
              "type": "string"
            }
          ]
        },
        "description": "Emails the buyer a link to a short signed statement confirming what happened to the package. The email names the store (the company_name given to Create), the tracking number and what was reported.\n\nA claim takes one signed affidavit: once signed, another request returns 400 ALREADY_FILLED. A second request to the same email within 3 days returns 400 TOO_SOON.\n\nRun Claim first: {{claim_id}} is captured from its response. Replace the email with an inbox you control when testing."
      },
      "response": []
    },
    {
      "name": "Affidavit List",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "if (pm.response.code === 200) {",
              "    pm.response.json().affidavits.forEach(function (a) {",
              "        console.log(a.affidavit_request_id + ' to ' + a.sent_to + ': ' + a.status);",
              "    });",
              "}"
            ]
          }
        }
      ],
      "request": {
        "method": "GET",
        "header": [],
        "url": {
          "raw": "https://api.u-pic.com/partners/v1/claim/{{claim_id}}/affidavits",
          "protocol": "https",
          "host": [
            "api",
            "u-pic",
            "com"
          ],
          "path": [
            "partners",
            "v1",
            "claim",
            "{{claim_id}}",
            "affidavits"
          ]
        },
        "auth": {
          "type": "bearer",
          "bearer": [
            {
              "key": "token",
              "value": "{{token}}",
              "type": "string"
            }
          ]
        },
        "description": "Lists the affidavit requests sent on a claim, newest first. Each is completed once the buyer has signed (with completed_at and affidavit_id), otherwise pending. The access code is masked."
      },
      "response": []
    },
    {
      "name": "Settlements",
      "event": [
        {
          "listen": "prerequest",
          "script": {
            "type": "text/javascript",
            "exec": [
              "// Default the report to the last full 30 days so the request runs as-is.",
              "// Replace date_from / date_to with the period you are reconciling.",
              "const day = 24 * 60 * 60 * 1000;",
              "const iso = (d) => new Date(d).toISOString().slice(0, 10);",
              "pm.collectionVariables.set(\"date_to\", iso(Date.now()));",
              "pm.collectionVariables.set(\"date_from\", iso(Date.now() - 30 * day));"
            ]
          }
        },
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const json = pm.response.json();",
              "if (json && Array.isArray(json.settlements)) {",
              "  console.log(\"page \" + json.page + \"/\" + json.total_pages + \": \" +",
              "              json.settlements.length + \" rows, \" + json.total_count +",
              "              \" settlements totalling \" + json.total_paid_amount + \" in range\");",
              "  if (json.has_more) {",
              "    console.log(\"More to collect -- re-send with page=\" + (json.page + 1));",
              "  }",
              "}"
            ]
          }
        }
      ],
      "request": {
        "method": "GET",
        "header": [],
        "url": {
          "raw": "https://api.u-pic.com/partners/v1/settlements?date_from={{date_from}}&date_to={{date_to}}",
          "protocol": "https",
          "host": [
            "api",
            "u-pic",
            "com"
          ],
          "path": [
            "partners",
            "v1",
            "settlements"
          ],
          "query": [
            {
              "key": "date_from",
              "value": "{{date_from}}"
            },
            {
              "key": "date_to",
              "value": "{{date_to}}"
            },
            {
              "key": "sub_client_identifier",
              "value": "{{sub_client_identifier}}",
              "disabled": true
            },
            {
              "key": "page",
              "value": "2",
              "disabled": true
            }
          ]
        },
        "auth": {
          "type": "bearer",
          "bearer": [
            {
              "key": "token",
              "value": "{{token}}",
              "type": "string"
            }
          ]
        },
        "description": "Lists the claims U-PIC has PAID in a date range, for reconciling payments against your own records.\n\nThe range matches on pay date, not file date: a claim filed in June and paid in August appears in an August report. Both dates are inclusive, and the range cannot exceed 366 days.\n\nOptional filters:\n  sub_client_identifier   restrict to one seller\n  page                    only needed for a range over 5,000 rows\n\nUp to 5,000 settlements come back in one request, which covers a normal reporting period. If the range holds more, total_pages says how many there are and has_more stays true: send the SAME request again with page=2, then 3, until has_more is false.\n\nKeep date_from, date_to and sub_client_identifier identical across the pages of one walk -- a page number is a position within that filtered set. page defaults to 1, so sending page=1 on the first call changes nothing. The page size is fixed at 5,000 and is not a parameter you send.\n\ntotal_count and total_paid_amount cover the WHOLE range rather than the page in hand, so the figure you reconcile against reads the same on every page.\n\nIncludes every paid claim on your account, not only those filed through this API. A claim U-PIC entered on your behalf returns null for external_order_ref, manifest_uuid and carrier, because its parcel was not booked here.\n\nA claim appears only once it carries both a pay date and the Paid status - approved-but-unpaid is not a settlement."
      },
      "response": []
    },
    {
      "name": "Booking Lookup",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "// A booking read back. ACTIVE means the parcel is insured -- read that,",
              "// not the 200 itself.",
              "if (pm.response.code === 200) {",
              "    const b = pm.response.json();",
              "    console.log('booking ' + b.manifest_uuid + ' is ' + b.status);",
              "    console.log('premium ' + b.premium_amount + ' covering ' + b.total_insured_value);",
              "    console.log(b.tracking_count + ' parcel(s): ' + (b.tracking_numbers || [])",
              "        .map(function (t) { return t.tracking_number; }).join(', '));",
              "} else if (pm.response.code === 404) {",
              "    console.log('No such booking on this account -- it was never created.');",
              "}"
            ]
          }
        }
      ],
      "request": {
        "method": "GET",
        "header": [],
        "url": {
          "raw": "https://api.u-pic.com/partners/v1/bookings/{{manifest_uuid}}",
          "protocol": "https",
          "host": [
            "api",
            "u-pic",
            "com"
          ],
          "path": [
            "partners",
            "v1",
            "bookings",
            "{{manifest_uuid}}"
          ]
        },
        "auth": {
          "type": "bearer",
          "bearer": [
            {
              "key": "token",
              "value": "{{token}}",
              "type": "string"
            }
          ]
        },
        "description": "Reads a booking back by the manifest_uuid that Book returned.\n\nstatus is the field that answers \"did this book?\" - ACTIVE means the parcel is insured. Do not infer it from the 200 alone.\n\npremium_amount is what the booking is CHARGED, the same figure that reaches your invoice. If you submitted your own premium_amount at quote time, that value is kept for comparison and is not what you are billed.\n\npremium_amount and total_insured_value describe the whole booking, not one parcel, so a multi-parcel booking returns every parcel in tracking_numbers[] with each parcel's own insured_value.\n\nRun Book first: {{manifest_uuid}} is captured by that request's test script."
      },
      "response": []
    },
    {
      "name": "Change Tracking Number",
      "event": [
        {
          "listen": "prerequest",
          "script": {
            "type": "text/javascript",
            "exec": [
              "// A fresh replacement number, set before every run, the same way Book sets its tracking numbers.",
              "// A number that is already booked would return 409 DUPLICATE_TRACKING.",
              "const digits = Array.from({length: 18}, () => Math.floor(Math.random() * 10)).join(\"\");",
              "pm.collectionVariables.set(\"tracking_number_new\", \"9400\" + digits);"
            ]
          }
        },
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "// The booking comes back in the same shape Booking Lookup returns.",
              "if (pm.response.code === 200) {",
              "    const b = pm.response.json();",
              "    console.log('booking ' + b.manifest_uuid + ' now covers: ' +",
              "        (b.tracking_numbers || []).map(function (t) { return t.tracking_number; }).join(', '));",
              "    console.log('premium unchanged at ' + b.premium_amount);",
              "} else if (pm.response.code === 400) {",
              "    const b = pm.response.json();",
              "    if (b.errcode === 'AMBIGUOUS_PARCEL') {",
              "        console.log('Multi-parcel booking -- send from_tracking_number. Parcels: ' +",
              "            (b.tracking_numbers || []).join(', '));",
              "    }",
              "} else if (pm.response.code === 409) {",
              "    console.log('Refused: ' + pm.response.json().errcode);",
              "}"
            ]
          }
        }
      ],
      "request": {
        "method": "PATCH",
        "header": [],
        "body": {
          "mode": "raw",
          "raw": "{\r\n  \"from_tracking_number\": \"{{tracking_b}}\",\r\n  \"to_tracking_number\": \"{{tracking_number_new}}\"\r\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "https://api.u-pic.com/partners/v1/bookings/{{manifest_uuid_multi}}",
          "protocol": "https",
          "host": [
            "api",
            "u-pic",
            "com"
          ],
          "path": [
            "partners",
            "v1",
            "bookings",
            "{{manifest_uuid_multi}}"
          ]
        },
        "auth": {
          "type": "bearer",
          "bearer": [
            {
              "key": "token",
              "value": "{{token}}",
              "type": "string"
            }
          ]
        },
        "description": "Corrects the tracking number on one parcel of a booking, for when a seller voids a label and reships under a new number.\n\nThis example changes {{tracking_b}} on the multi-parcel booking ({{manifest_uuid_multi}}) to {{tracking_number_new}}, which is generated before each run. It uses that booking because the single-parcel one has a claim on it by now.\n\nThis is a CORRECTION, not a re-booking. The premium, the coverage and the billing period all stay exactly as they were and only the identifying number moves. Cancelling and re-booking instead would re-price the shipment and can move it into a different billing period, so use this whenever the shipment itself has not changed.\n\nfrom_tracking_number is REQUIRED whenever the booking covers more than one parcel. Omit it only on a single-parcel booking; on a multi-parcel one the request returns 400 AMBIGUOUS_PARCEL rather than guessing which parcel you meant.\n\nReturns the booking in the same shape as Booking Lookup, so one response handler serves both.\n\nSafe to retry: re-sending a change that already succeeded returns 200, not an error.\n\nRefused with 409 CLAIM_EXISTS once a claim is filed against the parcel - the tracking number is what identifies that claim, and moving it would leave the claim pointing at a number nothing can find."
      },
      "response": []
    },
    {
      "name": "Remove Insurance - One Parcel",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "if (pm.response.code === 200) {",
              "    const b = pm.response.json();",
              "    console.log('cancelled: ' + (b.cancelled_tracking_numbers || []).join(', '));",
              "    // ACTIVE here is correct: the booking still insures its other parcels.",
              "    console.log('booking is now ' + b.status + ', ' + b.tracking_count + ' parcel(s) listed');",
              "} else if (pm.response.code === 409) {",
              "    const b = pm.response.json();",
              "    console.log('Refused: ' + b.errcode);",
              "}"
            ]
          }
        }
      ],
      "request": {
        "method": "DELETE",
        "header": [],
        "url": {
          "raw": "https://api.u-pic.com/partners/v1/bookings/{{manifest_uuid_multi}}?tracking_number={{tracking_a}}",
          "protocol": "https",
          "host": [
            "api",
            "u-pic",
            "com"
          ],
          "path": [
            "partners",
            "v1",
            "bookings",
            "{{manifest_uuid_multi}}"
          ],
          "query": [
            {
              "key": "tracking_number",
              "value": "{{tracking_a}}"
            }
          ]
        },
        "auth": {
          "type": "bearer",
          "bearer": [
            {
              "key": "token",
              "value": "{{token}}",
              "type": "string"
            }
          ]
        },
        "description": "Removes insurance from ONE parcel of a booking, leaving the others insured.\n\ntracking_number says which parcel. The booking stays ACTIVE while any parcel remains insured - coverage belongs to the parcel, not the booking - and only becomes CANCELLED once the last one is cancelled.\n\nREQUIRES the delete_manifests permission. Without it, 403.\n\nOnly meaningful on a multi-parcel booking. This example removes {{tracking_a}} from the multi-parcel booking ({{manifest_uuid_multi}}), leaving the other parcel insured. 'Remove Insurance' below then removes what is left.\n\nOn a booking with only ONE parcel this is identical to 'Remove Insurance' - cancelling the only parcel cancels the booking. Naming the parcel changes nothing there; it matters only when there are others to leave insured."
      },
      "response": []
    },
    {
      "name": "Remove Insurance",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "if (pm.response.code === 200) {",
              "    const b = pm.response.json();",
              "    if (b.already_cancelled) {",
              "        console.log('Already cancelled; nothing further to do.');",
              "    } else {",
              "        console.log('cancelled ' + (b.cancelled_tracking_numbers || []).length +",
              "            ' parcel(s); booking is now ' + b.status);",
              "    }",
              "} else if (pm.response.code === 403) {",
              "    console.log('This key does not carry delete_manifests.');",
              "} else if (pm.response.code === 409) {",
              "    console.log('Refused: ' + pm.response.json().errcode);",
              "}"
            ]
          }
        }
      ],
      "request": {
        "method": "DELETE",
        "header": [],
        "url": {
          "raw": "https://api.u-pic.com/partners/v1/bookings/{{manifest_uuid_multi}}",
          "protocol": "https",
          "host": [
            "api",
            "u-pic",
            "com"
          ],
          "path": [
            "partners",
            "v1",
            "bookings",
            "{{manifest_uuid_multi}}"
          ]
        },
        "auth": {
          "type": "bearer",
          "bearer": [
            {
              "key": "token",
              "value": "{{token}}",
              "type": "string"
            }
          ]
        },
        "description": "Removes insurance from the WHOLE booking - every parcel on it.\n\nThis example acts on the multi-parcel booking ({{manifest_uuid_multi}}) after 'Remove Insurance - One Parcel' above, so it cancels the parcel still insured and the booking becomes CANCELLED.\n\nNo tracking_number is sent, which is what makes this the whole-booking form. To cancel a single parcel instead, use 'Remove Insurance - One Parcel'.\n\nREQUIRES the delete_manifests permission on your key, the same permission that governs deleting a manifest through the standard API. Without it, 403.\n\nOnce the last parcel is cancelled the booking itself becomes CANCELLED, and every tracking number on it becomes bookable again.\n\nRefused with 409 CLAIM_EXISTS if a claim is filed against any parcel.\n\nOn a booking with only ONE parcel this and 'Remove Insurance - One Parcel' do exactly the same thing: the single parcel is cancelled and the booking becomes CANCELLED either way. The distinction only matters on a multi-parcel booking."
      },
      "response": []
    },
    {
      "name": "Reconciliation Report",
      "event": [
        {
          "listen": "prerequest",
          "script": {
            "type": "text/javascript",
            "exec": [
              "// Default the report to LAST MONTH (1st to last day) -- one invoice period -- so the",
              "// request runs as-is. Replace date_from / date_to with the period you are reconciling.",
              "const now = new Date();",
              "const first = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth() - 1, 1));",
              "const last = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), 0));",
              "const iso = (d) => d.toISOString().slice(0, 10);",
              "pm.collectionVariables.set(\"date_from\", iso(first));",
              "pm.collectionVariables.set(\"date_to\", iso(last));"
            ]
          }
        },
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "// One row per invoiced line. premium_charged sums to what was invoiced;",
              "// group by manifest_uuid for booking totals.",
              "if (pm.response.code === 200) {",
              "    const r = pm.response.json();",
              "    const total = (r.rows || []).reduce((s, x) => s + (x.premium_charged || 0), 0);",
              "    console.log(r.total_count + ' row(s), premium on this page ' + total.toFixed(2));",
              "    if (r.has_more) { console.log('More pages: re-send with page=' + (r.page + 1)); }",
              "}"
            ]
          }
        }
      ],
      "request": {
        "method": "GET",
        "header": [],
        "url": {
          "raw": "https://api.u-pic.com/partners/v1/bookings?date_from={{date_from}}&date_to={{date_to}}",
          "protocol": "https",
          "host": [
            "api",
            "u-pic",
            "com"
          ],
          "path": [
            "partners",
            "v1",
            "bookings"
          ],
          "query": [
            {
              "key": "date_from",
              "value": "{{date_from}}"
            },
            {
              "key": "date_to",
              "value": "{{date_to}}"
            },
            {
              "key": "sub_client_identifier",
              "value": "{{sub_client_identifier}}",
              "disabled": true
            },
            {
              "key": "page",
              "value": "2",
              "disabled": true
            }
          ]
        },
        "auth": {
          "type": "bearer",
          "bearer": [
            {
              "key": "token",
              "value": "{{token}}",
              "type": "string"
            }
          ]
        },
        "description": "The lines of your invoices whose date falls in a range, one row per parcel, for reconciling an invoice against your own records. To get one whole invoice, use 'Reconciliation Report - By Invoice' instead.\n\nEvery row is a line on an invoice and carries its invoice_id, so the rows add up to what you were invoiced. A period that has not been invoiced yet returns no rows. A CHARGE row is in the range by the date the parcel was booked (booked_at), a CREDIT row by the date it was cancelled. {{date_from}} to {{date_to}} are both inclusive, at most 366 days.\n\nEach row: type, invoice_id, manifest_uuid, tracking_number, ship_date, declared_value, premium_charged, carrier, external_order_ref, sub_client_identifier, status. type is CHARGE for a parcel billed on the invoice, or CREDIT for an adjustment, where one applies to your account. A booking covering several parcels appears as several rows sharing its manifest_uuid.\n\nA parcel cancelled after its invoice was issued stays on that invoice as charged, with status CANCELLED. A parcel cancelled before its invoice was issued was never billed and does not appear.\n\nPaging works as it does for Settlements: while has_more is true, re-send with the next page."
      },
      "response": []
    },
    {
      "name": "Reconciliation Report - By Invoice",
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "// One row per invoiced line. premium_charged sums to what was invoiced;",
              "// group by manifest_uuid for booking totals.",
              "if (pm.response.code === 200) {",
              "    const r = pm.response.json();",
              "    const total = (r.rows || []).reduce((s, x) => s + (x.premium_charged || 0), 0);",
              "    console.log(r.total_count + ' row(s), premium on this page ' + total.toFixed(2));",
              "    if (r.has_more) { console.log('More pages: re-send with page=' + (r.page + 1)); }",
              "}"
            ]
          }
        }
      ],
      "request": {
        "method": "GET",
        "header": [],
        "url": {
          "raw": "https://api.u-pic.com/partners/v1/bookings?invoice_id={{invoice_id}}",
          "protocol": "https",
          "host": [
            "api",
            "u-pic",
            "com"
          ],
          "path": [
            "partners",
            "v1",
            "bookings"
          ],
          "query": [
            {
              "key": "invoice_id",
              "value": "{{invoice_id}}"
            }
          ]
        },
        "auth": {
          "type": "bearer",
          "bearer": [
            {
              "key": "token",
              "value": "{{token}}",
              "type": "string"
            }
          ]
        },
        "description": "Every line of one invoice, one row per parcel, so premium_charged sums to the invoice.\n\nSet {{invoice_id}} to the invoice number on your invoice. Send invoice_id OR date_from/date_to, not both (400 CONFLICTING_FILTERS). An invoice not on your account returns 404 INVOICE_NOT_FOUND.\n\nSame rows and paging as 'Reconciliation Report'."
      },
      "response": []
    }
  ]
}
