Pagination in AWS php SDK - amazon-web-services

I am trying to implement ec2 API in a project. How do we implement pagination on
ec2-descibe-instances. I send the option as null
$ec2 = new AmazonEC2($key, $secret);
$ec2->set_region('us-east-1');
$allInstances = $ec2->describe_instances(null);
If I have hundreds of instances, rendering all instances might be an issue. So want to lazy load 10 instance at a time. I see python boto having some limits but the php SDK for aws.
Can any one please let me know how we can accomplish?

you should refer to this q How to get list of EC2 instances with Amazon PHP SDK 2?
Add Page parameter to the filter as Page=1, page=2 and so on.
$result = $ec2Client->DescribeInstances(array(
'Filters' => array(
array('Name' => 'instance-type', 'Values' => array('m1.small'),'Page' => 2),
)
));

Related

Prestashop quantities update through webservice

I'm building an API for a prestashop Website. I want to update my products from an external source
So i do a PUT Request on the product's stock_availables and that's fine as far as backoffice is concerned.
Although when i make a GET Request i get quantity=0
Any idea why?
Quantity is kept in stock_availables. You can try:
$xml = $webService->get([
'resource' => 'stock_availables',
'id' => $id,
]);
$quantity = $xml->stock_available->quantity;

AWS Connect : How do I show company name on outbound calls instead of a phone number , or maybe both?

I have been trying to show up the company name instead of a phone number when an outbound call is initiated automatically at certain times using aws connect contact flow. So far, everything is working as it should be except for showing up the name of the company. I have been trying to find a solution or a documentation on how to show the company name instead of a number but so far could not find anything useful. the only hint I got from aws documentation was , I should set the caller id and name by myself, and no further instruction or hints on how to do it. I Tried to change the phone number using outboundcall api's contact attributes but nothing was showing up.
$result = $client->startOutboundVoiceContact([
'Attributes' => array(
'sourcePhoneNumber' => $d->company_name,
'd`enter code here`ate'=> $d->date,
'time' => $d->time,
'clinic' => $d->company_branch_name,
'address' => $d->company_branch_address,
),
'ContactFlowId' => $this->contactFlowId, // REQUIRED
'DestinationPhoneNumber' => $d->phone_number, // REQUIRED
'InstanceId' => $this->instanceId, // REQUIRED
'SourcePhoneNumber' => $this->sourcePhoneNumber,
]);
'''
where $d is my database and i am getting all the information from there
any recommendation or solution would be very much helpful. thank you.
If I recall correctly this feature is only possible in the US.

How to add people to facebook ad account in business manager

I am trying to create ad account by following https://developers.facebook.com/docs/marketing-api/reference/ad-account. With the help of this code I could successfully create ad account but I want to add myself as people as well but not getting any way to do this.
My ad account creation parameters are like
$attachment = array(
'access_token' => $this->accessToken,
'name' => $associative_arr['name'],
'currency' => $associative_arr['currency'],
'timezone_id' => $associative_arr['timezone_id'],
'end_advertiser' => $this->businessAccount,
'media_agency' => 'NONE',
'partner' => 'NONE',
'user_role' => '1001'
);
and endpoint is
https://graph.facebook.com/v2.8/BUSINESS_ID/adaccount
I also tried updating ad account using following
https://developers.facebook.com/docs/marketing-api/aduser/v2.8
but no gain.
I am getting following error.
stdClass Object
(
[error] => stdClass Object
(
[message] => (#10) Application does not have permission for this action
[type] => OAuthException
[code] => 10
[fbtrace_id] => HyAJtY0OOMf
)
)
Can anyone give me suggestions how I can ad people to my ad account using curl or PHP SDK?
Besides getting the ads_management permission, what was your app's Marketing API access level? The default access level supports up to only 5 ad account access. If you've accessed more than that via the API, you won't be able to do that on more accounts unless you apply for higher level of access. You can manage your ad account list in your app dashboard.

Amazon Product API - URL response

is there anyway to dynamically generate the response for the Amazon Product API with using just a URL string?
I see there are PHP and C# libraries but I am just trying to browse to a URL and see the response. I noticed one of the required fields of the URL is a timestamp which makes this tricky. The following page helped to generate the URLs but I can't seem to find a way to do it dynamically?
http://associates-amazon.s3.amazonaws.com/scratchpad/index.html
Thanks!
This is the dynamic search for amazon product
Download aws_signed_request.php from this url
include('aws_signed_request.php');
$public_key = 'xxxxxxxx';
$private_key = 'xxxxxxxxxx';
$associate_tag = 'xxxxxx';
$keywords= 'PHP';
$search_index = 'Books';
// generate signed URL
$request = aws_signed_request('com', array(
'Operation' => 'ItemSearch',
'Keywords' => "Php Books",
"SearchIndex" => "Books",
"Count" => '24',
'ResponseGroup' => 'Large,EditorialReview'), $public_key, $private_key, $associate_tag);
// do request (you could also use curl etc.)
$response = #file_get_contents($request);
Documentation URL HERE
I'm not sure I totally understand your question, but I think the answer is "the data in the Amazon product API is only available via 'signed' URLs". That way, Amazon can track abuse, etc back to the source (i.e. the signer).
If it were possible to get the data with a "static" URL, then you could post that URL all over the Internet and anyone could get the data without signing up with Amazon. It's their data, and they have rules on it's use, so that wouldn't fly with them.
That said, you can usually create URLs with a timestamp in the future (months or even years). But you would still be responsible for it's use/abuse.

SignatureDoesNotMatch in Amazon API

I am using the Amazon API and get this error while updating my stock from my database to Amazon website:
Caught Exception: Internal Error
Response Status Code: 0
Error Code:
Error Type:
Request ID:
XML:
I read this thread (amazonsellercommunity . com/forums/thread.jspa?messageID=2194823) and then get the error explanation:
<Error><Type>Sender</Type><Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.</Message><Detail/></Error>
So I thought my MARKETPLACE_ID, MERCHANT_ID, AWS_ACCESS_KEY_ID or AWS_SECRET_ACCESS_KEY could be wrong. But I checked and these informations are correct.
Actually, I don't understand why this error happens... Before, it worked perfectly and since a couple of days it just crash. And I don't change anything in my code. Strange, isn't it?
Edit :
Here is my section code for signature.
define ('DATE_FORMAT', 'Y-m-d\TH:i:s\Z');
define('AWS_ACCESS_KEY_ID', 'ABC...'); // My AWS Access Key Id (20 characters)
define('AWS_SECRET_ACCESS_KEY', 'ABCDEF...'); // My AWS Secret Access Key (40 characters)
define('APPLICATION_NAME', 'MyCompany_AmazonMWS');
define('APPLICATION_VERSION', '0.0.1');
define ('MERCHANT_ID', 'XXXXXXX'); // My Merchant ID
define ('MARKETPLACE_ID', 'XXXXXXX'); // My Marketplace ID
$config = array (
'ServiceURL' => "https://mws.amazonservices.fr",
'ProxyHost' => null,
'ProxyPort' => -1,
'MaxErrorRetry' => 3,
);
$service = new MarketplaceWebService_Client(
AWS_ACCESS_KEY_ID,
AWS_SECRET_ACCESS_KEY,
$config,
APPLICATION_NAME,
APPLICATION_VERSION
);
$parameters = array (
'Marketplace' => MARKETPLACE_ID,
'Merchant' => MERCHANT_ID,
'FeedType' => '_POST_INVENTORY_AVAILABILITY_DATA_',
'FeedContent' => $feedHandle,
'PurgeAndReplace' => false,
'ContentMd5' => base64_encode(md5(stream_get_contents($feedHandle), true)),
);
// and then I do this:
$request = new MarketplaceWebService_Model_SubmitFeedRequest($parameters);
invokeSubmitFeed($service, $request);
If you want to see some parts of my code, just ask.
If I recall correctly, the authentication mechanism for Amazon APIs is sensitive to the current date/time on your machine (which is used in the process of signing the request). Check to see if your date/time is set correctly.
For me it was just an error with my web app passing url escaped strings. The special characters weren't like by amazon and this (not so useful) error came up. Make sure your file names have no url escaped characters.
I solved it (on Ubuntu 14.04 Server) using ntpdate:
First make sure it is installed:
apt-get install ntpdate
And then execute:
ntpdate ntp.ubuntu.com