Using an variable (array) in HTTP request

Hi,

so I’m trying to make a http request with a variable in the url, but the http request don’t work. I want to use the product_id from function2 in the second request but it keeps throwing out errors. Is the array from function2 the problem? How do I use them in the right way? If I just put in the data in the request without an expression, I get the information I want, so the url itself isn’t the problem. The workflow should get all unfulfilled orders since yesterday and search for the products. Here’s my workflow:

{
  "nodes": [
    {
      "parameters": {
        "authentication": "basicAuth",
        "url": "=https://bohme-shop.myshopify.com/admin/api/2021-04/orders.json?status=open&fulfillment_status=unfulfilled",
        "options": {},
        "queryParametersUi": {
          "parameter": []
        }
      },
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        950,
        320
      ],
      "credentials": {
        "httpBasicAuth": "Böhme.Shop"
      }
    },
    {
      "parameters": {
        "functionCode": "var d = new Date(); // Today!\nd.setDate(d.getDate() - 1); // Yesterday!\n\nitems[0].json.date_today = d;\nreturn items"
      },
      "name": "Function1",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        730,
        320
      ]
    },
    {
      "parameters": {
        "functionCode": "return items[0].json.orders.map(order => {\n  return {\n    json: order\n  }\n});\n"
      },
      "name": "Function2",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1160,
        320
      ]
    },
    {
      "parameters": {
        "authentication": "basicAuth",
        "url": "=https://bohme-shop.myshopify.com/admin/api/2021-04/products/{{$node[\"Function2\"].json[\"line_items\"][0][\"product_id\"]}}.json",
        "options": {},
        "headerParametersUi": {
          "parameter": []
        }
      },
      "name": "HTTP Request1",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1350,
        320
      ],
      "credentials": {
        "httpBasicAuth": "Böhme.Shop"
      }
    }
  ],
  "connections": {
    "HTTP Request": {
      "main": [
        [
          {
            "node": "Function2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function1": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function2": {
      "main": [
        [
          {
            "node": "HTTP Request1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

I’m new to all of this, please excuse mistakes in my workflow… :sweat_smile:
Thanks for your answers!

Hey @cvrooij!

Welcome to the community :sparkling_heart:

Is there a specific reason you’re using the HTTP Request node to fetch the products, instead of the Shopify node?

Can you also share the output of the Function2 node? Feel free to replace any sensitive information with dummy data.

Hey @harshil1712!

Thanks for your answer and the welcomes! How do I mark my workflow like you did in the edit? :thinking:

No there’s no reason, I just forgot about the shopify node… :man_facepalming:t2:
I switched the http nodes with the shopify node and the output data of the first shopify node is exactly the output data of function2, so function2 was only necessary with the http node I think. In general I add “created at min - yesterday” to the first shopify node but I left it out, to have some data I can work with. so the first function node is irrelevant for my problem I think.
My new workflow looks like this:

    {
      "nodes": [
    {
      "parameters": {
        "functionCode": "var d = new Date(); // Today!\nd.setDate(d.getDate() - 1); // Yesterday!\n\nitems[0].json.date_today = d;\nreturn items"
      },
      "name": "Function1",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        690,
        400
      ]
    },
    {
      "parameters": {
        "operation": "getAll",
        "options": {
          "fulfillmentStatus": "unfulfilled",
          "status": "open"
        }
      },
      "name": "Shopify",
      "type": "n8n-nodes-base.shopify",
      "typeVersion": 1,
      "position": [
        940,
        400
      ],
      "credentials": {
        "shopifyApi": "Böhme.Shop"
      }
    },
    {
      "parameters": {
        "resource": "product",
        "operation": "get",
        "productId": "={{$node[\"Set\"].json[\"line_items\"][0][\"product_id\"]}}",
        "additionalFields": {}
      },
      "name": "Shopify1",
      "type": "n8n-nodes-base.shopify",
      "typeVersion": 1,
      "position": [
        1180,
        400
      ],
      "credentials": {
        "shopifyApi": "Böhme.Shop"
      }
    }
      ],
      "connections": {
    "Function1": {
      "main": [
        [
          {
            "node": "Shopify",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Shopify": {
      "main": [
        [
          {
            "node": "Shopify1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
      }
    }

But it keeps showing an error message in the second node:

ERROR: Shopify error response [400]: expected String to be a id

Error: Shopify error response [400]: expected String to be a id
at Object.shopifyApiRequest (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Shopify/GenericFunctions.js:44:19)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async Object.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Shopify/Shopify.node.js:270:36)
at async /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/src/WorkflowExecute.js:416:47

I also got this error message sometimes with the http request node. The output data of the shopify node is an array with 9 items. I will post one item:

[
{

"id": 3782799229086,

"admin_graphql_api_id": "gid://shopify/Order/3782799229086",

"app_id": xx,

"browser_ip": "xx",

"buyer_accepts_marketing": false,

"cancel_reason": null,

"cancelled_at": null,

"cart_token": "xxx",

"checkout_id": 21272018911390,

"checkout_token": "xxx",

"client_details": {

"accept_language": "de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7",

"browser_height": 907,

"browser_ip": "xxx",

"browser_width": 1680,

"session_hash": null,

"user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36"

},

"closed_at": null,

"confirmed": true,

"contact_email": "e-mail",

"created_at": "2021-05-03T12:05:58+02:00",

"currency": "EUR",

"current_subtotal_price": "49.50",

"current_subtotal_price_set": {

"shop_money": {

"amount": "49.50",

"currency_code": "EUR"

},

"presentment_money": {

"amount": "49.50",

"currency_code": "EUR"

}

},

"current_total_discounts": "0.00",

"current_total_discounts_set": {

"shop_money": {

"amount": "0.00",

"currency_code": "EUR"

},

"presentment_money": {

"amount": "0.00",

"currency_code": "EUR"

}

},

"current_total_duties_set": null,

"current_total_price": "51.70",

"current_total_price_set": {

"shop_money": {

"amount": "51.70",

"currency_code": "EUR"

},

"presentment_money": {

"amount": "51.70",

"currency_code": "EUR"

}

},

"current_total_tax": "3.59",

"current_total_tax_set": {

"shop_money": {

"amount": "3.59",

"currency_code": "EUR"

},

"presentment_money": {

"amount": "3.59",

"currency_code": "EUR"

}

},

"customer_locale": "xx",

"device_id": null,

"discount_codes": [

],

"email": "xx",

"financial_status": "paid",

"fulfillment_status": null,

"gateway": "xx",

"landing_site": "/products/geschichte-der-wietzendorfer-hofe",

"landing_site_ref": null,

"location_id": null,

"name": "#xx",

"note": "",

"note_attributes": [

],

"number": 293,

"order_number": xx,

"order_status_url":"xxx",

"original_total_duties_set": null,

"payment_gateway_names": [

"paypal"

],

"phone": null,

"presentment_currency": "EUR",

"processed_at": "2021-05-03T12:05:57+02:00",

"processing_method": "express",

"reference": null,

"referring_site": "https://www.google.com/",

"source_identifier": null,

"source_name": "web",

"source_url": null,

"subtotal_price": "49.50",

"subtotal_price_set": {

"shop_money": {

"amount": "49.50",

"currency_code": "EUR"

},

"presentment_money": {

"amount": "49.50",

"currency_code": "EUR"

}

},

"tags": "xxx",

"tax_lines": [

{

"price": "3.24",

"rate": 0.07,

"title": "DE MwSt",

"price_set": {

"shop_money": {

"amount": "3.24",

"currency_code": "EUR"

},

"presentment_money": {

"amount": "3.24",

"currency_code": "EUR"

}

}

},

{

"price": "0.35",

"rate": 0.19,

"title": "DE MwSt",

"price_set": {

"shop_money": {

"amount": "0.35",

"currency_code": "EUR"

},

"presentment_money": {

"amount": "0.35",

"currency_code": "EUR"

}

}

}

],

"taxes_included": true,

"test": false,

"token": "xx",

"total_discounts": "0.00",

"total_discounts_set": {

"shop_money": {

"amount": "0.00",

"currency_code": "EUR"

},

"presentment_money": {

"amount": "0.00",

"currency_code": "EUR"

}

},

"total_line_items_price": "49.50",

"total_line_items_price_set": {

"shop_money": {

"amount": "49.50",

"currency_code": "EUR"

},

"presentment_money": {

"amount": "49.50",

"currency_code": "EUR"

}

},

"total_outstanding": "0.00",

"total_price": "51.70",

"total_price_set": {

"shop_money": {

"amount": "51.70",

"currency_code": "EUR"

},

"presentment_money": {

"amount": "51.70",

"currency_code": "EUR"

}

},

"total_price_usd": "62.15",

"total_shipping_price_set": {

"shop_money": {

"amount": "2.20",

"currency_code": "EUR"

},

"presentment_money": {

"amount": "2.20",

"currency_code": "EUR"

}

},

"total_tax": "3.59",

"total_tax_set": {

"shop_money": {

"amount": "3.59",

"currency_code": "EUR"

},

"presentment_money": {

"amount": "3.59",

"currency_code": "EUR"

}

},

"total_tip_received": "0.00",

"total_weight": 0,

"updated_at": "2021-05-03T12:06:10+02:00",

"user_id": null,

"billing_address": {

"first_name": "xx",

"address1": "xx xx",

"phone": null,

"city": "xx",

"zip": "xx",

"province": null,

"country": "xx",

"last_name": "xx",

"address2": "xx",

"company": null,

"latitude": xx,

"longitude": xx,

"name": "xx",

"country_code": "xx",

"province_code": null

},

"customer": {

"id": 5221130600606,

"email": "xx",

"accepts_marketing": false,

"created_at": "2021-05-03T12:03:06+02:00",

"updated_at": "2021-05-03T12:05:58+02:00",

"first_name": "xx",

"last_name": "xx",

"orders_count": 1,

"state": "disabled",

"total_spent": "51.70",

"last_order_id": 3782799229086,

"note": null,

"verified_email": true,

"multipass_identifier": null,

"tax_exempt": false,

"phone": null,

"tags": "",

"last_order_name": "#1293",

"currency": "EUR",

"accepts_marketing_updated_at": "2021-05-03T12:03:06+02:00",

"marketing_opt_in_level": null,

"tax_exemptions": [

],

"admin_graphql_api_id": "gid://shopify/Customer/5221130600606",

"default_address": {

"id": 6389405286558,

"customer_id": 5221130600606,

"first_name": "xx",

"last_name": "xx",

"company": null,

"address1": "xx",

"address2": "xx",

"city": "xx",

"province": null,

"country": "xx",

"zip": "xx",

"phone": null,

"name": "xx",

"province_code": null,

"country_code": "xx",

"country_name": "xx",

"default": true

}

},

"discount_applications": [

],

"fulfillments": [

],

"line_items": [

{

"id": 9848049762462,

"admin_graphql_api_id": "gid://shopify/LineItem/9848049762462",

"fulfillable_quantity": 1,

"fulfillment_service": "manual",

"fulfillment_status": null,

"gift_card": false,

"grams": 0,

"name": "Geschichte der Wietzendorfer Höfe",

"origin_location": {

"id": 1882484637755,

"country_code": "DE",

"province_code": "",

"name": "Böhme.Shop",

"address1": "xx",

"address2": "",

"city": "xx",

"zip": "xx"

},

"price": "49.50",

"price_set": {

"shop_money": {

"amount": "49.50",

"currency_code": "EUR"

},

"presentment_money": {

"amount": "49.50",

"currency_code": "EUR"

}

},

"product_exists": true,

**"product_id": 4799719145531,**

"properties": [

],

"quantity": 1,

"requires_shipping": true,

"sku": null,

"taxable": true,

"title": "Geschichte der Wietzendorfer Höfe",

"total_discount": "0.00",

"total_discount_set": {

"shop_money": {

"amount": "0.00",

"currency_code": "EUR"

},

"presentment_money": {

"amount": "0.00",

"currency_code": "EUR"

}

},

"variant_id": 33348532699195,

"variant_inventory_management": null,

"variant_title": "",

"vendor": "Böhme-Zeitung",

"tax_lines": [

{

"price": "3.24",

"price_set": {

"shop_money": {

"amount": "3.24",

"currency_code": "EUR"

},

"presentment_money": {

"amount": "3.24",

"currency_code": "EUR"

}

},

"rate": 0.07,

"title": "DE MwSt"

}

],

"duties": [

],

"discount_allocations": [

]

}

],

"refunds": [

],

"shipping_address": {

"first_name": "xx",

"address1": "xx",

"phone": null,

"city": "xx",

"zip": "xx",

"province": null,

"country": "xx",

"last_name": "xx",

"address2": "xx",

"company": null,

"latitude": 50.9205167,

"longitude": 6.4095361,

"name": "xx",

"country_code": "DE",

"province_code": null

},

"shipping_lines": [

{

"id": 3213070696606,

"carrier_identifier": null,

"code": "Buchversand",

"delivery_category": null,

"discounted_price": "2.20",

"discounted_price_set": {

"shop_money": {

"amount": "2.20",

"currency_code": "EUR"

},

"presentment_money": {

"amount": "2.20",

"currency_code": "EUR"

}

},

"phone": null,

"price": "2.20",

"price_set": {

"shop_money": {

"amount": "2.20",

"currency_code": "EUR"

},

"presentment_money": {

"amount": "2.20",

"currency_code": "EUR"

}

},

"requested_fulfillment_service_id": null,

"source": "shopify",

"title": "Buchversand",

"tax_lines": [

{

"price": "0.35",

"price_set": {

"shop_money": {

"amount": "0.35",

"currency_code": "EUR"

},

"presentment_money": {

"amount": "0.35",

"currency_code": "EUR"

}

},

"rate": 0.19,

"title": "DE MwSt"

}

],

"discount_allocations": [

]

}

]

},

{... next order

the marked (**) “product id” is the data I need for the following shopify node.

Thanks in advance!

Hey!
Can you please check the format of the output data you posted? It doesn’t seem to be correct.

I also noticed that in the Shopify1 node you’re trying to get the Product ID from a Set node, but there is no Set node present in your workflow.

You can refer to the video shared here to know how you can format the code in your post: How can I contribute? | Docs

sorry, but I’m not sure which output data you mean… :tired_face:

Yeah, I tried different ways to give the data to the shopify1 node through set (string/number) and after it didn’t worked, I forgot to change it before copying it for this post here. In my first try I used:

{
"nodes": [
{
  "parameters": {
    "resource": "product",
    "operation": "get",
    "productId": "={{$node[\"Shopify\"].json[\"line_items\"][0][\"product_id\"]}}",
    "additionalFields": {}
  },
  "name": "Shopify1",
  "type": "n8n-nodes-base.shopify",
  "typeVersion": 1,
  "position": [
    1180,
    400
  ],
  "credentials": {
    "shopifyApi": "Böhme.Shop"
  }
}
],
"connections": {}
}

Hey! Sorry I missed your reply. Were you able to solve this? If you still need help, let me know :slight_smile:

Hey! Sorry I missed your reply too! :sweat_smile: :see_no_evil: Yes, I was able to solve the problem. I’m not sure what I’ve changed back then, but it’s working fine now. Thanks for your help! @harshil1712

1 Like