Vtiger integration

Hi all,

I am trying to setup a connection between GravityForms and VtigerCRM (opensource). Basically this is what i’d like to achieve: when a user sends a form on the site, it submits the data from the form to vtiger as contact/lead/organisation etc. The GravityForms api works great with the HTTP node. However, with Vtiger does not. It requires a md5 of a token+accesskey. (in php: md5(TOKENSTRING + ))

see the following url on how to authenticate with vtiger: https://community.vtiger.com/help/vtigercrm/developers/third-party-app-integration.html#login-operation

Can someone point me in the right direction?

Thanks,

Patrick

Hi @patrick, welcome to the community.

You gotta grab your access key from My Preferences on the Web UI.

After that, your gonna make a POST with the HTTP NODE to the following URL

https://{your_instance}.od{x}.vtiger.com/restapi/v1/vtiger/default/create

Under authentication select basic authentication then a form is gonna pop up asking for user and password here you are gonna provide your email and the access token you grabbed from your preferences.

In the body, you are gonna add the following fields. For the example, I’m hardcoding the values but you are gonna use expresions to reference the data coming from GravityForms. More info about expresions can be found here https://docs.n8n.io/#/node-basics?id=expressions

   {
    	"elementType":"Contacts",
    	"element": {
    		"lastname": "ricardo",
    		"assigned_user_id": "19x1",
    		"contacttype": "lead"
    	}
    }

To find your user_id you see on the body can make a GET request to https://{your_instance}.od{x}.vtiger.com/restapi/v1/vtiger/default/me and grab the id.

Those are the fields required in order to create a lead but there is more info you can add when creating a lead. To get the info about these fields you can make a GET to the following URL

https://{your_instance}.od{x}.vtiger.com/restapi/v1/vtiger/default/describe?elementType=Contacts

Let me know if that helps. Regards.

Hi Ricardo,

Thanks for your answer:) Unfortunately, those instructions are from the on demand version, not opensource. Basic auth does not work with vtiger opensource.

Thanks,

Patrick

Hey @patrick sorry for the misunderstanding. Question, do you have the access key?

Hi @RicardoE105 Yes I have access key from the my preferences screen

What about the token? The one you get doing

GET /webservice.php?operation=getchallenge&username= HTTP/1.1

Do you have it?

Yes i have one, but it expires after 2 hours or so. @RicardoE105

Hey @patrick.

Since there is currently no way of generating an MD5 hash from a function node (more details about it here How to hash by sha256). Just came up with this:

The MD5 would be done by a custom function on google sheets and then you will use it for the POST request to save the info on Vtiger.

The other important part here is the authentication will be done every time you get new info on GravityForm so that you do not have to worry about the expiration.

Let me know if that makes sense. I can help you to put everything together.

Regards.

1 Like

Hi @RicardoE105,

Wow, thanks! Google sheets, very smart haha. Can you export the configuration for me?

Again, thank you very much,

Patrick

I actually wanted to at least make it possible to use builtin node.js modules (when activated via environment variable) in the Function-Nodes. Then it would be possible to create the hash in the Function-Node like this:
https://odino.org/generating-the-md5-hash-of-a-string-in-nodejs/

Can release it with the new version later today.

Perfect @jan so cool. @patrick if you can wait til later today this would be a better approach. Your call, if you still want to use the Google Sheets approach I can help you out as well.

@RicardoE105 I’d like to test it with the Google sheets, then later use the other approach since that works probably better.

ok

1 - Create Google Sheets
2 - Go to tools -> custom script and paste the code below and save it.

function MD5 (input) {
  var rawHash = Utilities.computeDigest(Utilities.DigestAlgorithm.MD5, input);
  var txtHash = '';
  for (i = 0; i < rawHash.length; i++) {
    var hashVal = rawHash[i];
    if (hashVal < 0) {
      hashVal += 256;
    }
    if (hashVal.toString(16).length == 1) {
      txtHash += '0';
    }
    txtHash += hashVal.toString(16);
  }
  return txtHash;
}

3 - Create the fields accessKey, token,concat and md5
4 - The fields concat and md5 have the following functions

concat: =CONCATENATE(B2,":",C2) being b2 the accessKey and c2 the token
md5: =MD5(D2) being d2 the concat field.

5 - Create Google Service Account so that you can authenticate against Google Sheets API. You can do that by following this tutorial https://www.youtube.com/watch?v=KFqx8OmkqVE

After this would be just passing data among nodes.

Keep me posted. @patrick

Got released with [email protected]

Information about how it can be activated can be found here:
https://docs.n8n.io/#/configuration?id=use-built-in-modules-in-function-nodes

1 Like

Ok, after a few hours I got the google part working, however, the vtiger part not. It returns an error that says that the auth token is invalid, i’ve tried with multiple vtiger instances. no luck so far, i’ll keep trying.

hey @patrick could you make it work?

Hi @RicardoE105 nope tried everything.

is it the error adding the data to vtiger? If you can provide me with a test key or something I can use to try to help you out.

@RicardoE105
Haven’t tested if it’s adding data to vtiger.
You can test with this url http://instancemasterv7.crmtiger.com/ username and password is master
From there you can get the access key under preferences.

@patrick just did it and worked fine. Here is the configuration:

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        310
      ]
    },
    {
      "parameters": {
        "functionCode": "return [\n  {\n    json: {\n      lastname: \"espinoza\"\n    }\n  }\n]"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        460,
        310
      ]
    },
    {
      "parameters": {
        "requestMethod": "POST",
        "url": "http://instancemasterv7.crmtiger.com/webservice.php",
        "options": {
          "bodyContentType": "form-urlencoded"
        },
        "bodyParametersUi": {
          "parameter": [
            {
              "name": "accessKey",
              "value": "={{$node[\"Function1\"].data[\"accessKey\"]}}"
            },
            {
              "name": "username",
              "value": "master"
            },
            {
              "name": "operation",
              "value": "login"
            }
          ]
        }
      },
      "name": "HTTP Request1",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        970,
        310
      ]
    },
    {
      "parameters": {
        "functionCode": "const crypto = require('crypto')\nlet accessKey = '4R8R24iH3jRgftDi'\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": [
        780,
        310
      ]
    },
    {
      "parameters": {
        "requestMethod": "POST",
        "url": "http://instancemasterv7.crmtiger.com/webservice.php?operation=getchallenge&username=master",
        "options": {}
      },
      "name": "httprequest1",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        610,
        310
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "httprequest1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function1": {
      "main": [
        [
          {
            "node": "HTTP Request1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "httprequest1": {
      "main": [
        [
          {
            "node": "Function1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Just make sure you have the last version of n8n and starting the app with export NODE_FUNCTION_ALLOW_BUILTIN=crypto

2 Likes