5

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.

Laurel
  • 5,965
  • 14
  • 31
  • 57
Deepak Rathi
  • 85
  • 1
  • 7

4 Answers4

2

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.

Anton
  • 485
  • 4
  • 12
2

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.

Jake
  • 2,058
  • 2
  • 24
  • 33
1

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."

Carlos Duran
  • 29
  • 1
  • 6
  • This held the answers for me. I seem to have been using incorrect CURL setup. Although it might have been this line that saved me: "GET ".$page." HTTP/1.0", However, it is important to note that the next two lines need to be changed from "text/html" to "text/xml". – Jake Jan 17 '12 at 03:49
0

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

Yasen
  • 3,400
  • 1
  • 27
  • 22