GravityForms New entries only

Hi all,

I am trying to only output the data from a new gravity forms form submission (entry). The way which I think is handy is to first get all of entries of a specific form and filter it.

https://localhost/wp-json/gf/v2/entries?search={"field_filters": [{"key":"is_read","value":"0"},{"key": "form_id","value":"5"}]}

This basically tells gravityforms to search for all entries that have "is_read": "0" and "form_id": "5"
If I am correct, you can then add an if module, to grab the newest entries.
Something like this: You trigger the workflow, the http request will be sent ==> checks if "is_read": "0"
Yes: send data to somewhere and updates the "is_read": "0" to "is_read": "1"
No: stop

Now the thing that I am trying to do is put the data in the Set module. For example the firstname, lastname, email etc. However, when doing so I have to manually set each item (see image) This is not very reliable since when a new entry has submitted which has “is_read”: 0 and “form_id”: 5 then it does not work, since I have to add the new Item (Item 2 in my case)

I wonder if you guys can understand me :upside_down_face:

Thanks,

Patrick

Hey @patrick could you provide the complete body you are receiving from gravity form.

Hi @RicardoE105

Here’s the response I get:

[ { "5": "the message", "6": "[email protected]", "id": "173", "form_id": "5", "post_id": null, "date_created": "2019-11-14 17:37:33", "date_updated": "2019-11-14 17:37:33", "is_starred": "0", "is_read": "0", "ip": "ipaddr", "source_url": "https://xxxxx.nl/", "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36", "currency": "EUR", "payment_status": null, "payment_date": null, "payment_amount": null, "payment_method": null, "transaction_id": null, "is_fulfilled": null, "created_by": "1", "transaction_type": null, "status": "active", "1.3": "thisisthefirstname", "1.6": "thisisthelastname", "1.2": "", "1.4": "", "1.8": "" }, { "5": "themessage", "6": "[email protected]", "id": "172", "form_id": "5", "post_id": null, "date_created": "2019-11-14 17:36:33", "date_updated": "2019-11-14 17:36:33", "is_starred": "0", "is_read": "0", "ip": "ipaddr", "source_url": "https://xxxx.nl/", "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36", "currency": "EUR", "payment_status": null, "payment_date": null, "payment_amount": null, "payment_method": null, "transaction_id": null, "is_fulfilled": null, "created_by": "1", "transaction_type": null, "status": "active", "1.3": "first", "1.6": "name", "1.2": "", "1.4": "", "1.8": "" } ]

These are two entries

So if I understand well you gotta parse that array to something like the array below independently the number of values returned by the API right?

[{
     "firstname": "aaaa",
     "lastname": "asas",
     "email": '[email protected]'
},
{
     "firstname": "bbbb",
     "lastname": "bbb",
     "email": '[email protected]'
}]

@RicardoE105 yes that’s correct, so I can put these values somewhere else, for example, Vtiger or Google sheet.

Run this workflow and you will notice that the set is called for each element of the array (HTTP response data)/

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "return [\n   { json: {\n      \n    \"5\": \"the message\",\n    \"6\": \"[email protected]\",\n    \"id\": \"173\",\n    \"form_id\": \"5\",\n    \"post_id\": null,\n    \"date_created\": \"2019-11-14 17:37:33\",\n    \"date_updated\": \"2019-11-14 17:37:33\",\n    \"is_starred\": \"0\",\n    \"is_read\": \"0\",\n    \"ip\": \"ipaddr\",\n    \"source_url\": \"https://xxxxx.nl/\",\n    \"user_agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36\",\n    \"currency\": \"EUR\",\n    \"payment_status\": null,\n    \"payment_date\": null,\n    \"payment_amount\": null,\n    \"payment_method\": null,\n    \"transaction_id\": null,\n    \"is_fulfilled\": null,\n    \"created_by\": \"1\",\n    \"transaction_type\": null,\n    \"status\": \"active\",\n    \"1.3\": \"thisisthefirstname\",\n    \"1.6\": \"thisisthelastname\",\n    \"1.2\": \"\",\n    \"1.4\": \"\",\n    \"1.8\": \"\"\n  }\n  },\n  {\n    json: {\n    \n    \"5\": \"themessage\",\n    \"6\": \"[email protected]\",\n    \"id\": \"172\",\n    \"form_id\": \"5\",\n    \"post_id\": null,\n    \"date_created\": \"2019-11-14 17:36:33\",\n    \"date_updated\": \"2019-11-14 17:36:33\",\n    \"is_starred\": \"0\",\n    \"is_read\": \"0\",\n    \"ip\": \"ipaddr\",\n    \"source_url\": \"https://xxxx.nl/\",\n    \"user_agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36\",\n    \"currency\": \"EUR\",\n    \"payment_status\": null,\n    \"payment_date\": null,\n    \"payment_amount\": null,\n    \"payment_method\": null,\n    \"transaction_id\": null,\n    \"is_fulfilled\": null,\n    \"created_by\": \"1\",\n    \"transaction_type\": null,\n    \"status\": \"active\",\n    \"1.3\": \"first\",\n    \"1.6\": \"name\",\n    \"1.2\": \"\",\n    \"1.4\": \"\",\n    \"1.8\": \"\"\n  \n    }\n  }\n]"
      },
      "name": "gravityform",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "firstname",
              "value": "={{$node[\"gravityform\"].data[\"1.3\"]}}"
            },
            {
              "name": "lastname",
              "value": "={{$node[\"gravityform\"].data[\"1.6\"]}}"
            },
            {
              "name": "email",
              "value": "={{$node[\"gravityform\"].data[\"6\"]}}"
            }
          ]
        }
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        640,
        300
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "gravityform",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "gravityform": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

@RicardoE105 That works indeed, but what if there not two entries but three, or four?

@patrick it will iterate for as many entries exist. To test it you can add another object to the mockup function and you will see the set node would return 3 objects this time. Another option would be using the function item node. Check the example below.

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "return [\n   { json: {\n      \n    \"5\": \"the message\",\n    \"6\": \"[email protected]\",\n    \"id\": \"173\",\n    \"form_id\": \"5\",\n    \"post_id\": null,\n    \"date_created\": \"2019-11-14 17:37:33\",\n    \"date_updated\": \"2019-11-14 17:37:33\",\n    \"is_starred\": \"0\",\n    \"is_read\": \"0\",\n    \"ip\": \"ipaddr\",\n    \"source_url\": \"https://xxxxx.nl/\",\n    \"user_agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36\",\n    \"currency\": \"EUR\",\n    \"payment_status\": null,\n    \"payment_date\": null,\n    \"payment_amount\": null,\n    \"payment_method\": null,\n    \"transaction_id\": null,\n    \"is_fulfilled\": null,\n    \"created_by\": \"1\",\n    \"transaction_type\": null,\n    \"status\": \"active\",\n    \"1.3\": \"thisisthefirstname\",\n    \"1.6\": \"thisisthelastname\",\n    \"1.2\": \"\",\n    \"1.4\": \"\",\n    \"1.8\": \"\"\n  }\n  },\n  {\n    json: {\n    \n    \"5\": \"themessage\",\n    \"6\": \"[email protected]\",\n    \"id\": \"172\",\n    \"form_id\": \"5\",\n    \"post_id\": null,\n    \"date_created\": \"2019-11-14 17:36:33\",\n    \"date_updated\": \"2019-11-14 17:36:33\",\n    \"is_starred\": \"0\",\n    \"is_read\": \"0\",\n    \"ip\": \"ipaddr\",\n    \"source_url\": \"https://xxxx.nl/\",\n    \"user_agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36\",\n    \"currency\": \"EUR\",\n    \"payment_status\": null,\n    \"payment_date\": null,\n    \"payment_amount\": null,\n    \"payment_method\": null,\n    \"transaction_id\": null,\n    \"is_fulfilled\": null,\n    \"created_by\": \"1\",\n    \"transaction_type\": null,\n    \"status\": \"active\",\n    \"1.3\": \"first\",\n    \"1.6\": \"name\",\n    \"1.2\": \"\",\n    \"1.4\": \"\",\n    \"1.8\": \"\"\n  \n    }\n  }\n]"
      },
      "name": "gravityform",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "const data = $node.gravityform.data\nreturn {\n    firstname: data['1.3'],\n    lastname: data['1.6'],\n    email: data['6']\n}"
      },
      "name": "FunctionItem",
      "type": "n8n-nodes-base.functionItem",
      "typeVersion": 1,
      "position": [
        660,
        300
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "gravityform",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "gravityform": {
      "main": [
        [
          {
            "node": "FunctionItem",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

@RicardoE105 I’ve just created a new entry, and i can see it in the http response, but it doesn’t add it.
Am i missing something here?

Here’s the code I have

{
  "nodes": [
    {
      "parameters": {
        "authentication": "basicAuth",
        "url": "https://../wp-json/gf/v2/entries?search={\"field_filters\": [{\"key\":\"is_read\",\"value\":\"0\"},{\"key\": \"form_id\",\"value\":\"5\"}]}",
        "options": {}
      },
      "name": "get",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        460,
        270
      ],
      "credentials": {
        "httpBasicAuth": "GravityForms"
      }
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "firstname",
              "value": "={{$node[\"gravityform\"].data[\"1.3\"]}}"
            },
            {
              "name": "lastname",
              "value": "={{$node[\"gravityform\"].data[\"1.6\"]}}"
            },
            {
              "name": "email",
              "value": "={{$node[\"gravityform\"].data[\"6\"]}}"
            }
          ]
        }
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        1040,
        270
      ]
    },
    {
      "parameters": {
        "functionCode": "const data = $node.gravityform.data\nreturn {\n    firstname: data['1.3'],\n    lastname: data['1.6'],\n    email: data['6']\n}"
      },
      "name": "FunctionItem1",
      "type": "n8n-nodes-base.functionItem",
      "typeVersion": 1,
      "position": [
        870,
        270
      ]
    },
    {
      "parameters": {
        "functionCode": "return [\n   { json: {\n      \n    \"5\": \"the message\",\n    \"6\": \"[email protected]\",\n    \"id\": \"173\",\n    \"form_id\": \"5\",\n    \"post_id\": null,\n    \"date_created\": \"2019-11-14 17:37:33\",\n    \"date_updated\": \"2019-11-14 17:37:33\",\n    \"is_starred\": \"0\",\n    \"is_read\": \"0\",\n    \"ip\": \"ipaddr\",\n    \"source_url\": \"https://xxxxx.nl/\",\n    \"user_agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36\",\n    \"currency\": \"EUR\",\n    \"payment_status\": null,\n    \"payment_date\": null,\n    \"payment_amount\": null,\n    \"payment_method\": null,\n    \"transaction_id\": null,\n    \"is_fulfilled\": null,\n    \"created_by\": \"1\",\n    \"transaction_type\": null,\n    \"status\": \"active\",\n    \"1.3\": \"thisisthefirstname\",\n    \"1.6\": \"thisisthelastname\",\n    \"1.2\": \"\",\n    \"1.4\": \"\",\n    \"1.8\": \"\"\n  }\n  },\n  {\n    json: {\n    \n    \"5\": \"themessage\",\n    \"6\": \"[email protected]\",\n    \"id\": \"172\",\n    \"form_id\": \"5\",\n    \"post_id\": null,\n    \"date_created\": \"2019-11-14 17:36:33\",\n    \"date_updated\": \"2019-11-14 17:36:33\",\n    \"is_starred\": \"0\",\n    \"is_read\": \"0\",\n    \"ip\": \"ipaddr\",\n    \"source_url\": \"https://xxxx.nl/\",\n    \"user_agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36\",\n    \"currency\": \"EUR\",\n    \"payment_status\": null,\n    \"payment_date\": null,\n    \"payment_amount\": null,\n    \"payment_method\": null,\n    \"transaction_id\": null,\n    \"is_fulfilled\": null,\n    \"created_by\": \"1\",\n    \"transaction_type\": null,\n    \"status\": \"active\",\n    \"1.3\": \"first\",\n    \"1.6\": \"name\",\n    \"1.2\": \"\",\n    \"1.4\": \"\",\n    \"1.8\": \"\"\n  \n    }\n  }\n]"
      },
      "name": "gravityform",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        660,
        270
      ]
    }
  ],
  "connections": {
    "get": {
      "main": [
        [
          {
            "node": "gravityform",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "FunctionItem1": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "gravityform": {
      "main": [
        [
          {
            "node": "FunctionItem1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

@patrick gotta be like this:

{
  "nodes": [
    {
      "parameters": {
        "authentication": "basicAuth",
        "url": "https://../wp-json/gf/v2/entries?search={\"field_filters\": [{\"key\":\"is_read\",\"value\":\"0\"},{\"key\": \"form_id\",\"value\":\"5\"}]}",
        "options": {}
      },
      "name": "get",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        430,
        620
      ],
      "credentials": {
        "httpBasicAuth": "GravityForms"
      }
    },
    {
      "parameters": {
        "functionCode": "const data = $node.get.data\nreturn {\n    firstname: data['1.3'],\n    lastname: data['1.6'],\n    email: data['6']\n}"
      },
      "name": "FunctionItem1",
      "type": "n8n-nodes-base.functionItem",
      "typeVersion": 1,
      "position": [
        660,
        620
      ]
    }
  ],
  "connections": {
    "get": {
      "main": [
        [
          {
            "node": "FunctionItem1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

@patrick did it work?

@RicardoE105

Nope, getting an “Entries exist but they do not contain any JSON data.” in the FunctionItem

@patrick dont you have like a sandbox env that I can use to request data from gravity form?

Solution:

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "authentication": "basicAuth",
        "url": "{{yourdomain}}/wp-json/gf/v2/entries?search={%22field_filters%22:%20[{%22key%22:%22is_read%22,%22value%22:%220%22},{%22key%22:%20%22form_id%22,%22value%22:%225%22}]}",
        "options": {}
      },
      "name": "get",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        480,
        300
      ],
      "credentials": {
        "httpBasicAuth": "basic"
      }
    },
    {
      "parameters": {
        "functionCode": "const forms = items[0].json.entries\nconst response = []\nfor (const form of forms) {\n  response.push({\n    json: {\n      firstname: form['1.3'],\n      lastname: form['1.6'],\n      email: form['6']\n    }\n  })\n}\nreturn response"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        660,
        300
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "get",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "get": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
2 Likes

@RicardoE105 Has created a better solution.

The code below, grabs the current GravityForms entries that are unread, you can then do something with that data (in this case create a lead in Vtiger) then it updates the entries so that they are read (and thus won’t be picked up in the following workflow execution) This basically creates a new entries only for GravityForms. Also it does not matter if there are two, three or even four entries, it automatically adds the entries as it should. So you can run the workflow every few hours.

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        90,
        320
      ]
    },
    {
      "parameters": {
        "requestMethod": "POST",
        "url": "https://vtigerinstance/webservice.php",
        "options": {
          "bodyContentType": "form-urlencoded"
        },
        "bodyParametersUi": {
          "parameter": [
            {
              "name": "accessKey",
              "value": "={{$node[\"Function1\"].data[\"accessKey\"]}}"
            },
            {
              "name": "username",
              "value": "admin"
            },
            {
              "name": "operation",
              "value": "login"
            }
          ]
        }
      },
      "name": "HTTP Request1",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        540,
        100
      ]
    },
    {
      "parameters": {
        "functionCode": "const crypto = require('crypto')\nlet accessKey = 'accesskey'\nlet token = $node.httprequest1.data.result.token\nlet hash = crypto.createHash('md5').update(`${token}${accessKey}`).digest(\"hex\")\n\nreturn [\n  {\n    json: {\n      accessKey: hash,\n    }\n  }\n]\n\n\n"
      },
      "name": "Function1",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        310,
        100
      ]
    },
    {
      "parameters": {
        "requestMethod": "POST",
        "url": "https://crminstance/webservice.php?operation=getchallenge&username=admin",
        "options": {}
      },
      "name": "httprequest1",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        100,
        100
      ]
    },
    {
      "parameters": {
        "requestMethod": "POST",
        "url": "https://crminstance/webservice.php",
        "options": {
          "bodyContentType": "form-urlencoded"
        },
        "headerParametersUi": {
          "parameter": []
        },
        "bodyParametersUi": {
          "parameter": [
            {
              "name": "operation",
              "value": "create"
            },
            {
              "name": "sessionName",
              "value": "={{$node[\"Function\"].data[\"sessionName\"]}}"
            },
            {
              "name": "elementType",
              "value": "Leads"
            },
            {
              "name": "=element",
              "value": "={\n\"firstname\": \"{{$node[\"Function\"].data[\"firstname\"]}}\",\n\"lastname\": \"{{$node[\"Function\"].data[\"lastname\"]}}\",\n\"assigned_user_id\": \"19x7\",\n\"email\": \"{{$node[\"Function\"].data[\"email\"]}}\",\n\"description\": \"{{$node[\"Function\"].data[\"description\"]}}\"\n\n}"
            }
          ]
        },
        "queryParametersUi": {
          "parameter": []
        }
      },
      "name": "HTTP Request2",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1230,
        280
      ]
    },
    {
      "parameters": {
        "requestMethod": "POST",
        "url": "https://crminstance/webservice.php",
        "options": {},
        "headerParametersUi": {
          "parameter": []
        },
        "queryParametersUi": {
          "parameter": [
            {
              "name": "operation",
              "value": "logout"
            },
            {
              "name": "sessionName",
              "value": "={{$node[\"HTTP Request1\"].data[\"result\"][\"sessionName\"]}}"
            }
          ]
        }
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1920,
        430
      ]
    },
    {
      "parameters": {
        "authentication": "basicAuth",
        "url": "https://wordpressinstance/wp-json/gf/v2/entries?search={%22field_filters%22:%20[{%22key%22:%22is_read%22,%22value%22:%220%22},{%22key%22:%20%22form_id%22,%22value%22:%223%22}]}",
        "options": {}
      },
      "name": "gravityforms",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        290,
        310
      ],
      "credentials": {
        "httpBasicAuth": "basic"
      }
    },
    {
      "parameters": {
        "functionCode": "const forms = items[0].json.entries\nconst response = []\nfor (const form of forms) {\n  response.push({\n    json: {\n      firstname: form['1.3'],\n      lastname: form['1.6'],\n      email: form['6'],\n      description: form['5'],\n      id: form['id'],\n      customer: form['9']\n    }\n  })\n}\nreturn response"
      },
      "name": "output",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        480,
        310
      ]
    },
    {
      "parameters": {
        "authentication": "basicAuth",
        "requestMethod": "PUT",
        "url": "=https://wordpressinstance/wp-json/gf/v2/entries/{{$node[\"Function\"].data[\"id\"]}}",
        "options": {},
        "bodyParametersUi": {
          "parameter": [
            {
              "name": "is_read",
              "value": "1"
            },
            {
              "name": "5",
              "value": "={{$node[\"Function\"].data[\"description\"]}}"
            },
            {
              "name": "6",
              "value": "={{$node[\"Function\"].data[\"email\"]}}"
            },
            {
              "name": "=1.3",
              "value": "={{$node[\"Function\"].data[\"firstname\"]}}"
            },
            {
              "name": "1.6",
              "value": "={{$node[\"Function\"].data[\"lastname\"]}}"
            }
          ]
        }
      },
      "name": "gravityforms1",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1420,
        280
      ],
      "credentials": {
        "httpBasicAuth": "basic"
      },
      "disabled": true
    },
    {
      "parameters": {
        "mode": "passThrough",
        "output": "input2"
      },
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 1,
      "position": [
        820,
        280
      ]
    },
    {
      "parameters": {
        "functionCode": "const response = []\nfor (const item of items) {\n  item.json.description = item.json.description.replace(/\\n/g, \"\")\n  item.json.description = item.json.description.replace(/\\r/g, \"\")\n  response.push({\n    json: {\n     ...item.json,\n     sessionName: $node[\"HTTP Request1\"].data.result.sessionName\n    }\n  })\n}\nreturn response\n"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1030,
        280
      ]
    },
    {
      "parameters": {},
      "name": "Function2",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1580,
        280
      ]
    },
    {
      "parameters": {
        "mode": "wait"
      },
      "name": "Merge1",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 1,
      "position": [
        1750,
        430
      ]
    },
    {
      "parameters": {},
      "name": "NoOp",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1540,
        450
      ]
    },
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        90,
        320
      ]
    },
    {
      "parameters": {
        "requestMethod": "POST",
        "url": "https://crminstance/webservice.php",
        "options": {
          "bodyContentType": "form-urlencoded"
        },
        "bodyParametersUi": {
          "parameter": [
            {
              "name": "accessKey",
              "value": "={{$node[\"Function1\"].data[\"accessKey\"]}}"
            },
            {
              "name": "username",
              "value": "admin"
            },
            {
              "name": "operation",
              "value": "login"
            }
          ]
        }
      },
      "name": "HTTP Request1",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        540,
        100
      ]
    },
    {
      "parameters": {
        "functionCode": "const crypto = require('crypto')\nlet accessKey = 'accesskey'\nlet token = $node.httprequest1.data.result.token\nlet hash = crypto.createHash('md5').update(`${token}${accessKey}`).digest(\"hex\")\n\nreturn [\n  {\n    json: {\n      accessKey: hash,\n    }\n  }\n]\n\n\n"
      },
      "name": "Function1",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        310,
        100
      ]
    },
    {
      "parameters": {
        "requestMethod": "POST",
        "url": "https://crminstancel/webservice.php?operation=getchallenge&username=admin",
        "options": {}
      },
      "name": "httprequest1",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        100,
        100
      ]
    },
    {
      "parameters": {
        "requestMethod": "POST",
        "url": "https://crminstance/webservice.php",
        "options": {
          "bodyContentType": "form-urlencoded"
        },
        "headerParametersUi": {
          "parameter": []
        },
        "bodyParametersUi": {
          "parameter": [
            {
              "name": "operation",
              "value": "create"
            },
            {
              "name": "sessionName",
              "value": "={{$node[\"Function\"].data[\"sessionName\"]}}"
            },
            {
              "name": "elementType",
              "value": "Leads"
            },
            {
              "name": "=element",
              "value": "={\n\"firstname\": \"{{$node[\"Function\"].data[\"firstname\"]}}\",\n\"lastname\": \"{{$node[\"Function\"].data[\"lastname\"]}}\",\n\"assigned_user_id\": \"19x7\",\n\"email\": \"{{$node[\"Function\"].data[\"email\"]}}\",\n\"description\": \"{{$node[\"Function\"].data[\"description\"]}}\"\n\n}"
            }
          ]
        },
        "queryParametersUi": {
          "parameter": []
        }
      },
      "name": "HTTP Request2",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1230,
        280
      ]
    },
    {
      "parameters": {
        "requestMethod": "POST",
        "url": "https://crminstance/webservice.php",
        "options": {},
        "headerParametersUi": {
          "parameter": []
        },
        "queryParametersUi": {
          "parameter": [
            {
              "name": "operation",
              "value": "logout"
            },
            {
              "name": "sessionName",
              "value": "={{$node[\"HTTP Request1\"].data[\"result\"][\"sessionName\"]}}"
            }
          ]
        }
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1920,
        430
      ]
    },
    {
      "parameters": {
        "authentication": "basicAuth",
        "url": "https://wordpressinstance/wp-json/gf/v2/entries?search={%22field_filters%22:%20[{%22key%22:%22is_read%22,%22value%22:%220%22},{%22key%22:%20%22form_id%22,%22value%22:%223%22}]}",
        "options": {}
      },
      "name": "gravityforms",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        290,
        310
      ],
      "credentials": {
        "httpBasicAuth": "basic"
      }
    },
    {
      "parameters": {
        "functionCode": "const forms = items[0].json.entries\nconst response = []\nfor (const form of forms) {\n  response.push({\n    json: {\n      firstname: form['1.3'],\n      lastname: form['1.6'],\n      email: form['6'],\n      description: form['5'],\n      id: form['id'],\n      customer: form['9']\n    }\n  })\n}\nreturn response"
      },
      "name": "output",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        480,
        310
      ]
    },
    {
      "parameters": {
        "authentication": "basicAuth",
        "requestMethod": "PUT",
        "url": "=https://wordpressinstance/wp-json/gf/v2/entries/{{$node[\"Function\"].data[\"id\"]}}",
        "options": {},
        "bodyParametersUi": {
          "parameter": [
            {
              "name": "is_read",
              "value": "1"
            },
            {
              "name": "5",
              "value": "={{$node[\"Function\"].data[\"description\"]}}"
            },
            {
              "name": "6",
              "value": "={{$node[\"Function\"].data[\"email\"]}}"
            },
            {
              "name": "=1.3",
              "value": "={{$node[\"Function\"].data[\"firstname\"]}}"
            },
            {
              "name": "1.6",
              "value": "={{$node[\"Function\"].data[\"lastname\"]}}"
            }
          ]
        }
      },
      "name": "gravityforms1",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1420,
        280
      ],
      "credentials": {
        "httpBasicAuth": "basic"
      },
      "disabled": true
    },
    {
      "parameters": {
        "mode": "passThrough",
        "output": "input2"
      },
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 1,
      "position": [
        820,
        280
      ]
    },
    {
      "parameters": {
        "functionCode": "const response = []\nfor (const item of items) {\n  item.json.description = item.json.description.replace(/\\n/g, \"\")\n  item.json.description = item.json.description.replace(/\\r/g, \"\")\n  response.push({\n    json: {\n     ...item.json,\n     sessionName: $node[\"HTTP Request1\"].data.result.sessionName\n    }\n  })\n}\nreturn response\n"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1030,
        280
      ]
    },
    {
      "parameters": {},
      "name": "Function2",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1580,
        280
      ]
    },
    {
      "parameters": {
        "mode": "wait"
      },
      "name": "Merge1",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 1,
      "position": [
        1750,
        430
      ]
    },
    {
      "parameters": {},
      "name": "NoOp",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1540,
        450
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "gravityforms",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request1": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function1": {
      "main": [
        [
          {
            "node": "HTTP Request1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "httprequest1": {
      "main": [
        [
          {
            "node": "Function1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request2": {
      "main": [
        [
          {
            "node": "gravityforms1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "gravityforms": {
      "main": [
        [
          {
            "node": "output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "output": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "gravityforms1": {
      "main": [
        [
          {
            "node": "Function2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "HTTP Request2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function2": {
      "main": [
        [
          {
            "node": "Merge1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge1": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "NoOp": {
      "main": [
        [
          {
            "node": "Merge1",
            "type": "main",
            "index": 1
          }
        ]
      ]
    }
  }
}
1 Like