phpapiinfusionsoft

Infusionsoft: Is it possible to add a new contact through an API call?


I have 2 CRMs - one is built on Infusionsoft and the other is custom.

I want to synchronize contacts between these 2 CRMS. It is just unidirectional from the custom one to the Infusionsoft one. So when a customer registers at the custom CRM, I want to add his/her info to the Infusionsoft CRM without having the customer realize it =)

Infusionsoft API uses oAuth2 authentication, and this theoretically means "I have to ask the user to enter my username and password for Infusionsoft to get them added to my Infusionsoft CRM" - as far as I understand their API, which is ridiculous.

I do believe what I am trying to do is NOT impossible..... Maybe I am wrong. In worst case, I could use PhantomJS to pass the oAuth authentication. I don't want to use PhantomJS if any other solution exists. I need help from an expert in Infusionsoft. Please advise. Is it possible?


Solution

  • Each Infusionsoft account has an API key that allows you to make calls to the API.

    Here are the directions to get the API key for your Infusionsoft application. http://ug.infusionsoft.com/article/AA-00442/0/Infusionsoft-API-Key.html

    Once you have the key you can use the PHP SKD to make calls and add contacts. Here is a link to the infusionosft php SDK: https://github.com/infusionsoft/infusionsoft-php

    Here is a link to the documentation to add a contact along with a php example: https://developer.infusionsoft.com/docs/xml-rpc/#contact

    https://github.com/infusionsoft/API-Sample-Code/blob/master/PHP/ContactService-Sample.php

    Edit It looks like they are eventually sunsetting account-level keys in the future which did not require you use to oauth. https://developer.infusionsoft.com/2014/07/03/simplifying-infusionsoft-authentication-with-oauth2/

    There are plenty of examples on how to use oauth with Infusionsoft here: https://developer.infusionsoft.com/docs/xml-rpc/#contact

    Click PHP on the right hand side and you will see how to get a token and create a contact with the API

    There are even more examples on the README in github:

    https://github.com/infusionsoft/infusionsoft-php/blob/master/README.md

    Authentication:

    $infusionsoft = new \Infusionsoft\Infusionsoft(array(
        'clientId'     => 'XXXXXXXXXXXXXXXXXXXXXXXX',
        'clientSecret' => 'XXXXXXXXXX',
        'redirectUri'  => 'http://example.com/',
    ));
    
    // If the serialized token is available in the session storage, we tell the SDK
    // to use that token for subsequent requests.
    if (isset($_SESSION['token'])) {
        $infusionsoft->setToken(unserialize($_SESSION['token']));
    }
    
    // If we are returning from Infusionsoft we need to exchange the code for an
    // access token.
    if (isset($_GET['code']) and !$infusionsoft->getToken()) {
        $infusionsoft->requestAccessToken($_GET['code']);
    }
    
    if ($infusionsoft->getToken()) {
        // Save the serialized token to the current session for subsequent requests
        $_SESSION['token'] = serialize($infusionsoft->getToken());
    
        // MAKE INFUSIONSOFT REQUEST
    } else {
        echo '<a href="' . $infusionsoft->getAuthorizationUrl() . '">Click here to authorize</a>';
    }