sparkapi / sparkapi4p2

A PHP wrapper for the flexmls REST API.
GNU General Public License v3.0
26 stars 28 forks source link

GetAccounts ByOffice #13

Closed thinkerytim closed 12 years ago

thinkerytim commented 12 years ago

in the sparkAPI4p2, you accept an optional parameters object with this method:

GetAccountsByOffice($id, $params = array())

However, in the actual platform docs (http://sparkplatform.com/docs/api_services/my_account#RetrieveAccountInfoForAnOffice) it says that there are no params.

I'd like to use the params object to filter the accounts (to search for agent by name, for example) or to order by. But I don't think this is supported in the API.

donclem commented 12 years ago

You are correct, the Get call for Account for Office Members does not allow _filter parameters. However, it does allow _pagination and _page calls.

As for filtering and orderby, you could always use the GetAccounts Get (that allows you to filter and orderby) and passing the OfficeId as one of the parameters to limit it down to just that office (and of course by Name).

For example, using your Luke Wild key, I used the following build to take show you what the params section is for under Get Accounts By Office Members:

Code

 // Get Accounts by Office Members

$id = '20000507120026142456000000';  // This is the Office ID for Luke
$params = array(
        "_pagination" => "1" // Setting _pagination to grab counts
        );
$resultGetAccountsByOffice = $api->GetAccountsByOffice($id, $params);
if ($resultGetAccountsByOffice === false) { // testing to see if the call was successful
    echo "API Error Code: {$api->last_error_code}\n";  // If not, print out the last error report
    echo "API Error Message: {$api->last_error_mess}\n";
    exit;
} else {
    if($params["_pagination"] == '1') {  // If so, check to see if Pagination was set
        $i = 1; // Set counter
        while($i <= $api->total_pages) { // loop until all pages are printed
                            // printing out the current page
            print_r($api->GetAccountsByOffice($id, $params = array("_pagination" => "1", "_page" => $i)));
            echo("Last count: " . $api->last_count . "\n"); // just to see the count, size, pages, current page.
            echo("Page size: " . $api->page_size . "\n");
            echo("Total pages: " . $api->total_pages . "\n");
            echo("Current page: " . $api->current_page . "\n");  
            echo("Page Number: " . $i++ . "\n");  // added just to see a page number if I comment out the others
        }
    } else {
        print_r($resultGetAccountsByOffice); // if no pagination, just print results from first page
    }
}
thinkerytim commented 12 years ago

That's true, but as I noted in the JIRA issue report, the GetAccounts service only includes full name, thus you can't filter or order by last name etc.

Tim Kramer tim@thethinkery.net The Thinkery, LLC

On Wed, Jul 25, 2012 at 12:20 PM, Don Clemens < reply@reply.github.com

wrote:

You are correct, the Get call for Account for Office Members does not allow _filter parameters. However, it does allow _pagination and _page calls.

As for filtering and orderby, you could always use the GetAccounts Get (that allows you to filter and orderby) and passing the OfficeId as one of the parameters to limit it down to just that office (and of course by Name).

For example, using your Luke Wild key, I used the following build to take show you what the params section is for under Get Accounts By Office Members:

Code

 // Get Accounts by Office Members

    $id = '20000507120026142456000000';  // This is the Office ID for

Luke $params = array( "_pagination" => "1" // Setting _pagination to grab counts ); $resultGetAccountsByOffice = $api->GetAccountsByOffice($id, $params); if ($resultGetAccountsByOffice === false) { // testing to see if the call was successful echo "API Error Code: {$api->last_error_code}\n"; // If not, print out the last error report echo "API Error Message: {$api->last_error_mess}\n"; exit; } else { if($params["_pagination"] == '1') { // If so, check to see if Pagination was set $i = 1; // Set counter while($i <= $api->total_pages) { // loop until all pages are printed // printing out the current page print_r($api->GetAccountsByOffice($id, $params = array("_pagination" => "1", "_page" => $i))); echo("Last count: " . $api->last_count . "\n"); // just to see the count, size, pages, current page. echo("Page size: " . $api->page_size . "\n"); echo("Total pages: " . $api->total_pages . "\n"); echo("Current page: " . $api->current_page . "\n"); echo("Page Number: " . $i++ . "\n"); // added just to see a page number if I comment out the others } } else { print_r($resultGetAccountsByOffice); // if no pagination, just print results from first page } }


Reply to this email directly or view it on GitHub: https://github.com/sparkapi/sparkapi4p2/issues/13#issuecomment-7259076