Simple OVHCloud API subflow

This is a very simple subflow to simplify the process of using the web api of OVH Cloud. It can be used to automate a lot of things.

firefox_2022_11_09_08-21-07_A0CIZf4NNG

image

In my case, I used it to automatically download my bills.

You can create a token here: https://www.ovh.com/auth/api/createToken

And test the api here: https://api.ovh.com/console/#/

[{"id":"a5cafc5603d78fca","type":"subflow","name":"OVH Api Request","info":"","category":"network","in":[{"x":60,"y":180,"wires":[{"id":"2488b07d4bbf5fff"}]}],"out":[{"x":1020,"y":180,"wires":[{"id":"a4581ead80dfe17d","port":0}]}],"env":[{"name":"endpoint","type":"str","value":"https://api.ovh.com/1.0","ui":{"icon":"font-awesome/fa-globe","label":{"en-US":"Endpoint"}}},{"name":"method","type":"str","value":"GET","ui":{"icon":"font-awesome/fa-globe","label":{"en-US":"Method"},"type":"select","opts":{"opts":[{"l":{"en-US":"GET"},"v":"GET"},{"l":{"en-US":"POST"},"v":"POST"},{"l":{"en-US":"PUT"},"v":"PUT"},{"l":{"en-US":"DELETE"},"v":"DELETE"}]}}},{"name":"path","type":"str","value":"/auth/details","ui":{"icon":"font-awesome/fa-link","label":{"en-US":"Path"},"type":"input","opts":{"types":["str","num","bool","json","bin","env","cred"]}}},{"name":"application_key","type":"str","value":"","ui":{"icon":"font-awesome/fa-key","label":{"en-US":"Application Key"}}},{"name":"application_secret","type":"str","value":"","ui":{"icon":"font-awesome/fa-key","label":{"en-US":"Application Secret"}}},{"name":"consumer_key","type":"str","value":"","ui":{"icon":"font-awesome/fa-key","label":{"en-US":"Consumer Key"}}}],"meta":{"module":"ovh_api_request","version":"1.0.0","author":"TheStaticTurtle <[email protected]>","desc":"OVH API Request","keywords":"ovh,api","license":"GPL-3.0"},"color":"#C0DEED","icon":"font-awesome/fa-cloud","status":{"x":660,"y":80,"wires":[{"id":"c96df7d146015e82","port":0}]}},{"id":"5b0714bf6f0dfa7e","type":"function","z":"a5cafc5603d78fca","name":"","func":"msg.headers = {}\n\nlet time = Math.round(flow.get(\"timeDelta\") + Date.now()/1000)\nmsg.timeDelta = flow.get(\"timeDelta\")\nmsg.time = time\nmsg.headers[\"X-Ovh-Timestamp\"] = time\n\nmsg.url = env.get(\"endpoint\") + msg.request_path\nmsg.method = msg.request_method\nmsg.payload = msg.body ? msg.body : \"\"\n\nmsg.application_secret = env.get(\"application_secret\")\nmsg.headers[\"X-Ovh-Application\"] = env.get(\"application_key\")\nmsg.headers[\"X-Ovh-Consumer\"] = env.get(\"consumer_key\")\n\nmsg.signature = [\n    env.get(\"application_secret\"),\n    env.get(\"consumer_key\"),\n    msg.request_method,\n    msg.url,\n    msg.body ? msg.body : \"\",\n    msg.time\n].join(\"+\")\n\nvar shasum = crypto.createHash('sha1')\nshasum.update(msg.signature)\nmsg.headers[\"X-Ovh-Signature\"] = \"$1$\" + shasum.digest('hex')\n\nmsg.request_headers = msg.headers\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"crypto","module":"crypto"}],"x":660,"y":180,"wires":[["a4581ead80dfe17d"]]},{"id":"7378689fab4d7fc7","type":"http request","z":"a5cafc5603d78fca","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://api.ovh.com/1.0/auth/time","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":410,"y":300,"wires":[["2b37591f03a22777"]]},{"id":"c96df7d146015e82","type":"status","z":"a5cafc5603d78fca","name":"","scope":null,"x":520,"y":80,"wires":[[]]},{"id":"75b21b65d565479d","type":"switch","z":"a5cafc5603d78fca","name":"Check flow.timeDelta","property":"timeDelta","propertyType":"flow","rules":[{"t":"nnull"},{"t":"null"}],"checkall":"true","repair":false,"outputs":2,"x":340,"y":180,"wires":[["5b0714bf6f0dfa7e"],["7378689fab4d7fc7"]]},{"id":"2b37591f03a22777","type":"change","z":"a5cafc5603d78fca","name":"","rules":[{"t":"set","p":"timeDelta","pt":"flow","to":"$round($number(payload) - ($millis() / 1000))\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":300,"wires":[["5b0714bf6f0dfa7e"]]},{"id":"2488b07d4bbf5fff","type":"function","z":"a5cafc5603d78fca","name":"","func":"return {\n    \"request_path\": !!msg.request_path ? msg.request_path : env.get(\"path\"),\n    \"request_method\": !!msg.request_method ? msg.request_method : env.get(\"method\"),\n    \"body\": msg.body,\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":160,"y":180,"wires":[["75b21b65d565479d"]]},{"id":"a4581ead80dfe17d","type":"http request","z":"a5cafc5603d78fca","name":"","method":"use","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":830,"y":180,"wires":[[]]}]

Flow Info

Created 2 years, 8 months ago
Rating: not yet rated

Actions

Rate:

Node Types

Core
  • change (x1)
  • function (x2)
  • http request (x2)
  • status (x1)
  • switch (x1)
Other
  • subflow (x1)

Tags

  • api
  • ovh
  • ovhcloud
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option