Support the ongoing development of Laravel.io →
Configuration Forms Laravel

I am using Guzzle 6 to update products to shopify via API. I am using async post method to upload products in bulk, but in response if any error occur in any posted requests , I am unable to find out which requests cause this error. As response come only after completion of async function. Any solution to this ? How can we find out postAsync requests cause error , so that we can store status of failed and success requests individually ? Also, post request limit is 2calls per second as per shopify.

I am using this code:

   $client = new Client();
$url = "https://optimze-test.myshopify.com/admin/api/2019-07/products.json";
        $promises = (function () use ($main_array,$client,$ShopifyHeaders,$url) {
          foreach ($main_array as $project) {
            // don't forget using generator
            yield $client->postAsync($url,['json' => $project,'headers'=>$ShopifyHeaders]);   
          }
        })();

        $eachPromise = new EachPromise($promises, [
          // how many concurrency we are use
          'concurrency' => 10,
          'fulfilled' => function (Response $response) {
            if ($response->getStatusCode() == 200) {
              $data = json_decode($response->getBody(), true);
                // processing response of user here
                echo "successes";
                Log::info('success::'.$data);
              }
            },
          'rejected' => function ($reason) {
            // handle promise rejected here
            echo "fail";
            Log::info('fail::'.$reason);
          }
        ]);

        $eachPromise->promise()->wait();

Where $main_array is array of data of products to be posted .

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Rajat bajwa_rajat Joined 21 Oct 2019

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.