How I can get account id and clientFolderId in icontact API

2.8k Views Asked by At

My question is specific for iContact API. I have register an application and get API id. But I am not able to find accountId and clientFolderId.

Please see this below link :

http://developer.icontact.com/documentation/request-your-accountid-and-clientfolderid/ At above page "Perform a GET on the Accounts resource" How I can perform this to get account id and clientfolderid.

4

There are 4 best solutions below

1
On

The only way to work with the iContact API, is to send correct headers to the server, then you will be able to make any of the requests and actions that appear in the documentation.

The best way that I found to do this is by setting up a PHP script with cUrl

     $url = "https://app.sandbox.icontact.com/icp/a/";
     $page = "/icp/a/";
     $headers = array( 
        "GET ".$page." HTTP/1.0",
        "Accept: text/html",
        "Content-Type: text/html",
        "API-Version: 2.2",
        "API-AppId: yourapiappid",
        "API-Username: yourapiusername",
        "API-Password: yourappidpassword"
    );

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

    $data = curl_exec($ch);

Here you get your accountId and the rest is just calling the right url with this script!

Hope it gives you a hint.

"Keep up the good coding."

1
On

This is my full code to get the account id and client folder id, thanks to Carlos Duran above for getting some of my code problems worked out:

/* iContact LIVE * /
$GLOBALS['iContact_settings'] = array(
    'apiUrl'   => 'https://app.icontact.com',
    'apiPage'  => '/icp/a/',
    'username' => 'username',
    'password' => 'password',
    'appId'    => 'appId'
);
/* iContact SANDBOX */
$GLOBALS['iContact_settings'] = array(
    'apiUrl'   => 'https://app.sandbox.icontact.com',
    'apiPage'  => '/icp/a/',
    'username' => 'username-beta',
    'password' => 'password',
    'appId'    => 'appId'
);
/**/


$icontact_url  = $GLOBALS['iContact_settings']['apiUrl'] . $GLOBALS['iContact_settings']['apiPage'];
$icontact_page = $GLOBALS['iContact_settings']['apiPage'];
$icontact_headers = array( 
    "GET ".$icontact_page." HTTP/1.0",
    "Accept: text/xml",
    "Content-Type: text/xml",
    "API-Version: 2.2",
    "API-AppId: " .    $GLOBALS['iContact_settings']['appId'],
    "API-Username: " . $GLOBALS['iContact_settings']['username'],
    "API-Password: " . $GLOBALS['iContact_settings']['password']
);


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $icontact_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $icontact_headers);

$data = curl_exec($ch);
curl_close($ch);

$account_id = "";
if (($pos=strpos($data,"<accountId>"))!==false){
    $account_id = substr($data, strlen("<accountId>")+$pos);
    if (($pos=strpos($account_id,"<"))!==false){
        $account_id = substr($account_id, 0, $pos);
    }
}


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $icontact_url ."$account_id/c/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $icontact_headers);

$data = curl_exec($ch);
curl_close($ch);

$client_folder_id = "";
if (($pos=strpos($data,"<clientFolderId>"))!==false){
    $client_folder_id = substr($data, strlen("<clientFolderId>")+$pos);
    if (($pos=strpos($client_folder_id,"<"))!==false){
        $client_folder_id = substr($client_folder_id, 0, $pos);
    }
}

I just switched to JSON, way better.

$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, $icontact_url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($handle, CURLOPT_HTTPHEADER, $icontact_headers);

$data = curl_exec($handle);
curl_close($handle);

$decoded = json_decode($data);
$account_id = $decoded->accounts[0]->accountId;

$handle = curl_init();
curl_setopt($handle, CURLOPT_URL, $icontact_url ."$account_id/c/");
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($handle, CURLOPT_HTTPHEADER, $icontact_headers);

$data   = curl_exec($handle);
curl_close($handle);

$decoded = json_decode($data);
$client_folder_

id = $decoded->clientfolders[0]->clientFolderId;

And use:

"Accept: application/json",
"Content-Type: application/json",

Instead of text/xml above.

0
On

The easiest way I have found: Login to sandbox or to your real iContact account, in the main menu go to Contact -> Sign-up forms, then create just any form, click on view HTML and you will find Account Id there.

0
On

This PHP iContact API is rather useful https://github.com/icontact