omise PHP get all charges - php

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.

Related

Retrieving events from mailgun account

I'm trying to keep track of all events happening on my Mailgun account. As per the documentation, something like this would work
$mailgun->events()->get('example.com');
My code is as below
$mg = Mailgun::create('API KEY');
$queryString = array(
'begin' => 'Tue, 1 October 2019 09:00:00 -0000',
'ascending' => 'yes',
'limit' => 25,
'pretty' => 'yes',
'subject' => 'pulse'
);
# Make the call to the client.
$result = $mg->events()->get('example.com', $queryString);
The result is a string, Mailgun Magnificent API.
I have also tried $result = $mg->events()->get('example.com'); with similar results
I expceted a detailed JSON Object displaying my events or probably an unauthorized error message. Is there something I could be missing?

Podio api task due_date format

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.

Getting "Invalid parameter" exception on getReportsStats with no reason

Can anyone help me with a fast code review?
$fields = array(
'campaign_id',
'spend'
);
$params = array(
'data_columns' => $fields,
'time_interval' => array(
'day_start' => array(
'year' => 2011,
'month' => 9,
'day' => 1
),
'day_stop' => array(
'year' => 2011,
'month' => 9,
'day' => 10
),
),
);
$stats = $adAccount->getReportsStats(array(), $params);
After running this code I am getting:
<b>Fatal error</b>: Uncaught exception 'FacebookAds\Http\Exception\AuthorizationException' with message 'Invalid parameter' in /home/maciekmp/public_html/face_test/FacebookAds/Http/Exception/RequestException.php:129
fdfd
I found the following in the facebook api developer docs. Search on "async". If the data you are querying is too old you will have to do an asynchronous call to the graph api. Which is usually the case with the error you received. The current version of the php-sdk does not support passing an async parameter out of the box. Since AdAccount defaults to GET request and async calls to the graph api must be done with POST request, you will need to extend the AdAccount class and create and prepare a request to use the POST method.
I found that when you try get more than 30 days of to the current date it shows this error.
29 days of data and it works, which is rather pointless! I'm going to ask in their developer forum.
$fields = array('campaign_id', 'total_actions', 'spend'); // The fields I ask for?
$params = array(
'data_columns' => array (
'campaign_group_id',
'total_actions',
'social_impressions',
'impressions',
'unique_impressions',
'clicks',
'spend',
'impressions',
// 'action_values_28d_view'
),
'time_interval'=>array(
'time_start'=>mktime(0,0,0,1,17,2015),
'time_stop'=>mktime(0,0,0,date("n"),date("d"),date("Y"))
),
/*
'time_ranges'=>array(
array(
'day_start'=>array(
'day'=>1,
'month'=>1,
'year'=>2015,
),
'day_stop'=>array(
'day'=>13,
'month'=>2,
'year'=>2015,
),
),
),
*/
// 'date_preset' => 'last_28_days',
'time_increment'=>1,
);

Multiple elements of same name in PHP SOAP Call

I know this type of question has been asked a number of times. I have spent several hours reading and trying the offered solutions - but none appear to work for my situation.
I need to send a SOAP request to an API that can contain an element that repeats like so:
<operationNumbers>
<operationNumber>1234</operationNumber>
<operationNumber>1235</operationNumber>
<operationNumber>1236</operationNumber>
<operationNumber>1237</operationNumber>
</operationNumbers>
I did read that perhaps I could do this:
$buildRequest = Array(
'myheader' => Array(
'date' => MY_DATE,
'id' => Array(
'client' => CLIENT,
'clientRef' => MYREF
)
),
'operationNumbers' => Array (
Array('operationNumber' => '1234'),
Array('operationNumber' => '1235')
)
);
$request = $client->__soapCall( 'getMultiOpDets', array($buildRequest) );
Sadly this does not work and results in 'invalid request', if I send in a single operation number eg:
...
'operationNumbers' => Array (
'operationNumber' => '1234'
)
...
The request is successful. I've tried soapVars/soapParams but cannot get it working using this approach. Any hints/tips/help appreciated.
So, I solved it.
$operationNumbersArray = array('1234','1235');
...
'operationNumbers' => array(
'operationNumber' => $operationNumbersArray
)
During my testing and fiddling about, I had inadvertently removed another value that was mandatory. The API did not give warning of it's omission (sadly).
Here is the code I use:
$wsdl = 'https://your.api/path?wsdl';
$client = new SoapClient($wsdl);
$multipleSearchValues = [1, 2, 3, 4];
$queryData = ['yourFieldName' => $multipleSearchValues];
$results = $client->YourApiMethod($queryData);
print_r($results);

batch put_item with DynamoDB in PHP

I'm running into issues sending data to my DynamoDB. I have no idea what the issue is because it appears the program runs correctly, however I don't seem to have any data in my DB. I was able to create tables using Amazons tutorial, but when I follow this tutorial, I get a failed response if I try and put ALL the items, and a false success when it's only one item, as nothing is updated in the db.
Here's the code, I'm curious specifically if anyone knows a means to debug these kinds of issues.
<?php
// If necessary, reference the sdk.class.php file.
// For example, the following line assumes the sdk.class.php file is
// in an sdk sub-directory relative to this file
require_once('includes/backend.php');
// Instantiate the class
$dynamodb = new AmazonDynamoDB();
####################################################################
# Setup some local variables for dates
$one_day_ago = date('Y-m-d H:i:s', strtotime("-1 days"));
$seven_days_ago = date('Y-m-d H:i:s', strtotime("-7 days"));
$fourteen_days_ago = date('Y-m-d H:i:s', strtotime("-14 days"));
$twenty_one_days_ago = date('Y-m-d H:i:s', strtotime("-21 days"));
####################################################################
# Adding data to the table
echo PHP_EOL . PHP_EOL;
echo "# Adding data to the table..." . PHP_EOL;
// Set up batch requests
$queue = new CFBatchRequest();
$queue->use_credentials($dynamodb->credentials);
// Add items to the batch
$dynamodb->batch($queue)->put_item(array(
'TableName' => 'ProductCatalog',
'Item' => array(
'Id' => array( AmazonDynamoDB::TYPE_NUMBER => '101' ), // Hash Key
'Title' => array( AmazonDynamoDB::TYPE_STRING => 'Book 101 Title' ),
'ISBN' => array( AmazonDynamoDB::TYPE_STRING => '111-1111111111' ),
'Authors' => array( AmazonDynamoDB::TYPE_ARRAY_OF_STRINGS => array('Author1') ),
'Price' => array( AmazonDynamoDB::TYPE_NUMBER => '2' ),
'Dimensions' => array( AmazonDynamoDB::TYPE_STRING => '8.5 x 11.0 x 0.5' ),
'PageCount' => array( AmazonDynamoDB::TYPE_NUMBER => '500' ),
'InPublication' => array( AmazonDynamoDB::TYPE_NUMBER => '1' ),
'ProductCategory' => array( AmazonDynamoDB::TYPE_STRING => 'Book' )
)
));
echo "Item put in <b>Reply</b>" . "<br/>";
// Execute the batch of requests in parallel
$responses = $dynamodb->batch($queue)->send();
// Check for success...
if ($responses->areOK())
{
echo "The data has been added to the table." . PHP_EOL;
}
else
{
utdump($responses);
}
Thank you for your time
Try setting your region explicitly, e.g. for EU you need to call:
$myDynamoDbObject->set_region('dynamodb.eu-west-1.amazonaws.com');
It might also be that you have two tables in different regions, your application work with one of them and you trying to read (or track with web console) another one because of different default regions applied.
If you're tracking number of items in the table, keep in mind that it is not a real time figure, it is only updated every 6 hours or so. So the way use can ensure your item is indeed written by trying to read it back immediately after you receive the "OK" response for your put request.

Categories