Closed mjmmagic closed 7 years ago
Hi @mjmmagic, the warning about guzzle/guzzle
is actually because a dev dependencies dependency, in satooshi/php-coveralls: 1.0.1
requires it, so you can ignore the warning. That library is only used to report code coverage metrics when my unit tests run on travis-ci, so your usage of fillup/walmart-partner-api-sdk-php
does not use guzzle/guzzle
itself at all.
The white page is probably a server error and your php is properly configured not to display errors, so check the apache error log and see what is happening there. The 401 is due to invalid credentials but can also be caused by a server that is not properly configured for network time and its time is off, so the signature calculation is off and then not considered valid by Walmart. If the error in your apache error log is not helpful for you, let me know what it says and I'll see if I can tell any better.
Thank you for trying to help. I ended up going to my log files (/usr/local/apache/logs), but I don't see any errors when I get a white page.
I even zeroed out the file with the command
error_log
And then re-accessed the FeedTest.php. Got a white page again, but nothing written to that log file above.
Just to make sure we are on the same page, this is the file I am running:
<?php
namespace WalmartTests;
include __DIR__ . '/../vendor/autoload.php';
use GuzzleHttp\Command\Exception\CommandClientException;
use Sil\PhpEnv\Env;
use Walmart\Feed;
class FeedTest extends \PHPUnit_Framework_TestCase
{
public $config = [];
public $proxy = null;
//public $proxy = 'tcp://localhost:8888';
public $verifySsl = false;
public $env = Feed::ENV_MOCK;
public $debugOutput = false;
public function __construct()
{
$this->config = [
'max_retries' => 0,
'http_client_options' => [
'defaults' => [
'proxy' => $this->proxy,
'verify' => $this->verifySsl,
]
],
'consumerId' => Env::get('CONSUMER_ID', 'a1462bb4-7fb7-4a3.........'),
'privateKey' => Env::get('PRIVATE_KEY', 'MIICdgIBADA........'),
];
parent::__construct();
}
public function testList()
{
$client = $this->getClient();
try {
$feed = $client->list([]);
$this->debug($feed);
$this->assertEquals(200, $feed['statusCode']);
$this->assertTrue(is_numeric($feed['totalResults']));
} catch (CommandClientException $e) {
$error = $e->getResponse()->getHeader('X-Error');
$this->fail($e->getMessage() . 'Error: ' . $error);
} catch (\Exception $e) {
$this->fail($e->getMessage());
}
}
public function testGet()
{
$client = $this->getClient();
try {
$feed = $client->get([
'feedId' => '1898c657-085c-4761-95fa-4ae515025e87',
'includeDetails' => 'true',
]);
$this->debug($feed);
$this->assertEquals(200, $feed['statusCode']);
$this->assertEquals('PROCESSED', $feed['feedStatus']);
} catch (CommandClientException $e) {
$error = $e->getResponse()->getHeader('X-Error');
$this->fail($e->getMessage() . 'Error: ' . $error);
} catch (\Exception $e) {
$this->fail($e->getMessage());
}
}
public function testGetFeedItem()
{
$client = $this->getClient();
try {
$feed = $client->getFeedItem([
'feedId' => '09a3f1b2-3852-4b87-b7e4-2715b3d7a52e',
'includeDetails' => 'true',
'limit' => 3,
]);
$this->debug($feed);
$this->assertEquals(200, $feed['statusCode']);
$this->assertEquals('INPROGRESS', $feed['meta']['feedStatus']);
$this->assertEquals(3, count($feed['elements']['itemDetails']['itemIngestionStatus']));
} catch (CommandClientException $e) {
$error = $e->getResponse()->getHeader('X-Error');
$this->fail($e->getMessage() . 'Error: ' . $error);
} catch (\Exception $e) {
$this->fail($e->getMessage());
}
}
private function getClient($extraConfig = [])
{
$config = array_merge_recursive($this->config, $extraConfig);
return new Feed($config, $this->env);
}
private function debug($output)
{
if ($this->debugOutput) {
fwrite(STDERR, print_r($output, true));
}
}
}
Do you think there is any sort of "echo" code I should put in there to determine where it may be failing?
ALSO now that I think about it...... I should mention that our account has NO FEEDS right now, maybe that is the problem? LOL I just assumed that even with zero feeds, the test script would display something!
ahh, that file is a unit test, it is intended to be run by the phpunit command line tool. So it wont work for you to call it from a browser. Also that test is in "mock mode" so it is going to use mocked responses so it wont call Walmart with your credentials.
Are you just trying to test out your credentials to see if you can get results? If so try something like:
<?php
include __DIR__ . '/vendor/autoload.php';
use Walmart\Feed;
$client = new Feed([
'consumerId' => getenv('CONSUMER_ID'),
'privateKey' => getenv('PRIVATE_KEY'),
]);
$feeds = $client->list([
'limit' => 50, // optional, default 50
'offset' => 0, // optional, default 0
]);
print_r($feeds);
The unit tests can be used for reference and with some tweaking can be used to test your account, but you might be better off checking out the usage examples under https://github.com/fillup/walmart-partner-api-sdk-php/tree/develop/docs for how to use the library with your own account.
Thank you for trying to help. You totally rock. Well, I tried the following code in a file I labeled test.php in the root directory of the SDK:
<?php
putenv("CONSUMER_ID=a1462bb4-7fb7-4a3*******");
putenv("PRIVATE_KEY=MIICdgIBADANBgkqhkiG9******");
require("vendor/autoload.php");
use Walmart\Feed;
$client = new Feed([
'consumerId' => getenv('CONSUMER_ID'),
'privateKey' => getenv('PRIVATE_KEY'),
]);
$feeds = $client->list([
'limit' => 50, // optional, default 50
'offset' => 0, // optional, default 0
]);
print_r($feeds);?>
In fact, if you want, you can run the same exact script from this URL: http://www.mjmmagic.com/store/backorder/Walmart/test.php
As you can see (at the time of this posting), this is the error that comes up:
Fatal error: Uncaught exception 'GuzzleHttp\Exception\ClientException' with message 'Client error response [url] https://marketplace.walmartapis.com/v2/feeds?limit=50&offset=0 [status code] 401 [reason phrase] Unauthorized' in /home/mjmmagic/public_html/store/backorder/Walmart/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:89 Stack trace: #0 /home/mjmmagic/public_html/store/backorder/Walmart/vendor/guzzlehttp/guzzle/src/Subscriber/HttpError.php(33): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Message\Request), Object(GuzzleHttp\Message\Response)) #1 /home/mjmmagic/public_html/store/backorder/Walmart/vendor/guzzlehttp/guzzle/src/Event/Emitter.php(108): GuzzleHttp\Subscriber\HttpError->onComplete(Object(GuzzleHttp\Event\CompleteEvent), 'complete') #2 /home/mjmmagic/public_html/store/backorder/Walmart/vendor/guzzlehttp/guzzle/src/RequestFsm.php(91): GuzzleHttp\Event\Emitter->emit('complete', Object(GuzzleHttp\Event\CompleteEvent)) #3 /home/mjmmagic/public_html/store/backorder/Walmart/vendor/g in /home/mjmmagic/public_html/store/backorder/Walmart/vendor/guzzlehttp/command/src/AbstractClient.php on line 171
And yes, my basic goal is to run these scripts from my browser via a POST command. I will have a CRON job call a function to update our Walmart inventory, so I am just trying to get a BASIC PHP example to authenticate so I can then have something to work with.
If I can get a basic authentication to happen, then I will have something to build on. My only goal is to make a PHP file that can both list released Walmart orders, and a separate function which can send updated inventory counts back to Walmart to adjust our inventory.
I think if you can help me get over these Guzzle Related errors above so that the Feed test works, then I may be able to run with the rest of it.
The 401 error is an authentication error. Basically Walmart says you didn't provide a valid signature. The signature is a calculation based on your clientId, the API call method, the full request url, and the current time in microseconds. Based on your code above you are not specifying which environment at Walmart to call, so it will default to production. Can you double check your consumerId and private key to ensure they are the right values for production? Also just for testing, what if rather than setting them using putenv
and then calling getenv
later you just set the values directly when instantiating the Feed class? Also, just for testing, try some other object, like getting a list of Orders or Items. There can be an auth issue when paginating through items, but I'm not aware of it with Feeds, but it would be good for you to try a couple other APIs just to be sure.
Hi Phillip - Sorry it took a couple days to get back to you, but we were busy trying to add some products to Walmart. I still need help on this issue.
FIRST OF ALL - I should mention that we are NOT a live account yet. We are still unpublished as a brand new account.
ALSO - I don't know if this means anything, but under our Consumer ID and Security Key area, there is something that says:
If you are integrating with Walmart's APIs directly, please pass 0f3e4dd4-0514-4346-b39d-af0e00ea066d as the WM_CONSUMER.CHANNEL.TYPE API header.
Again, not sure if that is something that is needed with your SDK, because the only thing I've ever seen in your files is the Consumer ID and Private Key variables.
Anyway, here is a breakdown of the test I am doing, which I cannot get to work.
I have an item in my account with a status of "stage":
Screenshot: https://s29.postimg.org/rjbj0hqzb/12_7_2016_4_46_05_PM.png
I then made this test PHP file which I am calling from the browser:
<?php
require("vendor/autoload.php");
use Walmart\Item;
$client = new Item([
'consumerId' => 'a1462bb4-7fb7-4.........',
'privateKey' => 'MIICdgIBADANBgkqhkiG9w0BAQ.........',
]);
$items = $client->list([
'sku' => '346', // optional
'limit' => 20, // optional, default is 20
'offset' => 0, //optional, default is 0
]);
Item::ENV_STAGE;
print_r($items);?>
Notice a couple of things:
When I call the script , I am still getting the same error:
Fatal error: Uncaught exception 'GuzzleHttp\Exception\ClientException' with message 'Client error response [url] https://marketplace.walmartapis.com/v2/items?sku=346&limit=20&offset=0 [status code] 401 [reason phrase] Unauthorized' in /home/mjmmagic/public_html/store/backorder/Walmart/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:89 Stack trace: #0 /home/mjmmagic/public_html/store/backorder/Walmart/vendor/guzzlehttp/guzzle/src/Subscriber/HttpError.php(33): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Message\Request), Object(GuzzleHttp\Message\Response)) #1 /home/mjmmagic/public_html/store/backorder/Walmart/vendor/guzzlehttp/guzzle/src/Event/Emitter.php(108): GuzzleHttp\Subscriber\HttpError->onComplete(Object(GuzzleHttp\Event\CompleteEvent), 'complete') #2 /home/mjmmagic/public_html/store/backorder/Walmart/vendor/guzzlehttp/guzzle/src/RequestFsm.php(91): GuzzleHttp\Event\Emitter->emit('complete', Object(GuzzleHttp\Event\CompleteEvent)) #3 /home/mjmmagic/public_html/store/backorder/Walmart/ in /home/mjmmagic/public_html/store/backorder/Walmart/vendor/guzzlehttp/command/src/AbstractClient.php on line 171
Hopefully, if you can help me get passed this silly error, I think we can make some progress on this thing! Just a working test script above (to return a single item) would be amazing if we can get it working.
Please let me know if there is anything else we can provide you to help troubleshoot this!
Oh ok, so if you're still in staging you need to tell the SDK to use the staging environment. Staging and production have different domains for calling the API. In your example above try changing to:
$client = new Item(
[
'consumerId' => 'a1462bb4-7fb7-4.........',
'privateKey' => 'MIICdgIBADANBgkqhkiG9w0BAQ.........',
],
Item::ENV_STAGE
);
I did that.......still no go. At first, if you see the code above (in my previous post), it looks like I had the Item::ENV_STAGE in the wrong part of the code. So I changed it with high hopes, but it looks like the same error.
My current code now looks like this:
<?php
require("vendor/autoload.php");
use Walmart\Item;
$client = new Item(
[
'consumerId' => 'a1462bb4-7fb7-4a........',
'privateKey' => 'MIICdgIBADANBgkqhki..........',
],
Item::ENV_STAGE
);
$items = $client->list([
'sku' => '346', // optional
'limit' => 20, // optional, default is 20
'offset' => 0, //optional, default is 0
]);
print_r($items);?>
The error message is still the following:
Fatal error: Uncaught exception 'GuzzleHttp\Exception\ClientException' with message 'Client error response [url] https://marketplace.stg.walmartapis.com/v2/items?sku=346&limit=20&offset=0 [status code] 401 [reason phrase] Unauthorized' in /home/mjmmagic/public_html/store/backorder/Walmart/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:89 Stack trace: #0 /home/mjmmagic/public_html/store/backorder/Walmart/vendor/guzzlehttp/guzzle/src/Subscriber/HttpError.php(33): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Message\Request), Object(GuzzleHttp\Message\Response)) #1 /home/mjmmagic/public_html/store/backorder/Walmart/vendor/guzzlehttp/guzzle/src/Event/Emitter.php(108): GuzzleHttp\Subscriber\HttpError->onComplete(Object(GuzzleHttp\Event\CompleteEvent), 'complete') #2 /home/mjmmagic/public_html/store/backorder/Walmart/vendor/guzzlehttp/guzzle/src/RequestFsm.php(91): GuzzleHttp\Event\Emitter->emit('complete', Object(GuzzleHttp\Event\CompleteEvent)) #3 /home/mjmmagic/public_html/store/backorder/Walm in /home/mjmmagic/public_html/store/backorder/Walmart/vendor/guzzlehttp/command/src/AbstractClient.php on line 171
As you can see from my prior screenshot (https://s29.postimg.org/rjbj0hqzb/12_7_2016_4_46_05_PM.png), the item clearly says "stage" for the status, so I assume that means my account is allowed to make API calls towards it.
And in case it helps, here is what my install directory looks like (so you can see the folders present, and the relative location of my test file):
At this point my only thoughts are:
Hi Phillip - I checked and the ntpd service IS running on our server. It's running with the following command line:
ntpd -u ntp:ntp -p /var/run/ntpd.pid -g
I guess at this point, I wouldn't mind emailing you my credentials just to see if you can get a sample test script for me to try. I am using the most basic script right now, and I still can't explain why it's not authenticating. We are now a LIVE PRODUCTION site on Walmart, and I just regenerated my Secret Key to try from scratch. It still throws the error:
Fatal error: Uncaught exception 'GuzzleHttp\Exception\ClientException' with message 'Client error response [url] https://marketplace.walmartapis.com/v2/items?sku=335&limit=20&offset=0 [status code] 401 [reason phrase] Unauthorized' in /home/mjmmagic/public_html/store/backorder/Walmart/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:89 Stack trace: #0 /home/mjmmagic/public_html/store/backorder/Walmart/vendor/guzzlehttp/guzzle/src/Subscriber/HttpError.php(33): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Message\Request), Object(GuzzleHttp\Message\Response)) #1 /home/mjmmagic/public_html/store/backorder/Walmart/vendor/guzzlehttp/guzzle/src/Event/Emitter.php(108): GuzzleHttp\Subscriber\HttpError->onComplete(Object(GuzzleHttp\Event\CompleteEvent), 'complete') #2 /home/mjmmagic/public_html/store/backorder/Walmart/vendor/guzzlehttp/guzzle/src/RequestFsm.php(91): GuzzleHttp\Event\Emitter->emit('complete', Object(GuzzleHttp\Event\CompleteEvent)) #3 /home/mjmmagic/public_html/store/backorder/Walmart/ in /home/mjmmagic/public_html/store/backorder/Walmart/vendor/guzzlehttp/command/src/AbstractClient.php on line 171
This is the link to that product id (SKU 335): https://www.walmart.com/ip/Encyclopedia-of-Pickpocketing-DVD-1-by-Byrd-and-Coats/102707565
I think this was resolved.
Hey there, what was the resolution? Was it simply an api key issue? I'm receiving the same error (on osx dev bed, building on top of a laravel install).
Technically, I never did solve the issue. If I try to run this script on my Apache web server (hosted remotely), I get these 401 errors. I never could get a resolution to it.
However, if I run the same exact script from my local Windows machine (not a remote web server), then it works fine.
So that is how I have been using it. On my local windows machine, I just call a Scheduled Task every hour to call the script and update my Walmart inventory. I no longer bother trying to get it to work on my remote Apache server, because of these errors.
Thanks, that was useful to know, thanks for the reply. I had my hopes up, and pushed the code over to a centos server with the hopes it would work there, no go unfortunately. Was your composer.json the same between windows and linux builds?
I had the same guzzle warning as well, by the way.
Mine is hitting the Walmart staging server and failing with authorization, code here:
$client = new Feed([
'consumerId' => getenv('CONSUMER_ID'),
'privateKey' => getenv('PRIVATE_KEY'),
], Feed::ENV_STAGE);
$feeds = $client->list([
'limit' => 50, // optional, default 50
'offset' => 0, // optional, default 0
]);
print_r($feeds);
die;
Then errors out with with a similar, by not exactly the same:
CommandClientException in AbstractClient.php line 171: Error executing command: Client error response [url] https://marketplace.stg.walmartapis.com/v2/feeds?limit=50&offset=0 [status code] 401 [reason phrase] Unauthorized
in AbstractClient.php line 171
at AbstractClient->createCommandException(object(CommandTransaction)) in AbstractClient.php line 253
at AbstractClient->GuzzleHttp\Command\{closure}(object(EndEvent), 'end') in Emitter.php line 108
at Emitter->emit('end', object(EndEvent)) in RequestFsm.php line 140
at RequestFsm->__invoke(object(Transaction)) in RequestFsm.php line 132
at RequestFsm->GuzzleHttp\{closure}(array('transfer_stats' => array('url' => 'https://marketplace.stg.walmartapis.com/v2/feeds?limit=50&offset=0', 'content_type' => 'application/xml;charset=ISO-8859-1', 'http_code' => '401', 'header_size' => '175', 'request_size' => '503', 'filetime' => '-1', 'ssl_verify_result' => '0', 'redirect_count' => '0', 'total_time' => '0.412601', 'namelookup_time' => '0.003257', 'connect_time' => '0.08176', 'pretransfer_time' => '0.327751', 'size_upload' => '0', 'size_download' => '402', 'speed_download' => '974', 'speed_upload' => '0', 'download_content_length' => '402', 'upload_content_length' => '-1', 'starttransfer_time' => '0.412518', 'redirect_time' => '0', 'redirect_url' => '', 'primary_ip' => '161.170.236.48', 'certinfo' => array(), 'primary_port' => '443', 'local_ip' => 'nerfed', 'local_port' => '59456', 'error' => '', 'errno' => '0'), 'curl' => array('error' => '', 'errno' => '0'), 'effective_url' => 'https://marketplace.stg.walmartapis.com/v2/feeds?limit=50&offset=0', 'headers' => array('Cache-Control' => array('no-cache'), 'Content-Type' => array('application/xml;charset=ISO-8859-1'), 'Content-Length' => array('402'), 'Date' => array('Sat, 06 May 2017 21:14:09 GMT'), 'Server' => array('web')), 'version' => '1.1', 'status' => '401', 'reason' => 'Unauthorized', 'body' => resource)) in FulfilledPromise.php line 25
at FulfilledPromise->then(object(Closure), null, null) in CompletedFutureValue.php line 55
at CompletedFutureValue->then(object(Closure), null, null) in FutureResponse.php line 43
at FutureResponse::proxy(object(CompletedFutureArray), object(Closure)) in RequestFsm.php line 135
at RequestFsm->__invoke(object(Transaction)) in Client.php line 165
at Client->send(object(Request)) in AbstractClient.php line 88
at AbstractClient->execute(object(Command)) in AbstractClient.php line 76
at AbstractClient->__call('list', array(array('limit' => '50', 'offset' => '0'))) in ItemsController.php line 64
---etc---
@fillup - would it be possible to send any insights, please?
Okay, newbie here! Here is what I did:
php composer.phar install
I didn't open the JSON file to make any edits to whatever Phillip (original author) already had in there. Do I need to modify the composer.JSON file to add anything?
Continuing on.....
This is where I run into trouble, because I am still learning how to test this out.
I first tried to run the tests/FeedTest.php script which came with this project. All I did was edit my own Private Key and Consumer ID in the script, and then ran it. Result = BLANK WHITE Page. No errors, no output, nothing. Shouldn't it output something?
Second, instead of using the pre-included FeedTest.php script, I used this basic one I saw from another GitHub post:
However, that outputs this 401 error that I see in a few other posts (but without a clear resolution that I could find):
Fatal error: Uncaught exception 'GuzzleHttp\Exception\ClientException' with message 'Client error response [url] https://marketplace.stg.walmartapis.com/v2/feeds?limit=50&offset=0 [status code] 401 [reason phrase] Unauthorized' in /home/mjmmagic/public_html/store/backorder/Walmart/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:89 Stack trace: #0 /home/mjmmagic/public_html/store/backorder/Walmart/vendor/guzzlehttp/guzzle/src/Subscriber/HttpError.php(33): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Message\Request), Object(GuzzleHttp\Message\Response)) #1 /home/mjmmagic/public_html/store/backorder/Walmart/vendor/guzzlehttp/guzzle/src/Event/Emitter.php(108): GuzzleHttp\Subscriber\HttpError->onComplete(Object(GuzzleHttp\Event\CompleteEvent), 'complete') #2 /home/mjmmagic/public_html/store/backorder/Walmart/vendor/guzzlehttp/guzzle/src/RequestFsm.php(91): GuzzleHttp\Event\Emitter->emit('complete', Object(GuzzleHttp\Event\CompleteEvent)) #3 /home/mjmmagic/public_html/store/backorder/Walmart/vend in /home/mjmmagic/public_html/store/backorder/Walmart/vendor/guzzlehttp/command/src/AbstractClient.php on line 171
Any idea what I can do to fix this?