Shopify / shopify-api-php

MIT License
376 stars 172 forks source link

Fields that are set to 0 are erroneously removed from request payload $params #271

Open elburro1887 opened 1 year ago

elburro1887 commented 1 year ago

Issue summary

In Base.php, in the request() function, there is a call to array_filter($params).

https://github.com/Shopify/shopify-api-php/blob/b26b415b7dcdf7daf61e4b3b622ea64e30a8a916/src/Rest/Base.php#L178

If we send a payload where one of the request payload values is 0, (such as we want to set the inventory level of a product to 0, the call to array_filter() removes the entire value where 0 is set from the payload array, and thus the API will respond that the value is missing.

Expected behavior

The value containing 0 should be passed to the API request and not be removed from the request payload.

Actual behavior

The request parameter containing a "0" gets removed and we receive an error, such as: EXCEPTION encountered! REST request failed: {"available":"Required parameter missing or invalid"}

Steps to reproduce the problem

Send the following request:

use Shopify\Rest\Admin2023_01\InventoryLevel;
use Shopify\Utils;
$this->test_session = Utils::loadCurrentSession(
    $requestHeaders,
    $requestCookies,
    $isOnline
);
$inventory_level = new InventoryLevel($this->test_session);
$inventory_level->set(
    [
        "location_id" => XXXX, 
        "inventory_item_id" => YYYYYY, 
        "available" => 0 
    ],
);

The call will return with the following error: EXCEPTION encountered! REST request failed: {"available":"Required parameter missing or invalid"}

When setting available to any value > 0, we will get a successful response


github-actions[bot] commented 1 year ago

This issue is stale because it has been open for 60 days with no activity. It will be closed if no further action occurs in 14 days.

elburro1887 commented 1 year ago

Is this issue solved? there has been no response form the developers so far.

PS: GitHub stale bot considered harmful

github-actions[bot] commented 1 year ago

This issue is stale because it has been open for 60 days with no activity. It will be closed if no further action occurs in 14 days.

elburro1887 commented 1 year ago

Is this issue solved? there has been no response from the developers so far.

PS: GitHub stale bot considered harmful

github-actions[bot] commented 10 months ago

This issue is stale because it has been open for 60 days with no activity. It will be closed if no further action occurs in 14 days.

elburro1887 commented 10 months ago

Is this issue solved? there has been no response from the developers so far.

PS: GitHub stale bot considered harmful

github-actions[bot] commented 8 months ago

This issue is stale because it has been open for 60 days with no activity. It will be closed if no further action occurs in 14 days.

elburro1887 commented 8 months ago

Is this issue solved? there has been no response from the developers so far.

PS: GitHub stale bot considered harmful

github-actions[bot] commented 6 months ago

This issue is stale because it has been open for 60 days with no activity. It will be closed if no further action occurs in 14 days.

elburro1887 commented 6 months ago

Is this issue solved? there has been no response from the developers so far.

PS: GitHub stale bot considered harmful

elburro1887 commented 5 months ago

The workaround here is to remove the following line

https://github.com/Shopify/shopify-api-php/blob/c26aee5aaa3ef4e6762b375335318689e59f2714/src/Rest/Base.php#L180

Here is a patch file for v5.3.0 that was generated using https://github.com/symplify/vendor-patches

--- /dev/null
+++ ../src/Rest/Base.php
@@ -177,7 +177,6 @@

         $client = new Rest($session->getShop(), $session->getAccessToken());

-        $params = array_filter($params);
         switch ($httpMethod) {
             case "get":
                 $response = $client->get(
github-actions[bot] commented 3 months ago

This issue is stale because it has been open for 60 days with no activity. It will be closed if no further action occurs in 14 days.

elburro1887 commented 3 months ago

Is this issue solved? there has been no response from the developers so far.

PS: GitHub stale bot considered harmful

github-actions[bot] commented 1 month ago

This issue is stale because it has been open for 60 days with no activity. It will be closed if no further action occurs in 14 days.

elburro1887 commented 1 month ago

Is this issue solved? there has been no response from the developers so far.

PS: GitHub stale bot considered harmful

paulomarg commented 1 month ago

Hey, sorry for the delay in responding here. The stalebot was removed, but the issue wasn't addressed yet.

I've added it to our tracking now so we can follow it more closely, and we will look into fixing it.

Thank you for your patience on this one!