fillup / walmart-partner-api-sdk-php

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

Can't fetch new orders #4

Closed compujo closed 8 years ago

compujo commented 8 years ago

I'm trying to fetch new orders, but it's failing for both production and mock environments

use Walmart\Order;

$client = new Order([
  'consumerId' => $settings['walmartConsumerId'],
  'privateKey' => $settings['walmartPrivateKey'],
  'wmConsumerChannelType' => $settings['walmartChannelType'],
],Order::ENV_MOCK);

try {
  $resultsArr = $client->listReleased([
      'createdStartDate' => '2016-06-01', // optional
      'limit' => 10, // optional, default 10
      //'nextCursor' => '', // optional, value comes from previous call, used for pagination
  ]);
}
catch (Exception $e) {
  die("There was a problem requesting the data: ".$e->getMessage());
}

print_r($resultsArr);

Error:

There was a problem requesting the data: Error executing command: Client error response [url] /v3/orders/released?limit=10&createdStartDate=2016-06-01 [status code] 400 [reason phrase] Bad Request

Error for production:

There was a problem requesting the data: Error executing command: Client error response [url] https://marketplace.walmartapis.com/v3/orders/released?limit=10&createdStartDate=2016-06-01 [status code] 404 [reason phrase] Not Found

I figure the error in production could be because we don't have any orders yet (account is not fully launched since we don't have the API client set up), but I'm not sure what's wrong with the Mock environment... do I have to add the mock responses myself somewhere?

Update: Mock environment works with $client->list(), but not if I add 'status' => 'Created', as a parameter

  //Bad request
  $resultsArr = $client->list([
    'createdStartDate' => '2016-06-01', // required
    'status' => 'Created', //optional
    'limit' => 10, // optional, default 10
    //'nextCursor' => '', // optional, value comes from previous call, used for pagination
  ]);

  //Works with Mock
  $resultsArr = $client->list([
    'createdStartDate' => '2016-06-01', // required
    'limit' => 10, // optional, default 10
    //'nextCursor' => '', // optional, value comes from previous call, used for pagination
  ]);
fillup commented 8 years ago

@compujosh If you don't have orders it will return a 404. It should probably return a 200 with an empty result set since the URI/Resource is valid but there are no results, unfortunately that is not the case.

As for the mock environment it works by matching exact request URLs + Method in the mock data files. You can update the files in src/mock/ to add or update urls for your testing. It is not the most robust mock environment but provides the ability to setup different responses based on different parameters.

compujo commented 8 years ago

Alright, is there a preferred way to check for a 404/no orders? like a PageNotFoundException or something

fillup commented 8 years ago

Now that I think about, just because the API has a weird behavior in this situation doesn't mean the SDK needs to follow it. I can probably refactor it to catch the exception and if 404 return a static response like below or just throw the exception. What do you think of that idea?

[
    'list' => [
        'meta' => [
            'totalCount' => 0
        ]
    ],
    'elements' => []
]

With a response like that you can either check the ['list']['meta']['totalCount'] value or just iterate over ['elements'] which would either have orders or not.

compujo commented 8 years ago

As long as you're not changing the existing structure in a way that will break existing stuff, sounds good

fillup commented 8 years ago

@compujosh I updated the library so both list() and listReleased() will return the following when the Walmart API returns a 404. Code is just in develop branch for now if you can try it out by changing your composer requirements to dev-develop and let me know if this works for you then I can release to master and bump version.

[
    'statusCode' => 200,
    'list' => [
        'meta' => [
            'totalCount' => 0
        ]
    ],
    'elements' => []
]
fillup commented 8 years ago

Hi @compujosh I went ahead and merged my changes into master and released version 1.0.3. Hopefully that will make your integration a little smoother.

nemanjatan commented 6 years ago

Hi,

I have same problem here.

When I try to use API in this way:

$client = new Order([
     'consumerId' => CONSUMER_ID,
     'privateKey' => PRIVATE_KEY,
     'wmConsumerChannelType' => WM_CONSUMER_CHANNEL_TYPE,
]);

try {
  $resultsArr = $client->listReleased([
    'createdStartDate' => '2018-03-13', // optional
    'limit' => 10, // optional, default 10
    'nextCursor' => '', // optional, value comes from previous call, used for pagination
]);
}
catch (Exception $e) {
  die("There was a problem requesting the data: ".$e->getMessage());
}

print_r($resultsArr);

I always get 400 Bad request with a bunch of GuzzleHttp\Exception\RequestException


When I delete createdStartDate, then I just get blank 200 page (and I have orders on my products, they are just not showing).

Do you know what I'm doing wrong (link to my demo page: https://nemanjatanaskovic.com/walmart/ )?

P.s. when I test orders on https://developer.walmart.com/#/explorer/order I'm also getting this 400 error (you can see screenshot on this url: https://nemanjatanaskovic.com/walmart/001.png)

Thanks for your help, Nemanja