Database update via API returns "State":"Waiting","InitialQuery"
I use a cron job to hit the API a few times a day, sometimes I get a blank result and this is what is returned:
Any idea why this happens ?? I am not requesting the API every second. It is literally twice a day ??
{"ResultId":XXX"","ResultUrl":"https:\/\/api.wildapricot.org\/v1\/accounts\XXX\/Contacts\/?resultId=XXX","Requested":"2015-07-26T22:56:05.057","State":"Waiting","InitialQuery":{"ObjectType":"Contact","FilterExpression":null,"SelectExpression":null}}
Sample code provided.
-
There is a sample PHP application available on github: https://github.com/WildApricot/ApiSamples/blob/master/PHP/sampleApplication.php
This sample contains a class WaApiClient, which helps you to get token and make API requests. The sample also contains a function getContactsList, which shows how to list contacts synchronously.
-
eberswine commented
I am a little confused on the new authentication process. Here is my old code, could you maybe steer me in the right direction with the new process ?? Thanks so much!!
define("API_KEY",'XXXX');
define("ACCOUNT_ID",'XXXX');define("ORGANIZATIONAL_MEMBERSHIP_LEVEL_ID",'XXX');
define("ASSOCIATE_MEMBERSHIP_LEVEL_ID",'XXX');/**
** This method is used for the get company list or contact or member
** Param
*/
function get_organization_list()
{
$api_key = API_KEY;
$account_id = ACCOUNT_ID;
$organization_list = array();
$url = "https://api.wildapricot.org/v1/Accounts/$account_id/Contacts?apikey=$api_key";
$public_contact_member = file_get_contents($url);
$json_decode_arr = json_decode($public_contact_member);
//pr($json_decode_arr);
-
eberswine commented
ok, great.
Thanks for your comments!SO if I update the authentication and then use the URL $async=false, then it should work great ! ?
-
It looks like you call asynchronous version of contact search. There are 2 options to get the result list of contacts:
1. You can contunue using asynchronous version of contact search. As you can see "State" of the request if "Waiting". In this case your programm should wait for some time and call "ResultUrl" till the state is "Complete". If state is "Complete", then response contains a filed "Contacts" with a result list of contacts.
2. Another option is to use synchronous version of contact search (it is only available in API v2). To do it your programm should add a query string parameter $async=false. So the correct version of URL will be https://api.wildapricot.org/v2/accounts/XXX/contacts?$async=false
Please note, that authentication scheme of API v2 differs from API v1. See http://help.wildapricot.com/display/DOC/API+V2+authentication for details.