We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3722
    • 171 Posts
    I have a client using LACRM (Less Annoying Customer Relationship Manager)
    http://www.lessannoyingcrm.com/

    They have some PHP code for creating a new client.
    I have no idea how to add to my contact form.
    I have the UserCode and APIToken, that is not the issue.

    Any ideas?
    Thanks
    BG66

    <?php
    /************************************************************************************
        This file demonstrates how to use the Less Annoying CRM API to create a new contact
        in your CRM.
         
        If you have any questions, feel free to email [email protected] for help
    **************************************************************************************/
     
    //Get your user UserCode and API token from https://www.lessannoyingcrm.com/account/api/
    $UserCode = "ABCDE";
    $APIToken = "111111111111111111111111111111111111111111111111";
    $EndpointURL = "https://api.lessannoyingcrm.com";
     
    $Function = "CreateContact";
     
    /*
    Notes:
    The only required field is a contact or company name. If you enter a company name
    but not a contact name, we will only create a company and all the other info (phone,
    email, etc.) will be stored with the company. If you enter both a contact AND a company
    name, we'll create both records and all the other info will be stored with the contact.
    */
     
    /*
    When entering a contact, you can either enter a FullName, or five separate fields
    (Salutation, FirstName, MiddleName, LastName, Suffix). If you enter the separate
    names, you are required to have at least a first or a last name (everything else
    is optional). Here are the different formats:
    */
    $FullName = "Tyler King";
    //OR
    $Salutation = "Mr.";
    $FirstName = "Tyler";
    $MiddleName = "";
    $LastName = "King";
    $Suffix = "Jr.";
    //since we can only use one of the name formats, I'm only going to pass a the full name
    //to the API call.
     
    /*
    To enter a new company, enter a company name that doesn't currently exist. If the
    company already exists, you can either enter the company name, or the CompanyId if
    you know that
    */
    $CompanyName = "Less Annoying CRM";
    //OR
    $CompanyId = 1111111;
     
    $Title = "Co-founder / CEO"; //This is only used if you're creating a company
    $Industry = "Software"; //This is only used if you're creating a company by itself
    $NumEmployees = "1-10"; //This is only used if you're creating a company by itself
     
    $BackgroundInfo = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
     
    /* 
    Many of the fields can have an arbitrary number of records per contact (like more than one email
    for a single contact. Here are examples of the formats you should use for those fields
    */
    $Email = array(
        0=>array(
            "Text"=>"[email protected]",
            "Type"=>"Work"
        ),
        1=>array(
            "Text"=>"[email protected]",
            "Type"=>"Other"
        )
    );
     
    $Phone = array(
        0=>array(
            "Text"=>"(415) 935-0105", //You can format phone numbers however you want
            "Type"=>"Work"
        ),
        1=>array(
            "Text"=>"(415)763-7329",
            "Type"=>"Other"
        )
    );
     
    $Address = array(
        0=>array(
            "Street"=>"123 Main St. \n Apt #321", //Use the newline character for a second address line
            "City"=>"St. Louis",
            "State"=>"MO",
            "Zip"=>"63130",
            "Country"=>"U.S.",
            "Type"=>"Shipping"
        )
    );
     
    $Website = array(
        0=>array("Text"=>"www.lessannoyingcrm.com")
    );
     
    //The birthday can be in any format, but you shouldn't use dd/mm/yyyy (or dd-mm-yyyy)
    //because it might be confused with the American format (mm/dd/yyyy). Instead, try
    //something like yyyy-mm-dd or "October 15th, 1973"
    $Birthday = "1/1/1982";
     
    /*
    Custom fields should be entered as one array where the key is the field name and
    the value is the value of the field.
    */
    $CustomFields = array(
        "Customer Reference #"=>"123456789",
        "Favorite Color"=>"Green",
    );
     
    //Note: you can assign contacts to other users by also passing an "AssignedTo" parameter
    //For example: "AssignedTo"=>111111 (where 111111 is the user's Id)
     
    //Now lets put all of those parameters into one array so we can call the API easily
    $Parameters = array(
        "FullName"=>$FullName, //You can use the individual name parts instead
        "CompanyName"=>$CompanyName,
        "Email"=>$Email,
        "Phone"=>$Phone,
        "Title"=>$Title,
        "Address"=>$Address,
        "Website"=>$Website,
        "Birthday"=>$Birthday,
        "CustomFields"=>$CustomFields
    );
     
     
    //The CallAPI function is at the bottom of this file
    CallAPI($EndpointURL, $UserCode, $APIToken, $Function, $Parameters);
     
    /*
    The API doesn't look at the type of request (POST, GET, etc) so you can use whatever
    you want. Here is a really ugly way to handle this in PHP:
    */
    function CallAPI($EndpointURL, $UserCode, $APIToken, $Function, $Parameters){
        $APIResult = file_get_contents("$EndpointURL?UserCode=$UserCode&APIToken=$APIToken&".
                    "Function=$Function&Parameters=".urlencode(json_encode($Parameters)));
        $APIResult = json_decode($APIResult, true);
         
        if(@$APIResult['Success'] === true){
            echo "Success!";
        }
        else{
            echo "API call failed. Error:".@$APIResult['Error'];
            exit;
        }
        return $APIResult;
    }
     
    ?>

      • 3749
      • 24,544 Posts
      I think it might work as a custom hook for FormIt: http://rtfm.modx.com/display/ADDON/FormIt.Hooks
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 3722
        • 171 Posts
        Quote from: BobRay at Jan 23, 2013, 05:05 PM
        I think it might work as a custom hook for FormIt: http://rtfm.modx.com/display/ADDON/FormIt.Hooks
        Thanks Bob, will take a look.
        BG66
          • 3722
          • 171 Posts
          Thanks Bob Ray, Got it working.

          I am using on an older Evo site with eForm.
          Used the redirect page with the Thank You parameter
          &thankyou=`##`


          On the Thank You page I entered the snippet code
          [[lacrm_form]]

          Where "lacrm_form" is the code posted earlier.

          Thanks
          BG66
            • 3749
            • 24,544 Posts
            I'm glad you got it sorted. Thanks for reporting back. smiley
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting