I was using the Fulfilled by Amazon (FBA) Inventory API( https://developer.amazonservices.com/doc/fba/inventory/v20101001/php.html/185-9758808-3007701 ) but getting the following error after executing " ListInventorySupplySample.php " . Can anyone please help me know what went wrong.
$request = new FBAInventoryServiceMWS_Model_ListInventorySupplyRequest();
$skus= new FBAInventoryServiceMWS_Model_SellerSkuList();
$skus->setmember(<sku>);
$request->setSellerId(SELLER_ID);
$request->setSellerSkus($skus);
$request->setMarketplace(MARKET_PLACE_ID);
$request->setQueryStartDateTime(date(DATE_FORMAT,strtotime(date("Y-m-d"). ' - 10 days')));
invokeListInventorySupply($service, $request);
Pasting the request.
FBAInventoryServiceMWS_Model_ListInventorySupplyRequest Object
(
_fieldsrotected => Array
(
SellerId => Array
(
FieldValue =>
FieldType => string
)
Marketplace => Array
(
FieldValue =>
FieldType => string
)
SellerSkus => Array
(
FieldValue =>
FieldType => FBAInventoryServiceMWS_Model_SellerSkuList
)
QueryStartDateTime => Array
(
FieldValue => 2014-09-23T00:00:00Z
FieldType => string
)
ResponseGroup => Array
(
FieldValue =>
FieldType => string
)
)
)
Pasting the following response.
HTTP/1.1 401 Unauthorized
Date: Fri, 03 Oct 2014 05:43:55 GMT
Server: AmazonMWS
x-mws-request-id: 0d956be3-5811-40f8-9084-4fbd77a83936
x-mws-timestamp: 2014-10-03T05:43:55.676Z
x-mws-response-context: 6n6IpwjyWO/qMfDqEazU02NkR09zL//rlcQMgApvMkfE7zhCMq2n2OtOE0y0F7AT4rO4RyslSkY=
Content-Type: text/xml
Content-Length: 295
Vary: User-Agent
<?xml version="1.0"?>
<ErrorResponse xmlns="http://mws.amazonaws.com/FulfillmentInventory/2010-10-01/">
<Error>
<Type>Sender</Type>
<Code>AccessDenied</Code>
<Message>Access denied</Message>
</Error>
<RequestID>0d956be3-5811-40f8-9084-4fbd77a83936</RequestID>
</ErrorResponse>
The issue is resolved I was using it in my localhost which is behind a proxy. the moment I uploaded it to the server the things worked. Thanks for your help.
Related
I am trying to get location header from the response on POST create session, but getting 405 error. All other response I am getting except for the location header.
require_once 'vendor/autoload.php';
require_once 'vendor/mashape/unirest-php/src/Unirest.php';
$response = Unirest\Request::post("https://skyscanner-skyscanner-flight-search-v1.p.rapidapi.com/apiservices/pricing/v1.0",
array(
"X-RapidAPI-Host" => "skyscanner-skyscanner-flight-search-v1.p.rapidapi.com",
"X-RapidAPI-Key" => "d0f49284f7mshba8a904a96cf3acp19aa44jsnb4056f027c69",
"Content-Type" => "application/x-www-form-urlencoded"
),
array(
"inboundDate" => "2019-04-25",
"cabinClass" => "business",
"children" => 0,
"infants" => 0,
"country" => "IN",
"currency" => "INR",
"locale" => "en-US",
"originPlace" => "BLR-sky",
"destinationPlace" => "DEL-sky",
"outboundDate" => "2019-04-26",
"adults" => 1
)
);
print_r($response);
I expect this type of response:
"cache-control": "private"
"content-type": "application/json"
"date": "Wed, 24 Apr 2019 05:01:39 GMT"
"location": "http://partners.api.skyscanner.net/apiservices/pricing/hk1/v1.0/42ba47f0-314c-41fa-987d-fb8c5862309b"
"server": "RapidAPI-1.0.15"
"x-rapidapi-region": "AWS - ap-southeast-1"
"x-rapidapi-version": "1.0.15"
"content-length": "2"
"connection": "Close"
But, actual output is:
Unirest\Response Object ( [code] => 405 [raw_body] => {} [body] => stdClass Object ( ) [headers] => Array ( [0] => HTTP/1.1 405 Method
Not Allowed [Cache-Control] => private [Content-Type] =>
application/json [Date] => Wed, 24 Apr 2019 04:34:14 GMT [Server] =>
RapidAPI-1.0.15 [X-RapidAPI-Region] => AWS - ap-southeast-1
[X-RapidAPI-Version] => 1.0.15 [Content-Length] => 2 [Connection] =>
keep-alive ) )
I'm assuming you're using Skyscanner Flight Search API on RapidAPI Hub. Interestingly enough, I can't see any POST request supported by this API.
This can be the reason, 405 Method Not Allowed means that the HTTP method is simply not supported. For example, a client might do a POST request on a resource where POST is not implemented or it's meaningless.
I have searched the site and found many resources to help me load and XML file to parse, however after following some of the examples, I can still not get this to work. What am I missing?
thanks
<?php
$url = 'http://api.l5srv.net/job_search/api/web/find_jobs.srv?CID=2239&SID=u9xcvY234AA09&format=XML&q=Sales&l=95054&r=25&s=relevance&a=2014-09-30&start=1&limit=8&highlight=off&userip=25.158.22.121&useragent=Mozilla%2F5.0';
$xml = simplexml_load_file($url) or die("feed not loading");
var_dump($xml);
?>
You're most likely confusing what you see in the browser under that URL with an XML document.
What you have at the URL
http://api.l5srv.net/job_search/api/web/find_jobs.srv?CID=2239&SID=u9xcvY234AA09&format=XML&q=Sales&l=95054&r=25&s=relevance&a=2014-09-30&start=1&limit=8&highlight=off&userip=25.158.22.121&useragent=Mozilla%2F5.0
is not an XML document. When you request that URL and you look into the response headers, you can see that it is a HTML document:
HTTP/1.1 200 OK
Content-Type: text/html;charset=ISO-8859-1
P3P: CP="IDC CON TEL CUR DEV SAM IND"
Date: Mon, 10 Aug 2015 15:50:46 GMT
Content-Language: en-US
Connection: Keep-Alive
Set-Cookie: X-Mapping-gjinjpae=F462690912B62A0C5476B15FCDB01A81; path=/
Set-Cookie: JSESSIONID=BC6666D2A357FB969A60E05E67B0888C; Path=/
Set-Cookie: JSESSIONID=700D01B2F92909260A05215F86AB8EE5; Path=/
Content-Length: 7147
You can also easily verify that with your browser by making use of the view source feature in your browser or by seeing, that the XML is not displayed "pretty".
However simplexml_load_file expects a well-formed XML document. In your case the main problem you've got is missing error handling. As you interact with a remote system, error handling is crucial for stable use, so make it part of your script:
Dealing with XML errors (SimpleXML - PHP Manual)
Next to that, as it's an HTML document and not an XML document, you need to parse it with a HTML parser - not an XML parser. So don't try with an XML parser at that stage, use a HTML parser first.
How do you parse and process HTML/XML in PHP? (Reference Q&A)
Edit:
The problem with that service is only when you request XML format. If you change the format parameter to JSON (&format=JSON) you can parse the data straight-away despite the wrong response content-type given:
$url = 'http://api.l5srv.net/job_search/api/web/find_jobs.srv?CID=2239&SID=u9xcvY234AA09&format=JSON&q=Sales&l=95054&r=25&s=relevance&a=2014-09-30&start=1&limit=8&highlight=off&userip=25.158.22.121&useragent=Mozilla%2F5.0';
$result = json_decode(file_get_contents($url));
print_r($result);
Gives:
Array
(
[0] => stdClass Object
(
[response] => stdClass Object
(
[query] => Sales
[location] => 95054
[highlight] => off
[totalresults] => 25406
[start] => 1
[end] => 9
[radius] => 25
[pageNumber] => 0
[results] => Array
(
[0] => stdClass Object
(
[jobtitle] => Sales
[zip] => 95101
[company] => Commercial Janitorial Company
[city] => San Jose
[state] => CA
[country] => US
[date] => 2015-07-14
[url] => http://api.l5srv.net/job_search/api/web/get_job.srv?token=3aeyzv6V2SA%2BKYF5lzqWmxyivVwoE3LFernO291sVVpLbWCG9bBAbVO%2BCGXuN1V%2F9QMmDY3KeK5iYg2phrtjypXtQ82Jngf1q8zQIzix14EuBlSL96sqjffsuHozTZ4SJ6Mf%2B%2BVwRrC65gRtKxH6wg0F50WEZtnD9Xv0%2Bxc2GMhFMszKNEOyrfCNg5YTn%2Flj
[snippet] => Company Description:
We are a Christian owned janitorial company doing business here in the Bay Area for nearly 40 years. You do not have to be Christian to work for us.
We operate in a fast paced, f
[onmousedown] => l5_trk(this)
)
[1] => stdClass Object
(
[jobtitle] => Sales
[...]
The code coming from this server is not valid XML. Try this:
<?php
$url = 'http://api.l5srv.net/job_search/api/web/find_jobs.srv?CID=2239&SID=u9xcvY234AA09&format=XML&q=Sales&l=95054&r=25&s=relevance&a=2014-09-30&start=1&limit=8&highlight=off&userip=25.158.22.121&useragent=Mozilla%2F5.0';
$data = file_get_contents($url);
$data = '<' . '?xml version="1.0" encoding="UTF-8"?' . '>' . str_replace(array("<", ">"), array("<", ">"), $data);
$xml = simplexml_load_string($data) or die("feed not loading");
var_dump($xml);
From cURL I´m getting back an response array where I´d like to test the body against a regex pattern. Here is a sample array:
Array ( [body] => 9068205463|admin [headers] => Array ( [0] => HTTP/1.1 200 OK [1] => Date: Mon, 04 May 2015 16:45:56 GMT [2] => Server: Apache [3] => Vary: Accept-Encoding [4] => Content-Encoding: gzip [5] => Content-Length: 38 [6] => Connection: close [7] => Content-Type: text/html ) [engine] => cURL [cached] => )
Here is what my php if statement looks like:
if (!preg_match("/^[0-9]{10}\|[a-zA-Z]+$/", $result['body'])) {
die ("preg_match failed");
}
Question: Why is Die() fired?
Testing pattern here works like expected.
http://www.phpliveregex.com/p/b2W
Strange as this is working on my localhost but not on a production server.
Php Version is: PHP 5.3.10-1ubuntu3.18 with Suhosin-Patch
You probably have some spaces in your value and that's the reason why it doesn't matches the pattern.
To fix this simply use trim() in preg_match(), e.g.
if (!preg_match("/^[0-9]{10}\|[a-zA-Z]+$/", trim($result['body']))) {
//^^^^^
die ("preg_match failed");
}
I'm trying to get my subscription list through OAuth2 from Google Reader.
I'm using Codeigniter and a library - CI_OPAUTH. I can get the permissions scren with no problems and give Google Reader permissions. The problem is when i get the callback header after authentication is done it give me an 403 Forbidden header.
Here are my options for the library:
$config['opauth_config'] = array(
'path' => '/mixordia/index.php/oauth/login/', //example: /ci_opauth/auth/login/
'callback_url' => '/mixordia/index.php/oauth/authenticate/', //example: /ci_opauth/auth/authenticate/
'callback_transport' => 'get', //Codeigniter don't use native session
'security_salt' => 'mixordias_salt_whwhwh_wayacross',
'debug' => true,
'Strategy' => array(
'Google' => array(
'client_id' => 'MY_ID',
'client_secret' => 'MY_SECRET',
'service' => 'reader',
'source' => 'APP Name',
'scope' => 'http://www.google.com/reader/api'
)
)
);
Here is what i get:
Array
(
[error] => Array
(
[provider] => Google
[code] => userinfo_error
[message] => Failed when attempting to query for user information
[raw] => Array
(
[response] => 0
[headers] => HTTP/1.0 403 Forbidden
WWW-Authenticate: Bearer realm="https://www.google.com/accounts/AuthSubRequest", error=insufficient_scope, scope="https://www.googleapis.com/auth/userinfo.id h ttps://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/plus.login https://www.google.com/accounts/OAuthLogin"
Content-Type: application/json; charset=UTF-8
Date: Thu, 13 Jun 2013 12:26:25 GMT
Expires: Thu, 13 Jun 2013 12:26:25 GMT
Cache-Control: private, max-age=0
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
)
)
[timestamp] => 2013-06-13T12:26:25+00:00
)
I've stuck in this for 2 days and I don't know what I'm doing wrong in the request with the library. can you help me?
The library tries to get user's profile, which requires userinfo.profile scope (https://www.googleapis.com/auth/userinfo.profile). Add that scope to your config and it should work.
I am using Solarium to access Solr from PHP. When I perform a normal select query using Solarium everything works fine.
Problem: When I attempt to do a MoreLikeThis query, I get the following error when trying to execute the query. What went wrong, and how can it be fixed?
Solr HTTP error: Not Found (404)
Location:
/home/mysite/public_html/application/libraries/Solarium/Result.php on line 98
PHP Code
$client = new Solarium_Client($config);
$query = $client->createMoreLikeThis()
->setQuery('id:' . $product_id)
->setMltFields('title, description')
->setMinimumDocumentFrequency(1)
->setMinimumTermFrequency(1)
->setInterestingTerms('details')
->setMatchInclude(false)
->setRows(10);
$resultset = $client->select($query);
I probed into the Solarium_Client_Response_Object at /solarium/Client.php and found the response received to be
Solarium_Client_Response Object
(
[_headers:protected] => Array
(
[0] => HTTP/1.1 404 Not Found
[1] => Server: Apache-Coyote/1.1
[2] => Content-Type: text/html;charset=utf-8
[3] => Content-Length: 979
[4] => Date: Mon, 27 Aug 2012 12:03:42 GMT
[5] => Connection: close
)
[_body:protected] =>
[_statusCode:protected] => 404
[_statusMessage:protected] => Not Found
)
You need to have the morelikethis handler configured in Solr. You probably have a select handler, so the standard select works. But for the morelikethis querytype you need to have another handler configured.
For more info see: http://wiki.apache.org/solr/MoreLikeThisHandler