Announcement

Collapse
No announcement yet.

API to integrate EspoCRM with other tools

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • API to integrate EspoCRM with other tools

    Hello

    do you have any open API if we want to integrate external tools with espoCRM ?

    Ex : can we create a Contact / Lead through a SOA Request or a REST service invokation ?
    Thanks!

    Regards

    Edit: i found that :
    http://forum.espocrm.com/general/298...xisting-system
    and this one :
    http://forum.espocrm.com/developer-h...-lead-true-api

    I'd like to have a google form to gather information and then, create a contact

    Thanks
    Last edited by wtconseil; 05-04-2015, 10:12 PM.

  • #2
    I created a google form to make a POC :
    with 3 fields : lastname, firstname, email

    When invokation the REST API like that :

    var firstname = res[0].getResponse();
    var lastname = res[1].getResponse();
    var email = res[2].getResponse();

    var payload = {"firstName": firstname,"lastName":lastname,"accountType":"test" , "emailAddressData":[{"emailAddress":email, "primary":true,"optOut":false,"invalid":false}]}
    var headers = {
    'contentType': 'application/json',
    'Authorization': "Basic ..",
    'Espo-Authorization': ".."

    };

    var options =
    {
    "method" : "post",
    "payload": payload,
    "headers": headers
    };
    var result = JSON.parse(UrlFetchApp.fetch('MYENDPOINT:8080/api/v1/Contact', options).getContentText());
    Logger.log(result);
    }


    I got this exception on EspoCRM logs :
    [2015-05-04 22:09:21] Espo.WARNING: E_WARNING: Invalid argument supplied for foreach() {"file":"/usr/share/nginx/html/espo/application/Espo/Services/Record.php","line":398} []
    [2015-05-04 22:09:21] Espo.ERROR: E_RECOVERABLE_ERROR: Argument 2 passed to Espo\Services\Record::beforeCreate() must be of the type array, string given, called in /usr/share/nginx/html/espo/application/Espo/Services/Record.php on line 428 and defined {"file":"/usr/share/nginx/html/espo/application/Espo/Services/Record.php","line":497} []
    [2015-05-04 22:09:21] Espo.ERROR: API [POST]:/:controller, Params:Array
    (
    [controller] => Contact
    )
    , InputData: lastName=b&emailAddressData=%5BLjava.lang.Object;@ 4f40d5be&accountType=test&firstName=a - {"reason":"Duplicate","data":{"5547e9dc0d0e0d2cb": ""}} [] []
    [2015-05-04 22:09:21] Espo.ERROR: Display Error: {"reason":"Duplicate","data":{"5547e9dc0d0e0d2cb": ""}}, Code: 409 URL: /api/v1/Contact [] []



    Which params should be an array ?
    Could you help me to debug my REST invokation ?

    Thanks !

    Comment


    • #3
      Try to add parameter
      "forceDuplicate": true
      to payload.

      It could be caused by duplicate record.

      Comment


      • #4
        Same issue
        with this payload
        PHP Code:
        var payload = {"assignedUserId":"552e6a3873d6db22f","assignedUserName":xxx,"firstName"firstname,"lastName":lastname,"accountType":"test","salutationName":"Dr.","emailAddressData":[{"emailAddress":lastname+Math.floor(Math.random()*10E7)+"@gmail.com","primary":true,"optOut":false,"invalid":false}],"emailAddress":lastname+Math.floor(Math.random()*10E7)+"@gmail.com","addressPostalCode":"","addressStreet":"a","addressState":"","addressCity":"b","addressCountry":"France","description":"c","champSeb":"d","testAnneSo":"d","phoneNumberData":[],"phoneNumber":null,"testList":"A","teamsIds":[],"teamsNames":{}, "forceDuplicate"true 
        here is my log from Espo

        PHP Code:
        [2015-05-05 13:07:17Espo.WARNINGE_WARNINGInvalid argument supplied for foreach() {"file":"/usr/share/nginx/html/espo/application/Espo/Services/Record.php","line":398} []
        [
        2015-05-05 13:07:17Espo.ERRORE_RECOVERABLE_ERRORArgument 2 passed to Espo\Services\Record::beforeCreate() must be of the type array, string givencalled in /usr/share/nginx/html/espo/application/Espo/Services/Record.php on line 428 and defined {"file":"/usr/share/nginx/html/espo/application/Espo/Services/Record.php","line":497} []
        [
        2015-05-05 13:07:17Espo.ERRORAPI [POST]:/:controllerParams:Array
        (
            [
        controller] => Contact
        )
        InputDataaddressState&lastName=b&testAnneSo=d&emailAddressData=%5BLjava.lang.Object;@30ea1f8f&champSeb=d&addressCity=b&salutationName=Dr.&assignedUserId=552e6a3873d6db22f&emailAddress=b17044066@gmail.com&testList=A&assignedUserName=Anne&addressStreet=a&teamsIds=%5BLjava.lang.Object;@5abdfe5f&teamsNames=%7B%7D&phoneNumber&forceDuplicate=true&description=c&accountType=test&addressPostalCode&phoneNumberData=%5BLjava.lang.Object;@6f873d83&firstName=a&addressCountry=France - {"reason":"Duplicate","data":{"5547e9dc0d0e0d2cb":""}} [] []
        [
        2015-05-05 13:07:17Espo.ERRORDisplay Error: {"reason":"Duplicate","data":{"5547e9dc0d0e0d2cb":""}}, Code409 URL: /api/v1/Contact [] [] 
        Last edited by wtconseil; 05-05-2015, 02:38 PM.

        Comment


        • #5
          Grrrr, it's working with my Chrome Extension REST CLIENT but not from Google APP form ...
          I don't know which header / payload they send.
          Is it possible to add some debug on EspoCRM ?

          I was doing some tcpdump directly on my vm but it's a little bit heavy.
          I'd like to check directly what is seen from EspoCrm

          Thanks for your help

          Comment


          • #6
            Finally, it's working.
            I had to add :

            payload = Utilities.jsonStringify(payload);

            to force Google App script to encode the variable.

            Thanks for helping me

            Comment

            Working...
            X