{
  "info": {
    "name": "b2g Zoho re-push",
    "description": "Re-push a company to Zoho CRM using a payload copied from zohoapimain_tbl.\n\nHOW TO USE\n1. Run request \"1. Check connection\" first. It must return \"status\": true. If it returns 401, the token has expired - ask a developer for a new one.\n2. In the database, run the query in the \"2. Re-push one company\" description to get the payload for the row you want to retry.\n3. Open \"2. Re-push one company\", paste the payload into the Body tab, and press Send.\n4. Read the response: \"status\": 1 means it worked. Anything else - see the TROUBLESHOOTING notes on that request.\n\nThe Authorization header is already set for the whole collection, so you never need to add it yourself.",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "auth": {
    "type": "bearer",
    "bearer": [
      {
        "key": "token",
        "value": "{{authToken}}",
        "type": "string"
      }
    ]
  },
  "variable": [
    {
      "key": "baseUrl",
      "value": "http://172.16.16.23:86/b2g/b2g_zohoapi/web",
      "type": "string",
      "description": "The b2g_zohoapi server. Do NOT copy the url out of zohoapimain_tbl - some rows recorded 'localhost:86', which only works on the server itself."
    },
    {
      "key": "authToken",
      "value": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJiMmctYXBpIiwiaWF0IjoxNzg4MzM1NTAyLCJleHAiOjE4MTk4NzE1MDIsInVpZCI6MSwiY29tcGFueVBrIjpudWxsLCJyZWdQayI6bnVsbCwidXNlclR5cGUiOiJBIn0.M3hp5sZOIWxjY9THcMzjDEQgY6zpeJOOYmbHbHgTHdU",
      "type": "string",
      "description": "Valid until 2027-09-02. Treat it like a password - it can create and change CRM records. To replace it: php yii zohosync/token 0 1 365"
    }
  ],
  "item": [
    {
      "name": "1. Check connection (run this first)",
      "request": {
        "method": "GET",
        "header": [],
        "url": {
          "raw": "{{baseUrl}}/apizoho/status",
          "host": ["{{baseUrl}}"],
          "path": ["apizoho", "status"]
        },
        "description": "Confirms the server is up and the token is valid. Costs nothing and changes nothing.\n\nEXPECTED: \"status\": true and \"zohoConfigured\": true.\n\nIF YOU GET 401 Unauthorized - the token has expired or is wrong. Ask a developer to run:  php yii zohosync/token 0 1 365\nIF YOU GET \"zohoConfigured\": false - the server's Zoho credentials need attention; a developer must fix that before any re-push will work."
      }
    },
    {
      "name": "2. Re-push one company",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "PASTE THE PAYLOAD HERE - replace this whole line, including this text.",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/apizoho/supplier/create",
          "host": ["{{baseUrl}}"],
          "path": ["apizoho", "supplier", "create"]
        },
        "description": "STEP 1 - find the rows that need retrying:\n\nSELECT zohoapimain_pk AS row_id,\n       zam_createdby   AS company_pk,\n       zam_createdon   AS attempted_on,\n       CASE zam_status WHEN 1 THEN 'success' WHEN 2 THEN 'FAILED' ELSE 'unknown' END AS result\nFROM zohoapimain_tbl\nWHERE zam_status <> 1 OR zam_api_res IS NULL OR zam_api_res = 'null'\nORDER BY zohoapimain_pk DESC;\n\nSTEP 2 - get the body for the row you picked (put its row_id in place of 68):\n\nSELECT JSON_EXTRACT(zam_data, '$.payload') AS postman_body\nFROM zohoapimain_tbl\nWHERE zohoapimain_pk = 68;\n\nSTEP 3 - copy that one cell, paste it into the Body tab here (replacing everything), and press Send.\n\nIMPORTANT: copy only the payload column from the query above. Do NOT paste the whole zam_data value - that one starts with {\"method\": ... and will be rejected.\n\nREADING THE RESPONSE\n\"status\": 1  -> worked. \"existing\": true means an existing CRM record was updated; false means a new one was created.\n\"status\": 0  -> did not work. Look at \"error\".\n\nTROUBLESHOOTING\n401 Unauthorized -> token expired. Run request 1 to confirm, then ask a developer for a new token.\n\"account.companyName is required\" -> the pasted body is wrong or incomplete. Re-copy it from STEP 2.\n\"portalError\" is filled but \"status\" is 1 -> the company synced, but its Portal Registration record did not. Report the portalError text to a developer.\n\"matchedBy\": \"crNumber\" on a JSRS/NIBE company -> it matched on a weak key. Tell a developer before trusting the result.\nNothing happens / times out -> the server may be busy. Wait a minute and press Send once more. Do not press Send repeatedly; each press is a real write."
      }
    }
  ]
}
