{
  "name": "Delivery :: NewCust :: AddContacts",
  "nodes": [
    {
      "parameters": {
        "inputSource": "passthrough"
      },
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "typeVersion": 1.1,
      "position": [
        -800,
        -128
      ],
      "id": "ae7fd953-4ed4-4f89-8d97-445729036ab8",
      "name": "When Executed by Another Workflow"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "30d455b7-a49d-4c97-bd98-ff057159558b",
              "name": "customer_name",
              "value": "={{ $json.subject.split(':')[2].trim() }}",
              "type": "string"
            },
            {
              "id": "3e8a7f07-e611-4305-a2bb-ce3ca9d4f6cf",
              "name": "customer_phone",
              "value": "={{ $json.subject.split(':')[1].trim() }}",
              "type": "string"
            },
            {
              "id": "b1ff4785-d09b-4fe6-b9cd-0d65bd3175a5",
              "name": "customer_id",
              "value": "={{ $json.subject.split(':')[0].trim() }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -592,
        -128
      ],
      "id": "3eda8aab-4929-4685-abee-98b38a812e14",
      "name": "Edit Fields"
    },
    {
      "parameters": {
        "content": "## v2 - No Code Nodes\n**Google Token fetched via HTTP Request**\n**Credentials hardcoded - rotate after testing**\n",
        "height": 200
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -736,
        -400
      ],
      "typeVersion": 1,
      "id": "073cbb07-af05-4a43-9f4b-4ae8e7dfe371",
      "name": "Sticky Note"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://live-mt-server.wati.io/5171/api/v1/addContact/91{{ $json.customer_phone.trim() }}",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "sourceType",
              "value": "Wati"
            }
          ]
        },
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "accept",
              "value": "*/*"
            },
            {
              "name": "Authorization",
              "value": "<redacted-credential>"
            },
            {
              "name": "Content-Type",
              "value": "application/json-patch+json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"name\": \"{{ $json.customer_id.trim() }} {{ $json.customer_name.trim() }} \",\n  \"customParams\": [\n    {\n      \"name\": \"customer_id\",\n      \"value\": \"{{ $json.customer_id.trim() }}\"\n    },\n    {\n      \"name\": \"customer_name\",\n      \"value\": \"{{ $json.customer_name.trim() }}\"\n    }\n  ]\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -384,
        -128
      ],
      "id": "132a27ce-f91e-42c3-ab70-d4d2b253675c",
      "name": "WATI Contacts",
      "retryOnFail": false
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://oauth2.googleapis.com/token",
        "sendBody": true,
        "contentType": "form-urlencoded",
        "bodyParameters": {
          "parameters": [
            {
              "name": "client_id",
              "value": "215567513459-08jqmp12j7iht6rsen1df722igej75ph.apps.googleusercontent.com"
            },
            {
              "name": "client_secret",
              "value": "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"
            },
            {
              "name": "refresh_token",
              "value": "1//04WHmPSLcI-jXCgYIARAAGAQSNwF-L9IrtnlPIaXEeEfKWgJ3W-VvG8zJdqzamhjWiJp3OtZ8YfJIA-XGhbHb4akitpKFohrAHqY"
            },
            {
              "name": "grant_type",
              "value": "refresh_token"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -160,
        -256
      ],
      "id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
      "name": "Get Google Token"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://people.googleapis.com/v1/people:createContact",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $json.access_token }}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"names\": [{\n    \"givenName\": \"{{ $('Edit Fields').item.json.customer_id }}\",\n    \"familyName\": \"{{ $('Edit Fields').item.json.customer_name }}\"\n  }],\n  \"phoneNumbers\": [{\n    \"value\": \"91{{ $('Edit Fields').item.json.customer_phone.trim() }}\",\n    \"type\": \"mobile\"\n  }],\n  \"emailAddresses\": [{\n    \"value\": \"aruvadaiorganic@gmail.com\",\n    \"type\": \"home\"\n  }]\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        80,
        -256
      ],
      "id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
      "name": "Create Google Contact",
      "retryOnFail": false,
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "amount": 1,
        "unit": "days"
      },
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        320,
        -320
      ],
      "id": "86dd719c-abf8-4495-b8d4-888a1e5ae8b1",
      "name": "Wait"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://oauth2.googleapis.com/token",
        "sendBody": true,
        "contentType": "form-urlencoded",
        "bodyParameters": {
          "parameters": [
            {
              "name": "client_id",
              "value": "215567513459-08jqmp12j7iht6rsen1df722igej75ph.apps.googleusercontent.com"
            },
            {
              "name": "client_secret",
              "value": "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"
            },
            {
              "name": "refresh_token",
              "value": "1//04WHmPSLcI-jXCgYIARAAGAQSNwF-L9IrtnlPIaXEeEfKWgJ3W-VvG8zJdqzamhjWiJp3OtZ8YfJIA-XGhbHb4akitpKFohrAHqY"
            },
            {
              "name": "grant_type",
              "value": "refresh_token"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        560,
        -336
      ],
      "id": "c3d4e5f6-a7b8-9012-cdef-123456789012",
      "name": "Get Google Token1"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://people.googleapis.com/v1/people:createContact",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $json.access_token }}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"names\": [{\n    \"givenName\": \"{{ $('Edit Fields').item.json.customer_id }}\",\n    \"familyName\": \"{{ $('Edit Fields').item.json.customer_name }}\"\n  }],\n  \"phoneNumbers\": [{\n    \"value\": \"91{{ $('Edit Fields').item.json.customer_phone.trim() }}\",\n    \"type\": \"mobile\"\n  }],\n  \"emailAddresses\": [{\n    \"value\": \"aruvadaiorganic@gmail.com\",\n    \"type\": \"home\"\n  }]\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        800,
        -336
      ],
      "id": "d4e5f6a7-b8c9-0123-defa-234567890123",
      "name": "Create Google Contact1"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://whatsapp-api.aruvadaiorganic.com/api/v1/send",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "<redacted-credential>"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "to",
              "value": "120363404238669120@g.us"
            },
            {
              "name": "message",
              "value": "N8N Google Contacts Error"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        80,
        -128
      ],
      "id": "82e6c11c-77b8-42b5-b1b7-c49cdaff1833",
      "name": "SEND TO IMPORTANT ALERT"
    }
  ],
  "connections": {
    "When Executed by Another Workflow": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "WATI Contacts",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "WATI Contacts": {
      "main": [
        [
          {
            "node": "Get Google Token",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Google Token": {
      "main": [
        [
          {
            "node": "Create Google Contact",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Google Contact": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "SEND TO IMPORTANT ALERT",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait": {
      "main": [
        [
          {
            "node": "Get Google Token1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Google Token1": {
      "main": [
        [
          {
            "node": "Create Google Contact1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate",
    "callerPolicy": "workflowsFromSameOwner",
    "errorWorkflow": "ddO7dDvDhlbewEs1",
    "saveDataSuccessExecution": "all"
  },
  "versionId": "f9cbf844-c561-46a7-8531-f5c07ea79bdf",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "cPALVyXxZde8E7yS",
  "tags": []
}