Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
elburro1887 opened this issue May 8, 2023 · 16 comments · Fixed by #370
Closed

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

elburro1887 opened this issue May 8, 2023 · 16 comments · Fixed by #370
Assignees
Labels
good first issue Good for newcomers

Comments

@elburro1887
Copy link

elburro1887 commented May 8, 2023

Issue summary

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

$params = array_filter($params);

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


@elburro1887 elburro1887 changed the title Call to array_filter in Base.php removes fields that are set to 0 from request payload Fields that are set to 0 are erroneously removed from request payload $params May 8, 2023
@github-actions
Copy link

github-actions bot commented Jul 8, 2023

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.

@github-actions github-actions bot added the Stale label Jul 8, 2023
@elburro1887
Copy link
Author

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

PS: GitHub stale bot considered harmful

@github-actions github-actions bot removed the Stale label Jul 9, 2023
@github-actions
Copy link

github-actions bot commented Sep 8, 2023

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.

@github-actions github-actions bot added the Stale label Sep 8, 2023
@elburro1887
Copy link
Author

elburro1887 commented Sep 8, 2023

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

PS: GitHub stale bot considered harmful

@github-actions github-actions bot removed the Stale label Sep 9, 2023
Copy link

github-actions bot commented Nov 8, 2023

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.

@github-actions github-actions bot added the Stale label Nov 8, 2023
@elburro1887
Copy link
Author

elburro1887 commented Nov 8, 2023

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

PS: GitHub stale bot considered harmful

@github-actions github-actions bot removed the Stale label Nov 9, 2023
Copy link

github-actions bot commented Jan 9, 2024

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.

@github-actions github-actions bot added the Stale label Jan 9, 2024
@elburro1887
Copy link
Author

elburro1887 commented Jan 9, 2024

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

PS: GitHub stale bot considered harmful

@github-actions github-actions bot removed the Stale label Jan 10, 2024
Copy link

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.

@github-actions github-actions bot added the Stale label Mar 11, 2024
@elburro1887
Copy link
Author

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

PS: GitHub stale bot considered harmful

@github-actions github-actions bot removed the Stale label Mar 12, 2024
@elburro1887
Copy link
Author

The workaround here is to remove the following line

$params = array_filter($params);

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(

Copy link

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.

@github-actions github-actions bot added the Stale label May 27, 2024
@elburro1887
Copy link
Author

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

PS: GitHub stale bot considered harmful

@github-actions github-actions bot removed the Stale label May 28, 2024
Copy link

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.

@github-actions github-actions bot added the Stale label Jul 27, 2024
@elburro1887
Copy link
Author

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

PS: GitHub stale bot considered harmful

@github-actions github-actions bot removed the Stale label Jul 28, 2024
@paulomarg
Copy link
Contributor

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants