Skip to content

Instantly share code, notes, and snippets.

@matthewpoer
Last active August 29, 2015 14:01
Show Gist options
  • Save matthewpoer/356440bdfde0b51d9363 to your computer and use it in GitHub Desktop.
Save matthewpoer/356440bdfde0b51d9363 to your computer and use it in GitHub Desktop.
As a SugarCRM Business Partner, we may need to obtain subscription data from the partner portal. Here's how to invoke the Partner Portal's API using cookies from your web browser, then generate a CSV with the data required.
<?php
/*
* You Need to set the $cookie param. Do so by logging into the partner portal
* at https://partners.sugarcrm.com, then log in. Then visit a the API page at
* https://partners.sugarcrm.com/account/list/5/5 with your Dev Console open.
* If you review your Resources, you can find the cookie that the portal gave
* your browser. Just copy-paste the entire set of cookies from the Request.
*/
$cookie = "";
/*
* No further editing is needed. Just run from CLI like `php -f file.php`
*/
$all_accounts_url = 'https://partners.sugarcrm.com/account/list/200/0';
$subscription_info_url = 'https://partners.sugarcrm.com/subscription/list/';
function send_and_decode_response($url){
global $cookie;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
$data = curl_exec($ch);
curl_close($ch);
return json_decode($data);
}
$accounts = send_and_decode_response($all_accounts_url);
$final_account_list = array();
$out = "Account_Name,Expiration_Date,NumberOfUsers\n";
foreach($accounts as $account){
$url = $subscription_info_url . $account->id;
$sub = send_and_decode_response($url);
$out .= $out .= "\"{$account->name}\",\"{$sub[0]->term_end_date_c}\",\"{$sub[0]->quantity_c}\"\n";
}
$fh = fopen('accounts.csv','w+');
fwrite($fh,$out);
fclose($fh);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment