I'm trying to get the Podio API (php-library) to return all tasks that have a due date withing a certain range. PodioTask::get_all() works fine, it returns all tasks (limited to 100). Of course that is not very useful so I add attributes as documented:
$tasks = PodioTask::get_all(array(
'org' => [my_organization_id],
'completed' => 'false',
'limit' => 100
)
);
Up until here behavior is still as expected. As soon as I attempt to add the due_date-attribute I get an error message saying Uncaught PodioBadRequestError: "The values are not in the right format" Request URL: http://api.podio.com/task/?org=[my_organization_id]&completed=false&due_date=&limit=100
I try to do it like this, which works fine for the filters on Podio items:
$tasks = PodioTask::get_all(array(
'org' => [my_organization_id],
'completed' => 'false',
'due_date' => array(
'from' => '2d',
'to' => '90d'
),
'limit' => 100
)
);
I tried replacing the from and to dates with absolute ones in the YYYY-MM-DD format (as a string, but also tried a DateTime-object), but I get the same error. I tried removing the array and just setting a single date (as a string and a DateTime object) and none of it works. I keep getting the message that the values are not in the right format. The documentation tells me the due_date-parameter is "The from and to date the task should be due between. For valid options see date filtering under the filter area." If I go there I end up with the documentation for filtering items and I am doing the exact same thing here as for items, which I can filter by date. (https://developers.podio.com/doc/tasks/get-tasks-77949)
It appears like the php-library expects a string, but the API needs the 'from' and 'to' properties.
Anyone got any ideas?
Try this
$attributes = array(
'org' => [my_organization_id],
'completed' => 'false',
'limit' => 100,
'due_date'=> $fromDate.'-'.$toDate
);
$tasks = PodioTask::get_all($attributes);
where $fromDate and $toDate are DateTime Objects.
Related
I'm using an api that has a "range" parameter that can apply to several different parameter items. The range i'm focusing on is "price". I'm using guzzle in laravel and according to the api documentation, the query for this particular parameter should be written like this "&range_facet=price|500|2500|250"...this is broken down into the minimum, maximum, and interval values of the price range parameter. That's not necessarily important to this question. When i try and run this query as is, i get nothing returned. When I remove that particular parameter, i get values but obviously they're not filtered the way i want them to be. When i run this in Insomnia, the pipes are replaced by "%7C", which is obviously (obviously?) not interpreted by the api as it's not how it's waiting for the GET request to be made. How can I insert the pipes into the query so that it calls the correct way?
I've tried to create an additional nested array with the price value being broken up into key value pairs but that didn't work either.
'range_facets' => ['price'['start'=>'500', end=>'2500', 'interval'=>'250']],
$client = new Client();
$result = $client->request('GET', "http://api.example.com", [
'headers' => [
'Host' => 'example-host',
'Content-Type' => 'application/json'
],
'query' => [
'api_key' => 'my_api_key',
'range_facets' => 'price|500|2500|250',
'year' => $year,
'latitude' => '30.170222',
'longitude' => '92.01320199',
'radius' => 500,
'start' => 0,
'rows' => 50
]
]);
I'd like to filter my prices but I need the pipe to be able to do it.
This is exactly how it should be. %7C should be decoded on the server side to | automatically (about query string encoding).
I bet the issue is in different place.
Omise PHP get all charges
ref : https://www.omise.co/charges-api
$charges = OmiseCharge::retrieve();
this code gives me 20 records which is okay.
$response = OmiseCharge::retrieve('',OMISE_PUBLIC_KEY,OMISE_SECRET_KEY);
this also gives me first 20 records.
but my requirement is fetch all charges with date params.
$param = array(
'from' => '2014-10-20 00:00:00',
'to' => '2014-09-25 00:00:00'
);
$response = OmiseCharge::retrieve($param);
this gives an error.
Fatal error: Uncaught exception 'OmiseNotFoundException' with message 'charge Array was not found'
what i am doing wrong.
currently Omise-PHP library doesn't support for passing array at the first parameter.
(As your solution) you have to pass it as string (including other filters, such as 'limit', 'offset').
$param = array(
'limit' => 40,
'offset' => 40,
'from' => '2011-10-20 00:00:00',
'to' => '2016-09-25 00:00:00'
);
$charges = OmiseCharge::retrieve('?'.http_build_query($param));
I don't know this library but after quick search some tips:
First of all (if you not already done this) read this doc about pagination.
I found that date has different format: iso8601 what means for ex 2014-10-20T00:00:00Z.
limit to 20 records you can change to 100, try to use pagination
BTW. Interesting API.
$param = array(
'from' => '2011-10-20 00:00:00',
'to' => '2016-09-25 00:00:00'
);
$response = OmiseCharge::retrieve('?'.http_build_query($param));
worked for me.
I am working with the Church Community Builder API (official docs, search for "group profile" to see relevant code) and with CCB Core WordPress Plugin to sync groups data from the API into custom post types (fields, taxonomies).
CCB Core maps a lot of this data automatically, but it doesn't map the group ID value CCB uses to distinguish one group from another and I'd like to sync it.
The relevant code is kept in the functions get_groups_custom_fields_map() and get_groups_taxonomy_map().
I've tried adding something like the following to get_groups_taxonomy_map():
'group_id' => array (
'api_mapping' => 'group',
'data_type' => 'integer',
),
But this doesn't work. Any suggestions on writing code to pull in this field?
UPDATE 9/10/16 7:25 PM:
I think I am wicked close.
I took the XML from the API documentation under Group Profile and ran it through simplexml and generated this output.
I then compared the output with how the get_groups_custom_fields_map and get_groups_custom_taxonomy_map was organized, which led me to believe the following should work:
'group' => array (
'api_mapping' => 'group',
'data_type' => 'object',
'child_object' => array(
'api_mapping' => '#attributes',
'data_type' => 'object',
'child_object' => array(
'group_id' => array(
'api_mapping' => 'id',
'data_type' => 'integer'
)
)
)
),
But it doesn't. What am I missing?
The SimpleXML representation of the response that comes back from CCB just so happens to have a really frustrating way of deserializing the IDs for the entities (Groups, Events, Individuals, etc) that come out of the API. (And it only happens on the IDs).
Even though Group ID looks like a property in the XML response string, it's actually an attribute which is slightly different. In your object response, notice that # symbol in the [#attributes] node. PHP will not allow direct access to that.
See "At sign" # in SimpleXML object?
As a workaround I actually obtain the Group ID like so right here:
https://github.com/jaredcobb/ccb-core/blob/1a6e88b47ad7d5293e88bac277e72cbc4e33a602/admin/class-ccb-core-sync.php#L589-L595
Code snippet of the above reference:
$group_id = 0;
foreach( $group->attributes() as $key => $value ) {
if ( $key == 'id' ) {
$group_id = (int) $value;
break;
}
}
So in general, we do have access to that group id, we just need to now save it as post meta. I'll update the plugin to take advantage of these IDs, but in the mean time you can use the $group_id variable directly and save the post meta in this function.
I have been trying to set up an automated script to pull from a RETS server using PHP and I can not get the PHRets search to return anything. My query is below:
/* Search RETS server */
$search = $rets->SearchQuery(
'Property', // Resource
3, // Class
'(LastTransDate_f77=2013-01-01+)', // DMQL
array(
'Format' => 'COMPACT-DECODED',
'Select' => 'AREA_f16',
'Count' => 1,
'Limit' => 20,
)
);
EDIT: I got this working finally. The problem had nothing to do with my code, however, it was in the MLS board's faulty documentation. The documentation said that I could select certain fields for certain property types, but that wasn't the case. I had to consult a third party developer and get the list of fields/column names that he had used.
Consult the PHRETS documentation. You have the second parameter as an integer. It should be a string. Also the comma needs to be removed after the last element in the array.
/* Search RETS server */
$search = $rets->SearchQuery(
'Property',
'3',
'(LastTransDate_f77=2013-01-01+)',
array(
'Format' => 'COMPACT-DECODED',
'Select' => 'AREA_f16',
'Count' => 1,
'Limit' => 20
));
I'm trying to update a specific Lead from Sugar CRM. I do not know the ID of this lead, so I'm trying to retrieve the lead ID by calling get_entry_list using email addresses or names. I wanted to use a query and specify an email address or a name like so:
'query' => "first_name = \"Bob\"",
I even tried:
'query' => "first_name LIKE \"%Bob%\"",
and
'query' => "email1 LIKE \"%bob#abc.com\"",
But I just get this result:
Database failure. Please refer to sugarcrm.log for details.
...and there's nothing inside sugarcrm.log :(
Here's the full code:
$get_entry_list_parameters = array(
//session id
'session' => $session_id,
//The name of the module from which to retrieve records
'module_name' => 'Leads',
//The SQL WHERE clause without the word "where".
'query' => "first_name = \"Bob\"",
//The SQL ORDER BY clause without the phrase "order by".
'order_by' => "",
//The record offset from which to start.
'offset' => '0',
//Optional. A list of fields to include in the results.
'select_fields' => array(
'id',
'name',
'email1',
),
'link_name_to_fields_array' => array(
),
//The maximum number of results to return.
'max_results' => '10',
//To exclude deleted records
'deleted' => '0',
//If only records marked as favorites should be returned.
'Favorites' => false,
);
$get_entry_list_result = call('get_entry_list', $get_entry_list_parameters, $url);
echo '<pre>';
print_r($get_entry_list_result);
echo '</pre>';
EDIT: I'm using v4_1 REST API
Check this a running example > http://urdhva-tech.blogspot.in/2013/02/rest-api-example.html
Hope you find it useful.
Else by looking at the $get_entry_list_parameters array, it looks like it should work just fine.
Take a look in service/v4/SugarWebServiceUtilv4.php beginning in line 78. Set a breakpoint there or log the query ($where) that was generated. Maybe this helps you find out the reason.