Walmart API integration with Laravel 7 and automatic digital signature creation
10:26 03 Aug 2020

I am working on Walmart API integration using Laravel 7. I have installed GuzzleHttp as well. I used DigitalSignatureUtil.jar to generate WM_SEC.AUTH_SIGNATURE and WM_SEC.TIMESTAMP. It works fine to fetch data in JSON the first time. The following is the code:

    $client = new GuzzleHttp\Client();
    $res = $client->request('GET', 'https://marketplace.walmartapis.com/v3/feeds', [
        'headers' => [
            'WM_SVC.NAME' => 'walmart market place',
            'WM_CONSUMER.ID' => '#########',
            'WM_QOS.CORRELATION_ID' => '########',
            'WM_CONSUMER.CHANNEL.TYPE' => '######',               
            'WM_SEC.AUTH_SIGNATURE' => '#######',
            'WM_SEC.TIMESTAMP' => '1596290047006',
            'Content-Type' => 'application/json',
            'Accept' => 'application/json',
        ]
    ]);
    $products = json_decode((string) $res->getBody(), true);

    return view('product', compact('products'));

Note: It gives errors if I use the code the next day or after a few minutes. I get the following error:

GuzzleHttp\Exception\ClientException
Client error: `GET https://marketplace.walmartapis.com/v3/feeds` resulted in a `401 Unauthorized` 
response: {"error": [{"code":"UNAUTHORIZED.GMP_GATEWAY_API",
"field":"UNAUTHORIZED","description":"Unauthorized","info":"Unauthorize (truncated...)

What should I do to fix this?

laravel-7 guzzle walmart-api