fillup / walmart-partner-api-sdk-php

PHP client for Walmart Partner APIs
MIT License
37 stars 51 forks source link

Trying to get first test script running #30

Closed mgatten closed 7 years ago

mgatten commented 7 years ago

I'm just starting an integration project, and I came across your library. Thank you SO MUCH for doing all the heavy lifting!

Just to confirm connectivity, I wrote a quick test script. It's getting a 401, and I'm not sure where to start troubleshooting. Perhaps you have a suggestion?

<?php
putenv("CONSUMER_ID=b8e189....."); // Truncated for security                      
putenv("PRIVATE_KEY=MIICdw....."); // Truncated for security                      

require("vendor/autoload.php");
use Walmart\Feed;

$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);
?>

The output generated when I run that from the command line:

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/mbws/public_html/commhub/chtg/walmart/api/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:89
Stack trace:
#0 /home/mbws/public_html/commhub/chtg/walmart/api/vendor/guzzlehttp/guzzle/src/Subscriber/HttpError.php(33): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Message\Request), Object(GuzzleHttp\Message\Response))
#1 /home/mbws/public_html/commhub/chtg/walmart/api/vendor/guzzlehttp/guzzle/src/Event/Emitter.php(108): GuzzleHttp\Subscriber\HttpError->onComplete(Object(GuzzleHttp\Event\CompleteEvent), 'complete')
#2 /home/mbws/public_html/commhub/chtg/walmart/api/vendor/guzzlehttp/guzzle/src/RequestFsm.php(91): GuzzleHttp\Event\Emitter->emit('complete', Object(GuzzleHttp\Event\CompleteEvent))
#3 /home/mbws/public_html/commhub/chtg/walmart/api/vendor/guzzlehttp/g in /home/mbws/public_html/commhub/chtg/walmart/api/vendor/guzzlehttp/command/src/AbstractClient.php on line 171

By putting a "die()" in various spots, I've confirmed that this is being generated by the "$feeds = $client..." command. The script remains silent up to that point.

What am I missing?

timdev commented 7 years ago

The exception is being thrown because the remote end is returning a 401. There's likely something going on with your consumerId or private key.

mjmmagic commented 7 years ago

I am having the same error. Did you ever figure it out? (All I did was install the latest 1.0.9 version of this SDK, and then use your same test file with my ID and Key credentials. I get the same error and can't figure out why.

Anyone offer any solutions?

fillup commented 7 years ago

Are you sure the consumerId and secret you are using is for the staging environment? You should have different credentials for staging and production but they are probably not the same.

One other factor can be if your server is not properly configured for internet time and is off a bit. The auth signature that is generated is based on the current time, so if you're off even by a couple seconds it will be wrong to Walmart.

fillup commented 7 years ago

I found out that developers are never given keys to the staging environment, so that explains why you're getting errors there. Can you try removing the environment argument or change it to Feed::ENV_PROD and see if you still get errors?