Basic Http request + cURL parameters

Hi!

I'm stuck in a process of accessing / making requests a testing woocommerce instance.
This allowed me to crash on a old problem I've had in node-red: how to pass cURL parameters in a call.

How do I - say - create a product?

While I'm able to authenticate and retrive the list of products, I don't understand how to pass parameters in the call, to be specific, the -d specified in the call with the json.

image

my flow:

[{"id":"153f50acda5fe0d6","type":"http request","z":"8dbd31e890d4295d","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"{{{site}}}{{{endPoint}}}","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"basic","senderr":false,"headers":[],"x":447.17896270751953,"y":905.0554389953613,"wires":[["b044df9340de714e"]]},{"id":"b044df9340de714e","type":"debug","z":"8dbd31e890d4295d","name":"","active":true,"console":"false","complete":"payload","x":578.0992164611816,"y":848.545488357544,"wires":[]},{"id":"ffb38a52daba1dd0","type":"change","z":"8dbd31e890d4295d","name":"Set Headers","rules":[{"t":"set","p":"headers","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"headers.content-type","pt":"msg","to":"application/json","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":312.0994644165039,"y":850.3637266159058,"wires":[["153f50acda5fe0d6"]]},{"id":"1730582a0669739a","type":"inject","z":"8dbd31e890d4295d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"},{"p":"endPoint","v":"/wp-json/wc/v3/products","vt":"str"},{"p":"site","v":"mySite.com","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"name\":\"Premium Quality\",\"type\":\"simple\",\"regular_price\":\"21.99\",\"description\":\"Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.\",\"short_description\":\"Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.\",\"categories\":[{\"id\":9},{\"id\":14}],\"images\":[{\"src\":\"http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg\"},{\"src\":\"http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg\"}]}","payloadType":"json","x":193.09944915771484,"y":910.3636865615845,"wires":[["ffb38a52daba1dd0"]]},{"id":"d018848cf10db5ef","type":"comment","z":"8dbd31e890d4295d","name":"Create a Product in Woocommerce","info":"","x":369.19036865234375,"y":786.4247627258301,"wires":[]}]

The -d is the data and would be passed to the http request node in msg.payload and the request should be a POST.
Something like this

[{"id":"ffb38a52daba1dd0","type":"change","z":"b9860b4b9de8c8da","name":"Set Headers","rules":[{"t":"set","p":"headers","pt":"msg","to":"{}","tot":"json"},{"t":"set","p":"headers.content-type","pt":"msg","to":"application/json","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":314.9205017089844,"y":2685.3082876205444,"wires":[["153f50acda5fe0d6"]]},{"id":"1730582a0669739a","type":"inject","z":"b9860b4b9de8c8da","name":"","props":[{"p":"payload"},{"p":"payload"},{"p":"endPoint","v":"/wp-json/wc/v3/products","vt":"str"},{"p":"site","v":"mySite.com","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{   \"name\": \"Premium Quality\",   \"type\": \"simple\",   \"regular_price\": \"21.99\",   \"description\": \"Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.\",   \"short_description\": \"Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.\",   \"categories\": [     {       \"id\": 9     },     {       \"id\": 14     }   ],   \"images\": [     {       \"src\": \"http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg\"     },     {       \"src\": \"http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg\"     }   ] }","payloadType":"json","x":195.9204864501953,"y":2745.308247566223,"wires":[["ffb38a52daba1dd0"]]},{"id":"153f50acda5fe0d6","type":"http request","z":"b9860b4b9de8c8da","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"{{{site}}}{{{endPoint}}}","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"basic","senderr":false,"headers":[],"credentials":{},"x":450,"y":2740,"wires":[["b044df9340de714e"]]},{"id":"b044df9340de714e","type":"debug","z":"b9860b4b9de8c8da","name":"","active":true,"console":"false","complete":"payload","x":580.9202537536621,"y":2683.4900493621826,"wires":[]}]

Untested.
[edit] fixed miss paste.

thanks.
I've imported your flow, and I see two payloads in the inject node.

The -d is the data and would be passed to the http request node in msg.payload and the request should be a POST .

So the -d in the cURL is basically the JSON I'm sending for creating a new product?

That will teach me to try to multi task.

Yes according to my limited read of the api.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.