400 error when using Flow, but succesfull with postman

Solved

400 error when using Flow, but succesfull with postman

drsw
New Member
7 0 0

Hi everyone,

 

As title says, I can easily POST changing inventory level through REST API (/inventory_levels/set.json) using Postman, but when it spits out error 400 Required parameter missing or invalid when running on Flow.

 

In Postman:

{
"location_id":84988625182,
"inventory_item_id":47947386061086,
"available":41
}

I originally used liquid to insert dynamic data:

{% assign inventory = lineItemsForeachitem.variant.inventoryQuantity|plus:1%}
{
"location_id":84988625182,
"inventory_item_id":{{lineItemsForeachitem.variant.inventoryItem.id|split:"/"|last}},
"available":{{inventory}}
}

(note that this HTTP request is placed after for loop)

 

And here's the error I received from Flow:

{"status":400,"response_body":"{\"errors\":{\"inventory_item_id\":\"Required parameter missing or invalid\"}}","verb":"POST","url":"https://core.sfe.shopifyinternal.com/admin/api/2024-01/inventory_levels/set.json","request_body":"\n{\"location_id\":84988625182,\"inventory_item_id\":47947386061086,\"available\":41}"}

Which is funny because that "inventory_item_id" is exactly the same as the one I sent from Postman.

 

I also tried not using any liquid when sending the HTTP request from flow, but it still spits out the same error.

 

What am I doing wrong here?

Accepted Solution (1)
DaveMcV
Shopify Staff
104 31 29

This is an accepted solution.

Hey Drsw,

 

Is your Content-Type header set to application/json?

DaveMcV | Flow Development Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.

View solution in original post

Replies 5 (5)

DaveMcV
Shopify Staff
104 31 29

Hi Drsw,

 

Looking at your error, it looks like your request is prefixed with a "\n", likely from the "assign" line if your liquid adding a newline. Replacing {% %}  with {%- -%} will remove newlines when evaluating Liquid.

Try this:

{%- assign inventory = lineItemsForeachitem.variant.inventoryQuantity|plus:1 -%}
{
"location_id":84988625182,
"inventory_item_id":{{lineItemsForeachitem.variant.inventoryItem.id|split:"/"|last}},
"available":{{inventory}}
}

 Hope that helps!

DaveMcV | Flow Development Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.
drsw
New Member
7 0 0

Hi @DaveMcV 

 

Unfortunately that didn't help.

 

I also tried going straight from `Order Fulfilled` to `Send HTTP Request` with static body like this:

{"location_id":84988625182,"inventory_item_id":47947386061086,"available":41}

But it still gives the same error:

{"status":400,"response_body":"{\"errors\":{\"inventory_item_id\":\"Required parameter missing or invalid\"}}","verb":"POST","url":"https://core.sfe.shopifyinternal.com/admin/api/2024-01/inventory_levels/set.json","request_body":"{\"location_id\":84988625182,\"inventory_item_id\":47947386061086,\"available\":41}"}

I also tried wrapping the location and inventory_item's id with double quote, that also didn't help.

 

I double-checked my token but it's correct; Postman can send the same payload with the same token.

 

Is there anything else I missed?

DaveMcV
Shopify Staff
104 31 29

This is an accepted solution.

Hey Drsw,

 

Is your Content-Type header set to application/json?

DaveMcV | Flow Development Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.
drsw
New Member
7 0 0

@DaveMcV, I am one idiot potato.

 

And you, are a legend.

DaveMcV
Shopify Staff
104 31 29

Awesome! Glad it's working. It happens to all of us 🙂 

DaveMcV | Flow Development Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.