{
  "info": {
    "name": "MarsX Lead Intake API: check your endpoints",
    "description": "Check your four hosted endpoints yourself, before you ask MarsX to run its reconciliation tests (R1 to R5). Point this collection at YOUR sandbox, run it, and fix what fails. It does not call any MarsX server.\n\n**The four endpoints** (integration guide section 5): your OAuth token URL, GET /v1/changes, GET /v1/privacy-events and GET /v1/leads/{partner_lead_id}. The checks use the JSON Schemas of the MarsX Lead Intake API v1 contract (openapi.yaml).\n\n**How to use it**\n\n1. Fork this collection and the environment \"MarsX endpoint check\" into your own workspace, or import both files.\n2. Select the environment and fill it. `partner_base_url` and `partner_token_url` are the addresses of your sandbox. `marsx_client_id` and `marsx_client_secret` are the read-only OAuth client you would give MarsX. `scope` is your read scope (the guide uses leads:read). `test_lead_id` is a live lead, `withdrawn_lead_id` a lead you hold that withdrew consent, `erased_lead_id` a lead you erased and no longer hold. `expired_changes_cursor` and `expired_privacy_cursor` are the two cursors that always answer 410. Fill the secret as a current value only. Never share or commit a filled environment.\n3. Run the whole collection in the Collection Runner, in order. Request 1 fetches the token that the other requests use, so run it first when you send a single request. Request 4 repeats itself until the last page, so a single Send reads one page only.\n\nUse a sandbox with invented leads only. Never point this collection at production data.\n\n**What each request checks, and the MarsX test it prepares**\n\n| Request | Checks | MarsX test |\n|---|---|---|\n| 1 and 2 | Token URL: 200 with the PartnerTokenResponse shape, and 401 invalid_client for a wrong secret | all |\n| 3 | changes, first page: 200, ChangesPage schema, next_cursor present, default page size | R1 |\n| 4 | changes, paging with limit=500 until has_more is false: order, no repeated (partner_lead_id, source_revision) pair, next_cursor on the last page | R2 |\n| 5 | changes: a limit above the maximum gets 400 | R2 |\n| 6 | changes: the expired cursor gets 410 urn:marsx:problem:cursor-expired | R4 |\n| 7 | privacy-events, first page: 200, PrivacyEventsPage schema, no contact or profile data | R1, R3 |\n| 8 | privacy-events: the expired cursor gets 410 | R4 |\n| 9 | leads: a live lead gets 200 with the LeadData shape, source_revision and updated_at | R1, R2 |\n| 10 | leads: a withdrawn lead gets 200 with the withdrawal form and no contact data | R1 |\n| 11 | leads: an erased lead you no longer hold gets 404 as application/problem+json | R3 |\n| 12 and 13 | No token and a bad token both get 401 | all |\n\n**What it cannot check.** R5 (the privacy list after an expired privacy-events cursor) is a file you send when MarsX asks. A valid token without the scope getting 403, your request limits, and whether 1,001 or more changes with one updated_at survive a restart between pages are checked by MarsX only. Request 4 reads straight through and looks for repeats and a wrong order.\n\n**MarsX still runs its own reconciliation tests afterwards.** A green run here means your status codes and shapes are right. It does not prove that your data is complete, and MarsX confirms each of R1 to R5 by email.\n\n**Safety.** Every request is sent over HTTPS only: a base URL or token URL that is not https is refused before anything is sent (the one exception is http://localhost and http://127.0.0.1, for local testing). A refused request loses its credentials, is pointed at an address that cannot resolve (.invalid) and shows an error. Redirects are not followed, and a 3xx answer fails a test. Request 1 fetches the bearer token and caches it in a collection variable (current value only). The other requests use it until 30 seconds before it expires, and then refuse to run until you run request 1 again. Headers that start with X-Mx- only steer the script and are removed before sending.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "event": [
    {
      "listen": "prerequest",
      "script": {
        "type": "text/javascript",
        "exec": [
          "// MarsX endpoint check, collection pre-request script. Runs before every request.",
          "// 1. Refuses a base URL or token URL that is not https (only http://localhost and http://127.0.0.1 pass, for local testing).",
          "// 2. Checks that the variables a request needs are filled.",
          "// 3. Adds the bearer token that request 1 cached. Headers that start with X-Mx- only steer this script and are removed before sending.",
          "// A script that only throws does not stop Postman from sending the request (the Postman CLI sends it anyway). refuse() therefore also drops the",
          "// credentials and points the request at a name that cannot resolve (.invalid), so that nothing leaves your machine when a check fails.",
          "const H = pm.request.headers;",
          "const refuse = (message) => {",
          "  H.remove('Authorization');",
          "  try { pm.request.url.update('https://refused.invalid/'); } catch (e) { /* the error below still stops the check */ }",
          "  throw new Error(message);",
          "};",
          "const val = (k) => String(pm.variables.get(k) || '').trim();",
          "const allowed = (u) => /^https:\\/\\//i.test(u) || /^http:\\/\\/(localhost|127\\.0\\.0\\.1)(:\\d+)?(\\/|$)/i.test(u);",
          "const HTTPS = ' must start with https:// (http://localhost and http://127.0.0.1 are allowed for local testing). Refusing to send anything.';",
          "const base = val('partner_base_url').replace(/\\/+$/, '');",
          "if (!base) { refuse('partner_base_url is empty. Fill the environment with the base URL of YOUR sandbox.'); }",
          "if (!allowed(base)) { refuse('partner_base_url' + HTTPS); }",
          "const tokenUrl = val('partner_token_url');",
          "if (tokenUrl && !allowed(tokenUrl)) { refuse('partner_token_url' + HTTPS); }",
          "pm.variables.set('partner_base_url', base);",
          "['test_lead_id', 'withdrawn_lead_id', 'erased_lead_id'].forEach((k) => pm.variables.set(k + '_enc', encodeURIComponent(val(k))));",
          "",
          "const ctl = (name) => { const h = H.get(name); if (h !== undefined && h !== null) { H.remove(name); } return h; };",
          "const mode = String(ctl('X-Mx-Auth') || 'bearer');",
          "String(ctl('X-Mx-Need') || '').split(',').map((s) => s.trim()).filter(Boolean).forEach((k) => {",
          "  if (!val(k)) { refuse(k + ' is empty. Fill it in the environment before you run this request.'); }",
          "});",
          "H.upsert({ key: 'Accept', value: 'application/json' });",
          "",
          "if (mode === 'token') { return; }",
          "if (mode === 'none') { H.remove('Authorization'); return; }",
          "if (mode === 'bad') { H.upsert({ key: 'Authorization', value: 'Bearer ' + 'never-issued-by-your-server' }); return; }",
          "",
          "const cv = pm.collectionVariables;",
          "const cached = cv.get('access_token_cache');",
          "const until = Number(cv.get('access_token_until') || 0);",
          "if (!cached || until - 30000 <= Date.now()) {",
          "  refuse('No valid token. Run request 1 (Token: valid client) first, or run the whole collection in order. Request 1 fetches the token and it is renewed by running request 1 again, 30 seconds before it expires.');",
          "}",
          "H.upsert({ key: 'Authorization', value: 'Bearer ' + cached });"
        ]
      }
    },
    {
      "listen": "test",
      "script": {
        "type": "text/javascript",
        "exec": [
          "// Every request: a redirect is a failure to fix, never something to follow.",
          "if (pm.response) {",
          "  pm.test('no redirect: the answer is not a 3xx (guide section 5)', () => pm.expect(pm.response.code, 'status ' + pm.response.code + ', Location ' + pm.response.headers.get('Location')).to.not.be.within(300, 399));",
          "}"
        ]
      }
    }
  ],
  "item": [
    {
      "name": "1. Token: valid client",
      "protocolProfileBehavior": {
        "followRedirects": false,
        "followOriginalHttpMethod": false
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const PROBLEM = {\"type\":\"object\",\"required\":[\"type\",\"title\",\"status\"],\"properties\":{\"type\":{\"type\":\"string\"},\"title\":{\"type\":\"string\"},\"status\":{\"type\":\"integer\"},\"detail\":{\"type\":\"string\"},\"instance\":{\"type\":\"string\"},\"errors\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"required\":[\"pointer\",\"message\"],\"properties\":{\"pointer\":{\"type\":\"string\"},\"message\":{\"type\":\"string\"}}}}},\"additionalProperties\":true};",
              "const json = () => { try { return pm.response.json(); } catch (e) { return undefined; } };",
              "const contentType = () => String(pm.response.headers.get('Content-Type') || '');",
              "const isProblemJson = () => contentType().toLowerCase().indexOf('application/problem+json') >= 0;",
              "const problemTests = (status) => {",
              "  pm.test('the error answer is application/problem+json (guide section 5)', () => pm.expect(isProblemJson(), 'Content-Type was \"' + contentType() + '\"').to.be.true);",
              "  pm.test('the error answer has type, title and status ' + status + ' (ProblemDetails)', () => {",
              "    pm.response.to.have.jsonSchema(PROBLEM);",
              "    pm.expect(json().status, 'the status member').to.eql(status);",
              "  });",
              "};",
              "",
              "const TOKEN = {\"type\":\"object\",\"required\":[\"access_token\",\"token_type\",\"expires_in\"],\"properties\":{\"access_token\":{\"type\":\"string\",\"minLength\":1},\"token_type\":{\"type\":\"string\",\"const\":\"Bearer\"},\"expires_in\":{\"type\":\"integer\",\"minimum\":300,\"maximum\":86400},\"scope\":{\"type\":\"string\"}}};",
              "const body = json();",
              "pm.test('token URL: 200 OK', () => pm.response.to.have.status(200));",
              "pm.test('token URL: the body is JSON', () => pm.expect(contentType().toLowerCase()).to.include('application/json'));",
              "pm.test('token URL: matches the PartnerTokenResponse schema (access_token, token_type Bearer, expires_in 300 to 86400)', () => pm.response.to.have.jsonSchema(TOKEN));",
              "if (pm.response.code === 200 && body && typeof body.access_token === 'string' && body.access_token) {",
              "  pm.collectionVariables.set('access_token_cache', body.access_token);",
              "  pm.collectionVariables.set('access_token_until', String(Date.now() + Number(body.expires_in || 300) * 1000));",
              "}"
            ]
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "X-Mx-Auth",
            "value": "token"
          },
          {
            "key": "X-Mx-Need",
            "value": "partner_token_url,marsx_client_id,marsx_client_secret"
          }
        ],
        "url": {
          "raw": "{{partner_token_url}}",
          "host": [
            "{{partner_token_url}}"
          ]
        },
        "description": "Asks your token URL for a token with the MarsX client (HTTP Basic, grant_type client_credentials, the scope). Guide section 5.1. The token is kept in a collection variable (current value only) for the requests that follow, so run this request first.",
        "auth": {
          "type": "basic",
          "basic": [
            {
              "key": "username",
              "value": "{{marsx_client_id}}",
              "type": "string"
            },
            {
              "key": "password",
              "value": "{{marsx_client_secret}}",
              "type": "string"
            }
          ]
        },
        "body": {
          "mode": "urlencoded",
          "urlencoded": [
            {
              "key": "grant_type",
              "value": "client_credentials",
              "type": "text"
            },
            {
              "key": "scope",
              "value": "{{scope}}",
              "type": "text"
            }
          ]
        }
      }
    },
    {
      "name": "2. Token: wrong secret gets 401 invalid_client",
      "protocolProfileBehavior": {
        "followRedirects": false,
        "followOriginalHttpMethod": false
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const PROBLEM = {\"type\":\"object\",\"required\":[\"type\",\"title\",\"status\"],\"properties\":{\"type\":{\"type\":\"string\"},\"title\":{\"type\":\"string\"},\"status\":{\"type\":\"integer\"},\"detail\":{\"type\":\"string\"},\"instance\":{\"type\":\"string\"},\"errors\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"required\":[\"pointer\",\"message\"],\"properties\":{\"pointer\":{\"type\":\"string\"},\"message\":{\"type\":\"string\"}}}}},\"additionalProperties\":true};",
              "const json = () => { try { return pm.response.json(); } catch (e) { return undefined; } };",
              "const contentType = () => String(pm.response.headers.get('Content-Type') || '');",
              "const isProblemJson = () => contentType().toLowerCase().indexOf('application/problem+json') >= 0;",
              "const problemTests = (status) => {",
              "  pm.test('the error answer is application/problem+json (guide section 5)', () => pm.expect(isProblemJson(), 'Content-Type was \"' + contentType() + '\"').to.be.true);",
              "  pm.test('the error answer has type, title and status ' + status + ' (ProblemDetails)', () => {",
              "    pm.response.to.have.jsonSchema(PROBLEM);",
              "    pm.expect(json().status, 'the status member').to.eql(status);",
              "  });",
              "};",
              "",
              "const body = json();",
              "pm.test('wrong secret: 401 Unauthorized', () => pm.response.to.have.status(401));",
              "pm.test('wrong secret: the body is JSON', () => pm.expect(contentType().toLowerCase()).to.include('application/json'));",
              "pm.test('wrong secret: the error is invalid_client', () => pm.expect(body && body.error, 'error member').to.eql('invalid_client'));",
              "pm.test('wrong secret: no access_token in the answer', () => pm.expect(body && body.access_token, 'access_token').to.be.undefined);"
            ]
          }
        }
      ],
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "X-Mx-Auth",
            "value": "token"
          },
          {
            "key": "X-Mx-Need",
            "value": "partner_token_url,marsx_client_id"
          }
        ],
        "url": {
          "raw": "{{partner_token_url}}",
          "host": [
            "{{partner_token_url}}"
          ]
        },
        "description": "Sends a wrong client secret. Expect 401 with the JSON error invalid_client (RFC 6749 section 5.2, guide section 5.1). The cached token is not touched.",
        "auth": {
          "type": "basic",
          "basic": [
            {
              "key": "username",
              "value": "{{marsx_client_id}}",
              "type": "string"
            },
            {
              "key": "password",
              "value": "marsx-endpoint-check-wrong-secret",
              "type": "string"
            }
          ]
        },
        "body": {
          "mode": "urlencoded",
          "urlencoded": [
            {
              "key": "grant_type",
              "value": "client_credentials",
              "type": "text"
            },
            {
              "key": "scope",
              "value": "{{scope}}",
              "type": "text"
            }
          ]
        }
      }
    },
    {
      "name": "3. changes: first page",
      "protocolProfileBehavior": {
        "followRedirects": false,
        "followOriginalHttpMethod": false
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const PROBLEM = {\"type\":\"object\",\"required\":[\"type\",\"title\",\"status\"],\"properties\":{\"type\":{\"type\":\"string\"},\"title\":{\"type\":\"string\"},\"status\":{\"type\":\"integer\"},\"detail\":{\"type\":\"string\"},\"instance\":{\"type\":\"string\"},\"errors\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"required\":[\"pointer\",\"message\"],\"properties\":{\"pointer\":{\"type\":\"string\"},\"message\":{\"type\":\"string\"}}}}},\"additionalProperties\":true};",
              "const json = () => { try { return pm.response.json(); } catch (e) { return undefined; } };",
              "const contentType = () => String(pm.response.headers.get('Content-Type') || '');",
              "const isProblemJson = () => contentType().toLowerCase().indexOf('application/problem+json') >= 0;",
              "const problemTests = (status) => {",
              "  pm.test('the error answer is application/problem+json (guide section 5)', () => pm.expect(isProblemJson(), 'Content-Type was \"' + contentType() + '\"').to.be.true);",
              "  pm.test('the error answer has type, title and status ' + status + ' (ProblemDetails)', () => {",
              "    pm.response.to.have.jsonSchema(PROBLEM);",
              "    pm.expect(json().status, 'the status member').to.eql(status);",
              "  });",
              "};",
              "",
              "",
              "const feedTests = () => {",
              "  const body = json();",
              "  pm.test('changes first page: 200 OK', () => pm.response.to.have.status(200));",
              "  pm.test('changes first page: the body is JSON', () => pm.expect(contentType().toLowerCase()).to.include('application/json'));",
              "  pm.test('changes first page: matches the ChangesPage schema', () => pm.response.to.have.jsonSchema(CHANGES_PAGE));",
              "  pm.test('changes first page: next_cursor is present and not empty', () => pm.expect(body && body.next_cursor, 'next_cursor').to.be.a('string').and.not.empty);",
              "};",
              "const CHANGES_PAGE = {\"type\":\"object\",\"required\":[\"items\",\"next_cursor\",\"has_more\"],\"properties\":{\"items\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"required\":[\"partner_lead_id\",\"source_revision\",\"updated_at\"],\"properties\":{\"partner_lead_id\":{\"type\":\"string\",\"pattern\":\"^[A-Za-z0-9._-]{1,64}$\"},\"source_revision\":{\"type\":\"integer\",\"minimum\":0},\"updated_at\":{\"type\":\"string\",\"format\":\"date-time\"}}}},\"next_cursor\":{\"type\":\"string\",\"minLength\":1},\"has_more\":{\"type\":\"boolean\"}}};",
              "const body = json();",
              "feedTests();",
              "pm.test('changes first page: the default page size is at least 100 when more pages follow', () => {",
              "  if (body && body.has_more === true) { pm.expect(body.items.length, 'items on the page').to.be.at.least(100); }",
              "});",
              "// A new run of the paging request starts from the oldest item.",
              "pm.collectionVariables.unset('paging_state');",
              "pm.collectionVariables.unset('paging_cursor');"
            ]
          }
        }
      ],
      "request": {
        "method": "GET",
        "header": [],
        "url": {
          "raw": "{{partner_base_url}}/v1/changes",
          "host": [
            "{{partner_base_url}}"
          ],
          "path": [
            "v1",
            "changes"
          ]
        },
        "description": "Reads the first page of GET /v1/changes with no parameters. Guide section 5.2 and 5.5. Related MarsX tests: R1 (a new lead appears in changes)."
      }
    },
    {
      "name": "4. changes: page through the whole feed (limit=500)",
      "protocolProfileBehavior": {
        "followRedirects": false,
        "followOriginalHttpMethod": false
      },
      "event": [
        {
          "listen": "prerequest",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const cursor = pm.collectionVariables.get('paging_cursor');",
              "pm.request.url.query.remove('cursor');",
              "// A cursor is opaque and may hold + / =. Postman does not encode a query value that a script adds, so it is encoded here.",
              "if (cursor) { pm.request.url.query.add({ key: 'cursor', value: encodeURIComponent(cursor) }); }"
            ]
          }
        },
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const PROBLEM = {\"type\":\"object\",\"required\":[\"type\",\"title\",\"status\"],\"properties\":{\"type\":{\"type\":\"string\"},\"title\":{\"type\":\"string\"},\"status\":{\"type\":\"integer\"},\"detail\":{\"type\":\"string\"},\"instance\":{\"type\":\"string\"},\"errors\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"required\":[\"pointer\",\"message\"],\"properties\":{\"pointer\":{\"type\":\"string\"},\"message\":{\"type\":\"string\"}}}}},\"additionalProperties\":true};",
              "const json = () => { try { return pm.response.json(); } catch (e) { return undefined; } };",
              "const contentType = () => String(pm.response.headers.get('Content-Type') || '');",
              "const isProblemJson = () => contentType().toLowerCase().indexOf('application/problem+json') >= 0;",
              "const problemTests = (status) => {",
              "  pm.test('the error answer is application/problem+json (guide section 5)', () => pm.expect(isProblemJson(), 'Content-Type was \"' + contentType() + '\"').to.be.true);",
              "  pm.test('the error answer has type, title and status ' + status + ' (ProblemDetails)', () => {",
              "    pm.response.to.have.jsonSchema(PROBLEM);",
              "    pm.expect(json().status, 'the status member').to.eql(status);",
              "  });",
              "};",
              "",
              "const CHANGES_PAGE = {\"type\":\"object\",\"required\":[\"items\",\"next_cursor\",\"has_more\"],\"properties\":{\"items\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"required\":[\"partner_lead_id\",\"source_revision\",\"updated_at\"],\"properties\":{\"partner_lead_id\":{\"type\":\"string\",\"pattern\":\"^[A-Za-z0-9._-]{1,64}$\"},\"source_revision\":{\"type\":\"integer\",\"minimum\":0},\"updated_at\":{\"type\":\"string\",\"format\":\"date-time\"}}}},\"next_cursor\":{\"type\":\"string\",\"minLength\":1},\"has_more\":{\"type\":\"boolean\"}}};",
              "const CAP = 200;",
              "const cv = pm.collectionVariables;",
              "const state = JSON.parse(cv.get('paging_state') || '{\"page\":0,\"items\":0,\"seen\":{},\"lastTime\":0}');",
              "const sent = cv.get('paging_cursor') || '';",
              "state.page += 1;",
              "const body = json();",
              "const where = ' (page ' + state.page + ')';",
              "let healthy = true;",
              "const check = (name, fn) => pm.test(name, () => { try { fn(); } catch (e) { healthy = false; throw e; } });",
              "check('paging: 200 OK', () => pm.response.to.have.status(200));",
              "check('paging: matches the ChangesPage schema', () => pm.response.to.have.jsonSchema(CHANGES_PAGE));",
              "check('paging: next_cursor is present and not empty, also on the last page', () => pm.expect(body && body.next_cursor, 'next_cursor' + where).to.be.a('string').and.not.empty);",
              "check('paging: no more than 500 items for limit=500', () => pm.expect(body.items.length, 'items' + where).to.be.at.most(500));",
              "const repeated = [];",
              "let backwards = 0;",
              "if (body && Array.isArray(body.items)) {",
              "  body.items.forEach((it) => {",
              "    const pair = it.partner_lead_id + ' revision ' + it.source_revision;",
              "    if (state.seen[pair]) { repeated.push(pair); } else { state.seen[pair] = 1; }",
              "    const t = Date.parse(it.updated_at);",
              "    if (t < state.lastTime) { backwards += 1; }",
              "    if (t > state.lastTime) { state.lastTime = t; }",
              "  });",
              "  state.items += body.items.length;",
              "}",
              "check('paging: no (partner_lead_id, source_revision) pair appears twice', () => pm.expect(repeated, 'repeated pairs' + where).to.eql([]));",
              "check('paging: oldest first, updated_at never goes backwards', () => pm.expect(backwards, 'items older than an earlier one' + where).to.eql(0));",
              "check('paging: while has_more is true the cursor moves on', () => { if (body.has_more === true) { pm.expect(body.next_cursor, 'next_cursor equals the cursor sent' + where).to.not.eql(sent); } });",
              "const more = healthy && body && body.has_more === true;",
              "if (more && state.page < CAP) {",
              "  cv.set('paging_state', JSON.stringify(state));",
              "  cv.set('paging_cursor', body.next_cursor);",
              "  (pm.execution && pm.execution.setNextRequest ? pm.execution : postman).setNextRequest(pm.info.requestName);",
              "} else {",
              "  cv.unset('paging_state');",
              "  cv.unset('paging_cursor');",
              "  pm.test('paging: reached the end of the feed (has_more false) after ' + state.page + ' page(s) and ' + state.items + ' item(s)', () => {",
              "    pm.expect(healthy, 'a check above failed, so paging stopped early').to.be.true;",
              "    pm.expect(more && state.page >= CAP, 'still has_more after ' + CAP + ' pages (safety cap)').to.be.false;",
              "    pm.expect(body.has_more, 'has_more on the last page').to.be.false;",
              "  });",
              "}"
            ]
          }
        }
      ],
      "request": {
        "method": "GET",
        "header": [],
        "url": {
          "raw": "{{partner_base_url}}/v1/changes?limit=500",
          "host": [
            "{{partner_base_url}}"
          ],
          "path": [
            "v1",
            "changes"
          ],
          "query": [
            {
              "key": "limit",
              "value": "500"
            }
          ]
        },
        "description": "Follows next_cursor with limit=500 until has_more is false. This request repeats itself (pm.execution.setNextRequest), so run the whole collection in the Collection Runner: a single Send reads one page only. It stops after 200 pages (100,000 items) as a safety cap. Checks: every page, the order, and that no (partner_lead_id, source_revision) pair appears twice. Related MarsX test: R2 (at least 1,001 changes that share one updated_at)."
      }
    },
    {
      "name": "5. changes: limit above the maximum gets 400",
      "protocolProfileBehavior": {
        "followRedirects": false,
        "followOriginalHttpMethod": false
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const PROBLEM = {\"type\":\"object\",\"required\":[\"type\",\"title\",\"status\"],\"properties\":{\"type\":{\"type\":\"string\"},\"title\":{\"type\":\"string\"},\"status\":{\"type\":\"integer\"},\"detail\":{\"type\":\"string\"},\"instance\":{\"type\":\"string\"},\"errors\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"required\":[\"pointer\",\"message\"],\"properties\":{\"pointer\":{\"type\":\"string\"},\"message\":{\"type\":\"string\"}}}}},\"additionalProperties\":true};",
              "const json = () => { try { return pm.response.json(); } catch (e) { return undefined; } };",
              "const contentType = () => String(pm.response.headers.get('Content-Type') || '');",
              "const isProblemJson = () => contentType().toLowerCase().indexOf('application/problem+json') >= 0;",
              "const problemTests = (status) => {",
              "  pm.test('the error answer is application/problem+json (guide section 5)', () => pm.expect(isProblemJson(), 'Content-Type was \"' + contentType() + '\"').to.be.true);",
              "  pm.test('the error answer has type, title and status ' + status + ' (ProblemDetails)', () => {",
              "    pm.response.to.have.jsonSchema(PROBLEM);",
              "    pm.expect(json().status, 'the status member').to.eql(status);",
              "  });",
              "};",
              "",
              "pm.test('limit 999999: 400 Bad Request, not 200 with fewer items', () => pm.response.to.have.status(400));",
              "if (pm.response.code === 400) { problemTests(400); }"
            ]
          }
        }
      ],
      "request": {
        "method": "GET",
        "header": [],
        "url": {
          "raw": "{{partner_base_url}}/v1/changes?limit=999999",
          "host": [
            "{{partner_base_url}}"
          ],
          "path": [
            "v1",
            "changes"
          ],
          "query": [
            {
              "key": "limit",
              "value": "999999"
            }
          ]
        },
        "description": "Asks for limit=999999, far above any page maximum. Expect 400 (guide section 5.2 and 5.5), not a silent cut to your maximum. Related MarsX test: R2 (MarsX asks for 500 per page)."
      }
    },
    {
      "name": "6. changes: expired cursor gets 410 cursor-expired",
      "protocolProfileBehavior": {
        "followRedirects": false,
        "followOriginalHttpMethod": false
      },
      "event": [
        {
          "listen": "prerequest",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.request.url.query.remove('cursor');",
              "pm.request.url.query.add({ key: 'cursor', value: encodeURIComponent(String(pm.variables.get('expired_changes_cursor')).trim()) });"
            ]
          }
        },
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const PROBLEM = {\"type\":\"object\",\"required\":[\"type\",\"title\",\"status\"],\"properties\":{\"type\":{\"type\":\"string\"},\"title\":{\"type\":\"string\"},\"status\":{\"type\":\"integer\"},\"detail\":{\"type\":\"string\"},\"instance\":{\"type\":\"string\"},\"errors\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"required\":[\"pointer\",\"message\"],\"properties\":{\"pointer\":{\"type\":\"string\"},\"message\":{\"type\":\"string\"}}}}},\"additionalProperties\":true};",
              "const json = () => { try { return pm.response.json(); } catch (e) { return undefined; } };",
              "const contentType = () => String(pm.response.headers.get('Content-Type') || '');",
              "const isProblemJson = () => contentType().toLowerCase().indexOf('application/problem+json') >= 0;",
              "const problemTests = (status) => {",
              "  pm.test('the error answer is application/problem+json (guide section 5)', () => pm.expect(isProblemJson(), 'Content-Type was \"' + contentType() + '\"').to.be.true);",
              "  pm.test('the error answer has type, title and status ' + status + ' (ProblemDetails)', () => {",
              "    pm.response.to.have.jsonSchema(PROBLEM);",
              "    pm.expect(json().status, 'the status member').to.eql(status);",
              "  });",
              "};",
              "",
              "const body = json();",
              "pm.test('expired cursor: 410 Gone', () => pm.response.to.have.status(410));",
              "if (pm.response.code === 410) {",
              "  problemTests(410);",
              "  pm.test('expired cursor: the problem type is urn:marsx:problem:cursor-expired', () => pm.expect(body && body.type, 'type member').to.eql('urn:marsx:problem:cursor-expired'));",
              "}"
            ]
          }
        }
      ],
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "X-Mx-Need",
            "value": "expired_changes_cursor"
          }
        ],
        "url": {
          "raw": "{{partner_base_url}}/v1/changes",
          "host": [
            "{{partner_base_url}}"
          ],
          "path": [
            "v1",
            "changes"
          ]
        },
        "description": "Sends expired_changes_cursor, the cursor you gave MarsX that always answers 410. Expect 410 with the problem type urn:marsx:problem:cursor-expired (guide section 5.5). Related MarsX test: R4."
      }
    },
    {
      "name": "7. privacy-events: first page",
      "protocolProfileBehavior": {
        "followRedirects": false,
        "followOriginalHttpMethod": false
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const PROBLEM = {\"type\":\"object\",\"required\":[\"type\",\"title\",\"status\"],\"properties\":{\"type\":{\"type\":\"string\"},\"title\":{\"type\":\"string\"},\"status\":{\"type\":\"integer\"},\"detail\":{\"type\":\"string\"},\"instance\":{\"type\":\"string\"},\"errors\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"required\":[\"pointer\",\"message\"],\"properties\":{\"pointer\":{\"type\":\"string\"},\"message\":{\"type\":\"string\"}}}}},\"additionalProperties\":true};",
              "const json = () => { try { return pm.response.json(); } catch (e) { return undefined; } };",
              "const contentType = () => String(pm.response.headers.get('Content-Type') || '');",
              "const isProblemJson = () => contentType().toLowerCase().indexOf('application/problem+json') >= 0;",
              "const problemTests = (status) => {",
              "  pm.test('the error answer is application/problem+json (guide section 5)', () => pm.expect(isProblemJson(), 'Content-Type was \"' + contentType() + '\"').to.be.true);",
              "  pm.test('the error answer has type, title and status ' + status + ' (ProblemDetails)', () => {",
              "    pm.response.to.have.jsonSchema(PROBLEM);",
              "    pm.expect(json().status, 'the status member').to.eql(status);",
              "  });",
              "};",
              "const PROFILE_KEYS = [\"partner_customer_id\",\"customer_name\",\"phone\",\"email\",\"phone_verified\",\"model_interest\",\"purchase_timeframe\",\"test_drive_requested\",\"enquiry_notes\",\"customer_province\",\"customer_city\",\"preferred_dealer_code\",\"source_channel\",\"campaign\",\"utm_source\",\"utm_medium\",\"utm_campaign\",\"ad_click_id\",\"ad_id\",\"ad_creative_id\",\"session_id\",\"contact_consent\",\"consent_time\",\"consent_reference\",\"notice_version\",\"consent_purpose\",\"ai_intent_label\",\"ai_summary\",\"customer_address\",\"customer_gps\",\"lead_score\",\"creative_label\",\"staff_notes\"];",
              "const hasProfileData = (obj) => PROFILE_KEYS.filter((k) => Object.prototype.hasOwnProperty.call(obj || {}, k));",
              "",
              "",
              "const feedTests = () => {",
              "  const body = json();",
              "  pm.test('privacy-events first page: 200 OK', () => pm.response.to.have.status(200));",
              "  pm.test('privacy-events first page: the body is JSON', () => pm.expect(contentType().toLowerCase()).to.include('application/json'));",
              "  pm.test('privacy-events first page: matches the PrivacyEventsPage schema', () => pm.response.to.have.jsonSchema(PRIVACY_PAGE));",
              "  pm.test('privacy-events first page: next_cursor is present and not empty', () => pm.expect(body && body.next_cursor, 'next_cursor').to.be.a('string').and.not.empty);",
              "};",
              "const PRIVACY_PAGE = {\"type\":\"object\",\"required\":[\"items\",\"next_cursor\",\"has_more\"],\"properties\":{\"items\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"required\":[\"partner_lead_id\",\"request_type\",\"request_time\",\"request_reference\"],\"properties\":{\"partner_lead_id\":{\"type\":\"string\",\"pattern\":\"^[A-Za-z0-9._-]{1,64}$\"},\"request_type\":{\"type\":\"string\",\"enum\":[\"withdraw_consent\",\"erasure\",\"restriction\"]},\"request_time\":{\"type\":\"string\",\"format\":\"date-time\"},\"request_reference\":{\"type\":\"string\",\"pattern\":\"^[A-Za-z0-9._-]{1,64}$\"}}}},\"next_cursor\":{\"type\":\"string\",\"minLength\":1},\"has_more\":{\"type\":\"boolean\"}}};",
              "const body = json();",
              "feedTests();",
              "const items = body && Array.isArray(body.items) ? body.items : [];",
              "pm.test('privacy-events first page: no item carries a contact or profile field (guide section 5.3)', () => {",
              "  const leaks = [];",
              "  items.forEach((it) => hasProfileData(it).forEach((k) => leaks.push(k)));",
              "  pm.expect(leaks, 'contact or profile members found in items').to.eql([]);",
              "});",
              "pm.test('privacy-events first page: no item value looks like a phone number or an email address', () => {",
              "  const hits = [];",
              "  items.forEach((it) => Object.keys(it).forEach((k) => { if (/[^\\s@]+@[^\\s@]+\\.[^\\s@]+|\\+?62[0-9]{8,}|(^|[^0-9])08[0-9]{8,}/.test(String(it[k]))) { hits.push(k); } }));",
              "  pm.expect(hits, 'members whose value looks like contact data').to.eql([]);",
              "});",
              "pm.test('privacy-events first page: the default page size is at least 100 when more pages follow', () => {",
              "  if (body && body.has_more === true) { pm.expect(items.length, 'items on the page').to.be.at.least(100); }",
              "});"
            ]
          }
        }
      ],
      "request": {
        "method": "GET",
        "header": [],
        "url": {
          "raw": "{{partner_base_url}}/v1/privacy-events",
          "host": [
            "{{partner_base_url}}"
          ],
          "path": [
            "v1",
            "privacy-events"
          ]
        },
        "description": "Reads the first page of GET /v1/privacy-events. Guide section 5.3: every withdrawal, erasure and restriction, oldest first, with no contact or profile data. Related MarsX tests: R1 and R3 (a deletion of a lead you no longer hold, an erased lead)."
      }
    },
    {
      "name": "8. privacy-events: expired cursor gets 410 cursor-expired",
      "protocolProfileBehavior": {
        "followRedirects": false,
        "followOriginalHttpMethod": false
      },
      "event": [
        {
          "listen": "prerequest",
          "script": {
            "type": "text/javascript",
            "exec": [
              "pm.request.url.query.remove('cursor');",
              "pm.request.url.query.add({ key: 'cursor', value: encodeURIComponent(String(pm.variables.get('expired_privacy_cursor')).trim()) });"
            ]
          }
        },
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const PROBLEM = {\"type\":\"object\",\"required\":[\"type\",\"title\",\"status\"],\"properties\":{\"type\":{\"type\":\"string\"},\"title\":{\"type\":\"string\"},\"status\":{\"type\":\"integer\"},\"detail\":{\"type\":\"string\"},\"instance\":{\"type\":\"string\"},\"errors\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"required\":[\"pointer\",\"message\"],\"properties\":{\"pointer\":{\"type\":\"string\"},\"message\":{\"type\":\"string\"}}}}},\"additionalProperties\":true};",
              "const json = () => { try { return pm.response.json(); } catch (e) { return undefined; } };",
              "const contentType = () => String(pm.response.headers.get('Content-Type') || '');",
              "const isProblemJson = () => contentType().toLowerCase().indexOf('application/problem+json') >= 0;",
              "const problemTests = (status) => {",
              "  pm.test('the error answer is application/problem+json (guide section 5)', () => pm.expect(isProblemJson(), 'Content-Type was \"' + contentType() + '\"').to.be.true);",
              "  pm.test('the error answer has type, title and status ' + status + ' (ProblemDetails)', () => {",
              "    pm.response.to.have.jsonSchema(PROBLEM);",
              "    pm.expect(json().status, 'the status member').to.eql(status);",
              "  });",
              "};",
              "",
              "const body = json();",
              "pm.test('expired cursor: 410 Gone', () => pm.response.to.have.status(410));",
              "if (pm.response.code === 410) {",
              "  problemTests(410);",
              "  pm.test('expired cursor: the problem type is urn:marsx:problem:cursor-expired', () => pm.expect(body && body.type, 'type member').to.eql('urn:marsx:problem:cursor-expired'));",
              "}"
            ]
          }
        }
      ],
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "X-Mx-Need",
            "value": "expired_privacy_cursor"
          }
        ],
        "url": {
          "raw": "{{partner_base_url}}/v1/privacy-events",
          "host": [
            "{{partner_base_url}}"
          ],
          "path": [
            "v1",
            "privacy-events"
          ]
        },
        "description": "Sends expired_privacy_cursor, the cursor you gave MarsX that always answers 410. Expect 410 with urn:marsx:problem:cursor-expired. MarsX then keeps the connection's leads restricted until recovery is proven (guide section 5.5). Related MarsX test: R4."
      }
    },
    {
      "name": "9. leads: a live lead",
      "protocolProfileBehavior": {
        "followRedirects": false,
        "followOriginalHttpMethod": false
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const PROBLEM = {\"type\":\"object\",\"required\":[\"type\",\"title\",\"status\"],\"properties\":{\"type\":{\"type\":\"string\"},\"title\":{\"type\":\"string\"},\"status\":{\"type\":\"integer\"},\"detail\":{\"type\":\"string\"},\"instance\":{\"type\":\"string\"},\"errors\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"required\":[\"pointer\",\"message\"],\"properties\":{\"pointer\":{\"type\":\"string\"},\"message\":{\"type\":\"string\"}}}}},\"additionalProperties\":true};",
              "const json = () => { try { return pm.response.json(); } catch (e) { return undefined; } };",
              "const contentType = () => String(pm.response.headers.get('Content-Type') || '');",
              "const isProblemJson = () => contentType().toLowerCase().indexOf('application/problem+json') >= 0;",
              "const problemTests = (status) => {",
              "  pm.test('the error answer is application/problem+json (guide section 5)', () => pm.expect(isProblemJson(), 'Content-Type was \"' + contentType() + '\"').to.be.true);",
              "  pm.test('the error answer has type, title and status ' + status + ' (ProblemDetails)', () => {",
              "    pm.response.to.have.jsonSchema(PROBLEM);",
              "    pm.expect(json().status, 'the status member').to.eql(status);",
              "  });",
              "};",
              "const LEAD = {\"new\":{\"type\":\"object\",\"required\":[\"partner_lead_id\",\"record_action\",\"created_at\",\"customer_name\",\"phone\",\"email\",\"model_interest\",\"campaign\",\"test_drive_requested\",\"enquiry_notes\",\"source_channel\",\"contact_consent\",\"consent_time\"],\"properties\":{\"partner_lead_id\":{\"type\":\"string\",\"pattern\":\"^[A-Za-z0-9._-]{1,64}$\"},\"partner_customer_id\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":128,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"source_revision\":{\"type\":\"integer\",\"minimum\":0},\"record_action\":{\"type\":\"string\",\"enum\":[\"new\",\"update\",\"withdraw\",\"delete\"],\"const\":\"new\"},\"created_at\":{\"type\":\"string\",\"format\":\"date-time\"},\"updated_at\":{\"type\":\"string\",\"format\":\"date-time\"},\"customer_name\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":200,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"phone\":{\"type\":\"string\",\"pattern\":\"^\\\\+628[0-9]+$\",\"maxLength\":16},\"email\":{\"type\":\"string\",\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\",\"anyOf\":[{\"format\":\"email\",\"maxLength\":254},{\"const\":\"not_provided\"}]},\"phone_verified\":{\"type\":[\"boolean\",\"null\"]},\"model_interest\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":120,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"purchase_timeframe\":{\"type\":\"string\",\"enum\":[\"Bulan ini\",\"1 bulan ke depan\",\"3 bulan ke depan\",\"Belum tahu\"]},\"test_drive_requested\":{\"type\":\"string\",\"enum\":[\"Y\",\"N\",\"unknown\"]},\"enquiry_notes\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":500,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"customer_province\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":120,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"customer_city\":{\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\",\"type\":\"string\",\"minLength\":1,\"maxLength\":120},\"preferred_dealer_code\":{\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\",\"type\":\"string\",\"minLength\":1,\"maxLength\":64},\"source_channel\":{\"type\":\"string\",\"enum\":[\"meta_lead_form\",\"tiktok_lead_form\",\"google_lead_form\",\"other_ad_lead_form\",\"chat\",\"website_form\",\"marketplace\",\"whatsapp\",\"instagram_dm\",\"other\"]},\"campaign\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":200,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"utm_source\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":200,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"utm_medium\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":200,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"utm_campaign\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":200,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"ad_click_id\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":255,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"ad_id\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":128,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"ad_creative_id\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":128,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"session_id\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":128,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"contact_consent\":{\"type\":\"string\",\"enum\":[\"yes\"]},\"consent_time\":{\"type\":\"string\",\"format\":\"date-time\"},\"consent_reference\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":200,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"notice_version\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":64,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"consent_purpose\":{\"type\":\"string\",\"minLength\":1},\"ai_intent_label\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":200,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"ai_summary\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":1000,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"customer_address\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":500,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"customer_gps\":{\"type\":\"string\",\"pattern\":\"^-?(90(\\\\.0+)?|[1-8]?[0-9](\\\\.[0-9]+)?), ?-?(180(\\\\.0+)?|1[0-7][0-9](\\\\.[0-9]+)?|[1-9]?[0-9](\\\\.[0-9]+)?)$\",\"maxLength\":64},\"lead_score\":{\"type\":\"integer\",\"minimum\":0,\"maximum\":100},\"creative_label\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":100,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"staff_notes\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":500,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"}},\"anyOf\":[{\"required\":[\"customer_city\"]},{\"required\":[\"preferred_dealer_code\"],\"properties\":{\"preferred_dealer_code\":{\"not\":{\"const\":\"not_specified\"}}}}],\"additionalProperties\":false},\"update\":{\"type\":\"object\",\"required\":[\"partner_lead_id\",\"record_action\",\"created_at\",\"customer_name\",\"phone\",\"email\",\"model_interest\",\"campaign\",\"test_drive_requested\",\"enquiry_notes\",\"source_channel\",\"contact_consent\",\"consent_time\",\"source_revision\",\"updated_at\"],\"properties\":{\"partner_lead_id\":{\"type\":\"string\",\"pattern\":\"^[A-Za-z0-9._-]{1,64}$\"},\"partner_customer_id\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":128,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"source_revision\":{\"type\":\"integer\",\"minimum\":0},\"record_action\":{\"type\":\"string\",\"enum\":[\"new\",\"update\",\"withdraw\",\"delete\"],\"const\":\"update\"},\"created_at\":{\"type\":\"string\",\"format\":\"date-time\"},\"updated_at\":{\"type\":\"string\",\"format\":\"date-time\"},\"customer_name\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":200,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"phone\":{\"type\":\"string\",\"pattern\":\"^\\\\+628[0-9]+$\",\"maxLength\":16},\"email\":{\"type\":\"string\",\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\",\"anyOf\":[{\"format\":\"email\",\"maxLength\":254},{\"const\":\"not_provided\"}]},\"phone_verified\":{\"type\":[\"boolean\",\"null\"]},\"model_interest\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":120,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"purchase_timeframe\":{\"type\":\"string\",\"enum\":[\"Bulan ini\",\"1 bulan ke depan\",\"3 bulan ke depan\",\"Belum tahu\"]},\"test_drive_requested\":{\"type\":\"string\",\"enum\":[\"Y\",\"N\",\"unknown\"]},\"enquiry_notes\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":500,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"customer_province\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":120,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"customer_city\":{\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\",\"type\":\"string\",\"minLength\":1,\"maxLength\":120},\"preferred_dealer_code\":{\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\",\"type\":\"string\",\"minLength\":1,\"maxLength\":64},\"source_channel\":{\"type\":\"string\",\"enum\":[\"meta_lead_form\",\"tiktok_lead_form\",\"google_lead_form\",\"other_ad_lead_form\",\"chat\",\"website_form\",\"marketplace\",\"whatsapp\",\"instagram_dm\",\"other\"]},\"campaign\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":200,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"utm_source\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":200,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"utm_medium\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":200,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"utm_campaign\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":200,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"ad_click_id\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":255,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"ad_id\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":128,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"ad_creative_id\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":128,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"session_id\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":128,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"contact_consent\":{\"type\":\"string\",\"enum\":[\"yes\"]},\"consent_time\":{\"type\":\"string\",\"format\":\"date-time\"},\"consent_reference\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":200,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"notice_version\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":64,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"consent_purpose\":{\"type\":\"string\",\"minLength\":1},\"ai_intent_label\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":200,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"ai_summary\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":1000,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"customer_address\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":500,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"customer_gps\":{\"type\":\"string\",\"pattern\":\"^-?(90(\\\\.0+)?|[1-8]?[0-9](\\\\.[0-9]+)?), ?-?(180(\\\\.0+)?|1[0-7][0-9](\\\\.[0-9]+)?|[1-9]?[0-9](\\\\.[0-9]+)?)$\",\"maxLength\":64},\"lead_score\":{\"type\":\"integer\",\"minimum\":0,\"maximum\":100},\"creative_label\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":100,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"staff_notes\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":500,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"}},\"anyOf\":[{\"required\":[\"customer_city\"]},{\"required\":[\"preferred_dealer_code\"],\"properties\":{\"preferred_dealer_code\":{\"not\":{\"const\":\"not_specified\"}}}}],\"additionalProperties\":false},\"withdraw\":{\"type\":\"object\",\"required\":[\"partner_lead_id\",\"record_action\",\"created_at\",\"source_revision\",\"updated_at\",\"request_type\",\"request_time\",\"request_reference\"],\"properties\":{\"partner_lead_id\":{\"type\":\"string\",\"pattern\":\"^[A-Za-z0-9._-]{1,64}$\"},\"partner_customer_id\":{\"type\":\"string\",\"minLength\":1},\"source_revision\":{\"type\":\"integer\",\"minimum\":0},\"record_action\":{\"type\":\"string\",\"enum\":[\"new\",\"update\",\"withdraw\",\"delete\"],\"const\":\"withdraw\"},\"created_at\":{\"type\":\"string\",\"format\":\"date-time\"},\"updated_at\":{\"type\":\"string\",\"format\":\"date-time\"},\"request_type\":{\"type\":\"string\",\"enum\":[\"withdraw_consent\",\"restriction\"]},\"request_time\":{\"type\":\"string\",\"format\":\"date-time\"},\"request_reference\":{\"type\":\"string\",\"pattern\":\"^[A-Za-z0-9._-]{1,64}$\"}},\"additionalProperties\":false},\"delete\":{\"type\":\"object\",\"required\":[\"partner_lead_id\",\"record_action\",\"created_at\",\"source_revision\",\"updated_at\",\"request_type\",\"request_time\",\"request_reference\"],\"properties\":{\"partner_lead_id\":{\"type\":\"string\",\"pattern\":\"^[A-Za-z0-9._-]{1,64}$\"},\"partner_customer_id\":{\"type\":\"string\",\"minLength\":1},\"source_revision\":{\"type\":\"integer\",\"minimum\":0},\"record_action\":{\"type\":\"string\",\"enum\":[\"new\",\"update\",\"withdraw\",\"delete\"],\"const\":\"delete\"},\"created_at\":{\"type\":\"string\",\"format\":\"date-time\"},\"updated_at\":{\"type\":\"string\",\"format\":\"date-time\"},\"request_type\":{\"type\":\"string\",\"enum\":[\"withdraw_consent\",\"erasure\",\"restriction\"],\"const\":\"erasure\"},\"request_time\":{\"type\":\"string\",\"format\":\"date-time\"},\"request_reference\":{\"type\":\"string\",\"pattern\":\"^[A-Za-z0-9._-]{1,64}$\"}},\"additionalProperties\":false}};",
              "",
              "const body = json();",
              "pm.test('live lead: 200 OK', () => pm.response.to.have.status(200));",
              "pm.test('live lead: the body is JSON', () => pm.expect(contentType().toLowerCase()).to.include('application/json'));",
              "pm.test('live lead: record_action is new or update', () => pm.expect(body && body.record_action, 'record_action').to.be.oneOf(['new', 'update']));",
              "pm.test('live lead: matches the LeadData schema for its record_action', () => {",
              "  pm.expect(LEAD[body && body.record_action], 'no LeadData variant for record_action ' + (body && body.record_action)).to.be.an('object');",
              "  pm.response.to.have.jsonSchema(LEAD[body.record_action]);",
              "});",
              "pm.test('live lead: source_revision is a whole number and updated_at is a date-time (always present, guide section 5.4)', () => {",
              "  pm.expect(Number.isInteger(body.source_revision) && body.source_revision >= 0, 'source_revision ' + body.source_revision).to.be.true;",
              "  pm.expect(String(body.updated_at || ''), 'updated_at').to.match(/^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(Z|[+-]\\d{2}:\\d{2})$/);",
              "});",
              "pm.test('live lead: partner_lead_id is the id that was asked for', () => pm.expect(body && body.partner_lead_id, 'partner_lead_id').to.eql(String(pm.variables.get('test_lead_id')).trim()));"
            ]
          }
        }
      ],
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "X-Mx-Need",
            "value": "test_lead_id"
          }
        ],
        "url": {
          "raw": "{{partner_base_url}}/v1/leads/{{test_lead_id_enc}}",
          "host": [
            "{{partner_base_url}}"
          ],
          "path": [
            "v1",
            "leads",
            "{{test_lead_id_enc}}"
          ]
        },
        "description": "Reads GET /v1/leads/{test_lead_id}. Guide section 5.4: 200 with the full current state in the LeadData shape, always with source_revision and updated_at. Related MarsX tests: R1 and R2 (MarsX fetches the full state of any lead it is missing)."
      }
    },
    {
      "name": "10. leads: a withdrawn lead gets the withdrawal form",
      "protocolProfileBehavior": {
        "followRedirects": false,
        "followOriginalHttpMethod": false
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const PROBLEM = {\"type\":\"object\",\"required\":[\"type\",\"title\",\"status\"],\"properties\":{\"type\":{\"type\":\"string\"},\"title\":{\"type\":\"string\"},\"status\":{\"type\":\"integer\"},\"detail\":{\"type\":\"string\"},\"instance\":{\"type\":\"string\"},\"errors\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"required\":[\"pointer\",\"message\"],\"properties\":{\"pointer\":{\"type\":\"string\"},\"message\":{\"type\":\"string\"}}}}},\"additionalProperties\":true};",
              "const json = () => { try { return pm.response.json(); } catch (e) { return undefined; } };",
              "const contentType = () => String(pm.response.headers.get('Content-Type') || '');",
              "const isProblemJson = () => contentType().toLowerCase().indexOf('application/problem+json') >= 0;",
              "const problemTests = (status) => {",
              "  pm.test('the error answer is application/problem+json (guide section 5)', () => pm.expect(isProblemJson(), 'Content-Type was \"' + contentType() + '\"').to.be.true);",
              "  pm.test('the error answer has type, title and status ' + status + ' (ProblemDetails)', () => {",
              "    pm.response.to.have.jsonSchema(PROBLEM);",
              "    pm.expect(json().status, 'the status member').to.eql(status);",
              "  });",
              "};",
              "const PROFILE_KEYS = [\"partner_customer_id\",\"customer_name\",\"phone\",\"email\",\"phone_verified\",\"model_interest\",\"purchase_timeframe\",\"test_drive_requested\",\"enquiry_notes\",\"customer_province\",\"customer_city\",\"preferred_dealer_code\",\"source_channel\",\"campaign\",\"utm_source\",\"utm_medium\",\"utm_campaign\",\"ad_click_id\",\"ad_id\",\"ad_creative_id\",\"session_id\",\"contact_consent\",\"consent_time\",\"consent_reference\",\"notice_version\",\"consent_purpose\",\"ai_intent_label\",\"ai_summary\",\"customer_address\",\"customer_gps\",\"lead_score\",\"creative_label\",\"staff_notes\"];",
              "const hasProfileData = (obj) => PROFILE_KEYS.filter((k) => Object.prototype.hasOwnProperty.call(obj || {}, k));",
              "const LEAD = {\"new\":{\"type\":\"object\",\"required\":[\"partner_lead_id\",\"record_action\",\"created_at\",\"customer_name\",\"phone\",\"email\",\"model_interest\",\"campaign\",\"test_drive_requested\",\"enquiry_notes\",\"source_channel\",\"contact_consent\",\"consent_time\"],\"properties\":{\"partner_lead_id\":{\"type\":\"string\",\"pattern\":\"^[A-Za-z0-9._-]{1,64}$\"},\"partner_customer_id\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":128,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"source_revision\":{\"type\":\"integer\",\"minimum\":0},\"record_action\":{\"type\":\"string\",\"enum\":[\"new\",\"update\",\"withdraw\",\"delete\"],\"const\":\"new\"},\"created_at\":{\"type\":\"string\",\"format\":\"date-time\"},\"updated_at\":{\"type\":\"string\",\"format\":\"date-time\"},\"customer_name\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":200,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"phone\":{\"type\":\"string\",\"pattern\":\"^\\\\+628[0-9]+$\",\"maxLength\":16},\"email\":{\"type\":\"string\",\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\",\"anyOf\":[{\"format\":\"email\",\"maxLength\":254},{\"const\":\"not_provided\"}]},\"phone_verified\":{\"type\":[\"boolean\",\"null\"]},\"model_interest\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":120,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"purchase_timeframe\":{\"type\":\"string\",\"enum\":[\"Bulan ini\",\"1 bulan ke depan\",\"3 bulan ke depan\",\"Belum tahu\"]},\"test_drive_requested\":{\"type\":\"string\",\"enum\":[\"Y\",\"N\",\"unknown\"]},\"enquiry_notes\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":500,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"customer_province\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":120,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"customer_city\":{\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\",\"type\":\"string\",\"minLength\":1,\"maxLength\":120},\"preferred_dealer_code\":{\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\",\"type\":\"string\",\"minLength\":1,\"maxLength\":64},\"source_channel\":{\"type\":\"string\",\"enum\":[\"meta_lead_form\",\"tiktok_lead_form\",\"google_lead_form\",\"other_ad_lead_form\",\"chat\",\"website_form\",\"marketplace\",\"whatsapp\",\"instagram_dm\",\"other\"]},\"campaign\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":200,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"utm_source\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":200,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"utm_medium\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":200,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"utm_campaign\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":200,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"ad_click_id\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":255,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"ad_id\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":128,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"ad_creative_id\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":128,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"session_id\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":128,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"contact_consent\":{\"type\":\"string\",\"enum\":[\"yes\"]},\"consent_time\":{\"type\":\"string\",\"format\":\"date-time\"},\"consent_reference\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":200,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"notice_version\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":64,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"consent_purpose\":{\"type\":\"string\",\"minLength\":1},\"ai_intent_label\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":200,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"ai_summary\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":1000,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"customer_address\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":500,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"customer_gps\":{\"type\":\"string\",\"pattern\":\"^-?(90(\\\\.0+)?|[1-8]?[0-9](\\\\.[0-9]+)?), ?-?(180(\\\\.0+)?|1[0-7][0-9](\\\\.[0-9]+)?|[1-9]?[0-9](\\\\.[0-9]+)?)$\",\"maxLength\":64},\"lead_score\":{\"type\":\"integer\",\"minimum\":0,\"maximum\":100},\"creative_label\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":100,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"staff_notes\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":500,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"}},\"anyOf\":[{\"required\":[\"customer_city\"]},{\"required\":[\"preferred_dealer_code\"],\"properties\":{\"preferred_dealer_code\":{\"not\":{\"const\":\"not_specified\"}}}}],\"additionalProperties\":false},\"update\":{\"type\":\"object\",\"required\":[\"partner_lead_id\",\"record_action\",\"created_at\",\"customer_name\",\"phone\",\"email\",\"model_interest\",\"campaign\",\"test_drive_requested\",\"enquiry_notes\",\"source_channel\",\"contact_consent\",\"consent_time\",\"source_revision\",\"updated_at\"],\"properties\":{\"partner_lead_id\":{\"type\":\"string\",\"pattern\":\"^[A-Za-z0-9._-]{1,64}$\"},\"partner_customer_id\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":128,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"source_revision\":{\"type\":\"integer\",\"minimum\":0},\"record_action\":{\"type\":\"string\",\"enum\":[\"new\",\"update\",\"withdraw\",\"delete\"],\"const\":\"update\"},\"created_at\":{\"type\":\"string\",\"format\":\"date-time\"},\"updated_at\":{\"type\":\"string\",\"format\":\"date-time\"},\"customer_name\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":200,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"phone\":{\"type\":\"string\",\"pattern\":\"^\\\\+628[0-9]+$\",\"maxLength\":16},\"email\":{\"type\":\"string\",\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\",\"anyOf\":[{\"format\":\"email\",\"maxLength\":254},{\"const\":\"not_provided\"}]},\"phone_verified\":{\"type\":[\"boolean\",\"null\"]},\"model_interest\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":120,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"purchase_timeframe\":{\"type\":\"string\",\"enum\":[\"Bulan ini\",\"1 bulan ke depan\",\"3 bulan ke depan\",\"Belum tahu\"]},\"test_drive_requested\":{\"type\":\"string\",\"enum\":[\"Y\",\"N\",\"unknown\"]},\"enquiry_notes\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":500,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"customer_province\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":120,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"customer_city\":{\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\",\"type\":\"string\",\"minLength\":1,\"maxLength\":120},\"preferred_dealer_code\":{\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\",\"type\":\"string\",\"minLength\":1,\"maxLength\":64},\"source_channel\":{\"type\":\"string\",\"enum\":[\"meta_lead_form\",\"tiktok_lead_form\",\"google_lead_form\",\"other_ad_lead_form\",\"chat\",\"website_form\",\"marketplace\",\"whatsapp\",\"instagram_dm\",\"other\"]},\"campaign\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":200,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"utm_source\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":200,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"utm_medium\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":200,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"utm_campaign\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":200,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"ad_click_id\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":255,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"ad_id\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":128,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"ad_creative_id\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":128,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"session_id\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":128,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"contact_consent\":{\"type\":\"string\",\"enum\":[\"yes\"]},\"consent_time\":{\"type\":\"string\",\"format\":\"date-time\"},\"consent_reference\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":200,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"notice_version\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":64,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"consent_purpose\":{\"type\":\"string\",\"minLength\":1},\"ai_intent_label\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":200,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"ai_summary\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":1000,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"customer_address\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":500,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"customer_gps\":{\"type\":\"string\",\"pattern\":\"^-?(90(\\\\.0+)?|[1-8]?[0-9](\\\\.[0-9]+)?), ?-?(180(\\\\.0+)?|1[0-7][0-9](\\\\.[0-9]+)?|[1-9]?[0-9](\\\\.[0-9]+)?)$\",\"maxLength\":64},\"lead_score\":{\"type\":\"integer\",\"minimum\":0,\"maximum\":100},\"creative_label\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":100,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"},\"staff_notes\":{\"type\":\"string\",\"minLength\":1,\"maxLength\":500,\"pattern\":\"^[^\\\\u0000-\\\\u0008\\\\u000B\\\\u000C\\\\u000E-\\\\u001F]*$\"}},\"anyOf\":[{\"required\":[\"customer_city\"]},{\"required\":[\"preferred_dealer_code\"],\"properties\":{\"preferred_dealer_code\":{\"not\":{\"const\":\"not_specified\"}}}}],\"additionalProperties\":false},\"withdraw\":{\"type\":\"object\",\"required\":[\"partner_lead_id\",\"record_action\",\"created_at\",\"source_revision\",\"updated_at\",\"request_type\",\"request_time\",\"request_reference\"],\"properties\":{\"partner_lead_id\":{\"type\":\"string\",\"pattern\":\"^[A-Za-z0-9._-]{1,64}$\"},\"partner_customer_id\":{\"type\":\"string\",\"minLength\":1},\"source_revision\":{\"type\":\"integer\",\"minimum\":0},\"record_action\":{\"type\":\"string\",\"enum\":[\"new\",\"update\",\"withdraw\",\"delete\"],\"const\":\"withdraw\"},\"created_at\":{\"type\":\"string\",\"format\":\"date-time\"},\"updated_at\":{\"type\":\"string\",\"format\":\"date-time\"},\"request_type\":{\"type\":\"string\",\"enum\":[\"withdraw_consent\",\"restriction\"]},\"request_time\":{\"type\":\"string\",\"format\":\"date-time\"},\"request_reference\":{\"type\":\"string\",\"pattern\":\"^[A-Za-z0-9._-]{1,64}$\"}},\"additionalProperties\":false},\"delete\":{\"type\":\"object\",\"required\":[\"partner_lead_id\",\"record_action\",\"created_at\",\"source_revision\",\"updated_at\",\"request_type\",\"request_time\",\"request_reference\"],\"properties\":{\"partner_lead_id\":{\"type\":\"string\",\"pattern\":\"^[A-Za-z0-9._-]{1,64}$\"},\"partner_customer_id\":{\"type\":\"string\",\"minLength\":1},\"source_revision\":{\"type\":\"integer\",\"minimum\":0},\"record_action\":{\"type\":\"string\",\"enum\":[\"new\",\"update\",\"withdraw\",\"delete\"],\"const\":\"delete\"},\"created_at\":{\"type\":\"string\",\"format\":\"date-time\"},\"updated_at\":{\"type\":\"string\",\"format\":\"date-time\"},\"request_type\":{\"type\":\"string\",\"enum\":[\"withdraw_consent\",\"erasure\",\"restriction\"],\"const\":\"erasure\"},\"request_time\":{\"type\":\"string\",\"format\":\"date-time\"},\"request_reference\":{\"type\":\"string\",\"pattern\":\"^[A-Za-z0-9._-]{1,64}$\"}},\"additionalProperties\":false}};",
              "",
              "const body = json();",
              "pm.test('withdrawn lead: 200 OK, not 404 (you still hold it)', () => pm.response.to.have.status(200));",
              "pm.test('withdrawn lead: record_action is withdraw (or delete for an erasure still held)', () => pm.expect(body && body.record_action, 'record_action').to.be.oneOf(['withdraw', 'delete']));",
              "pm.test('withdrawn lead: matches the withdrawal form schema (identity and privacy request fields only)', () => {",
              "  pm.expect(LEAD[body && body.record_action], 'no LeadData variant for record_action ' + (body && body.record_action)).to.be.an('object');",
              "  pm.response.to.have.jsonSchema(LEAD[body.record_action]);",
              "});",
              "pm.test('withdrawn lead: no contact or profile data', () => pm.expect(hasProfileData(body), 'contact or profile members found').to.eql([]));",
              "pm.test('withdrawn lead: source_revision and updated_at are present', () => {",
              "  pm.expect(Number.isInteger(body.source_revision), 'source_revision').to.be.true;",
              "  pm.expect(body.updated_at, 'updated_at').to.be.a('string').and.not.empty;",
              "});",
              "pm.test('withdrawn lead: partner_lead_id is the id that was asked for', () => pm.expect(body && body.partner_lead_id, 'partner_lead_id').to.eql(String(pm.variables.get('withdrawn_lead_id')).trim()));"
            ]
          }
        }
      ],
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "X-Mx-Need",
            "value": "withdrawn_lead_id"
          }
        ],
        "url": {
          "raw": "{{partner_base_url}}/v1/leads/{{withdrawn_lead_id_enc}}",
          "host": [
            "{{partner_base_url}}"
          ],
          "path": [
            "v1",
            "leads",
            "{{withdrawn_lead_id_enc}}"
          ]
        },
        "description": "Reads GET /v1/leads/{withdrawn_lead_id} for a lead you still hold that withdrew consent or asked for restriction. Expect 200 with the withdrawal form only: identity and privacy request fields, the withdrawal's own source_revision and updated_at, and no contact data (guide section 5.4 and 5.5). Related MarsX test: R1."
      }
    },
    {
      "name": "11. leads: an erased lead you no longer hold gets 404",
      "protocolProfileBehavior": {
        "followRedirects": false,
        "followOriginalHttpMethod": false
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const PROBLEM = {\"type\":\"object\",\"required\":[\"type\",\"title\",\"status\"],\"properties\":{\"type\":{\"type\":\"string\"},\"title\":{\"type\":\"string\"},\"status\":{\"type\":\"integer\"},\"detail\":{\"type\":\"string\"},\"instance\":{\"type\":\"string\"},\"errors\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"required\":[\"pointer\",\"message\"],\"properties\":{\"pointer\":{\"type\":\"string\"},\"message\":{\"type\":\"string\"}}}}},\"additionalProperties\":true};",
              "const json = () => { try { return pm.response.json(); } catch (e) { return undefined; } };",
              "const contentType = () => String(pm.response.headers.get('Content-Type') || '');",
              "const isProblemJson = () => contentType().toLowerCase().indexOf('application/problem+json') >= 0;",
              "const problemTests = (status) => {",
              "  pm.test('the error answer is application/problem+json (guide section 5)', () => pm.expect(isProblemJson(), 'Content-Type was \"' + contentType() + '\"').to.be.true);",
              "  pm.test('the error answer has type, title and status ' + status + ' (ProblemDetails)', () => {",
              "    pm.response.to.have.jsonSchema(PROBLEM);",
              "    pm.expect(json().status, 'the status member').to.eql(status);",
              "  });",
              "};",
              "",
              "pm.test('erased lead: 404 Not Found, not 200', () => pm.response.to.have.status(404));",
              "if (pm.response.code === 404) { problemTests(404); }"
            ]
          }
        }
      ],
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "X-Mx-Need",
            "value": "erased_lead_id"
          }
        ],
        "url": {
          "raw": "{{partner_base_url}}/v1/leads/{{erased_lead_id_enc}}",
          "host": [
            "{{partner_base_url}}"
          ],
          "path": [
            "v1",
            "leads",
            "{{erased_lead_id_enc}}"
          ]
        },
        "description": "Reads GET /v1/leads/{erased_lead_id}, a lead you erased and hold nothing for. Expect 404 as application/problem+json (guide section 5.4 and 5.5). Related MarsX test: R3 (privacy-events lists it and leads/{id} gives 404)."
      }
    },
    {
      "name": "12. No token gets 401",
      "protocolProfileBehavior": {
        "followRedirects": false,
        "followOriginalHttpMethod": false
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const PROBLEM = {\"type\":\"object\",\"required\":[\"type\",\"title\",\"status\"],\"properties\":{\"type\":{\"type\":\"string\"},\"title\":{\"type\":\"string\"},\"status\":{\"type\":\"integer\"},\"detail\":{\"type\":\"string\"},\"instance\":{\"type\":\"string\"},\"errors\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"required\":[\"pointer\",\"message\"],\"properties\":{\"pointer\":{\"type\":\"string\"},\"message\":{\"type\":\"string\"}}}}},\"additionalProperties\":true};",
              "const json = () => { try { return pm.response.json(); } catch (e) { return undefined; } };",
              "const contentType = () => String(pm.response.headers.get('Content-Type') || '');",
              "const isProblemJson = () => contentType().toLowerCase().indexOf('application/problem+json') >= 0;",
              "const problemTests = (status) => {",
              "  pm.test('the error answer is application/problem+json (guide section 5)', () => pm.expect(isProblemJson(), 'Content-Type was \"' + contentType() + '\"').to.be.true);",
              "  pm.test('the error answer has type, title and status ' + status + ' (ProblemDetails)', () => {",
              "    pm.response.to.have.jsonSchema(PROBLEM);",
              "    pm.expect(json().status, 'the status member').to.eql(status);",
              "  });",
              "};",
              "",
              "const body = json();",
              "pm.test('no token: 401 Unauthorized', () => pm.response.to.have.status(401));",
              "pm.test('no token: the answer carries no feed data', () => pm.expect(body && body.items, 'items').to.be.undefined);",
              "if (pm.response.code === 401) { problemTests(401); }"
            ]
          }
        }
      ],
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "X-Mx-Auth",
            "value": "none"
          }
        ],
        "url": {
          "raw": "{{partner_base_url}}/v1/changes?limit=1",
          "host": [
            "{{partner_base_url}}"
          ],
          "path": [
            "v1",
            "changes"
          ],
          "query": [
            {
              "key": "limit",
              "value": "1"
            }
          ]
        },
        "description": "Calls GET /v1/changes with no Authorization header. Expect 401 and no feed data (guide section 5.1). Never a 200 and never a redirect to a sign-in page."
      }
    },
    {
      "name": "13. Bad token gets 401",
      "protocolProfileBehavior": {
        "followRedirects": false,
        "followOriginalHttpMethod": false
      },
      "event": [
        {
          "listen": "test",
          "script": {
            "type": "text/javascript",
            "exec": [
              "const PROBLEM = {\"type\":\"object\",\"required\":[\"type\",\"title\",\"status\"],\"properties\":{\"type\":{\"type\":\"string\"},\"title\":{\"type\":\"string\"},\"status\":{\"type\":\"integer\"},\"detail\":{\"type\":\"string\"},\"instance\":{\"type\":\"string\"},\"errors\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"required\":[\"pointer\",\"message\"],\"properties\":{\"pointer\":{\"type\":\"string\"},\"message\":{\"type\":\"string\"}}}}},\"additionalProperties\":true};",
              "const json = () => { try { return pm.response.json(); } catch (e) { return undefined; } };",
              "const contentType = () => String(pm.response.headers.get('Content-Type') || '');",
              "const isProblemJson = () => contentType().toLowerCase().indexOf('application/problem+json') >= 0;",
              "const problemTests = (status) => {",
              "  pm.test('the error answer is application/problem+json (guide section 5)', () => pm.expect(isProblemJson(), 'Content-Type was \"' + contentType() + '\"').to.be.true);",
              "  pm.test('the error answer has type, title and status ' + status + ' (ProblemDetails)', () => {",
              "    pm.response.to.have.jsonSchema(PROBLEM);",
              "    pm.expect(json().status, 'the status member').to.eql(status);",
              "  });",
              "};",
              "",
              "const body = json();",
              "pm.test('bad token: 401 Unauthorized', () => pm.response.to.have.status(401));",
              "pm.test('bad token: the answer carries no feed data', () => pm.expect(body && body.items, 'items').to.be.undefined);",
              "if (pm.response.code === 401) { problemTests(401); }"
            ]
          }
        }
      ],
      "request": {
        "method": "GET",
        "header": [
          {
            "key": "X-Mx-Auth",
            "value": "bad"
          }
        ],
        "url": {
          "raw": "{{partner_base_url}}/v1/changes?limit=1",
          "host": [
            "{{partner_base_url}}"
          ],
          "path": [
            "v1",
            "changes"
          ],
          "query": [
            {
              "key": "limit",
              "value": "1"
            }
          ]
        },
        "description": "Calls GET /v1/changes with a token that was never issued. Expect 401 (guide section 5.1: a wrong token gets 401, and MarsX then asks for a new token once)."
      }
    }
  ]
}
