0

I'll be honest, I'm completely new to using cURL but do have experience using VBA.

I need to find a way to call an API using cURL (or a VBA equivalent), parse the results and pipe it into a cell. I've included an example of the API i need to use below but to be honest, i have no clue where to even start at this point! As i said before, i have experience using VBA but i have never had to call API's through it before so any advice on this would be greatly appreciated!

curl https://url.com/example/example \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $API_KEY" \
  -d '{
  "param1": "example",
  "param2": "example",
  "param3": "example",
  "param4": "example",
  "param5": "example",
  "param6": "example",
  "stop": ["example"]
}'

Thanks in advance!

smib98
  • 3
  • 1
  • Look into `XMLHTTP` request, [this](https://codingislove.com/http-requests-excel-vba/) should get you started. – Raymond Wu Jul 14 '21 at 08:45
  • Checkout [this](https://stackoverflow.com/questions/2784367/capture-output-value-from-a-shell-command-in-vba/32600510) too if it really needs to be curl. – Pᴇʜ Jul 14 '21 at 08:45
  • That first one looks perfect. Do you know how i would use the "xmlhttp.Send" to send data such as {"Text": "This is a test"}? – smib98 Jul 14 '21 at 09:59
  • @smib98 That is data sent as json so it depends on how you build your data. Typically i will build a string variable with the data in json format. There are many ways on how to do it. Search SO for examples. – Raymond Wu Jul 14 '21 at 12:01
  • @smib98 - `"{""Text"": ""This is a test""}"`, you need to double up the quote to escape it. Alternatively you can use `Chr(34)` for `"` so it will look like this: `"{" & Chr(34) & "Text" & Chr(34) & ": " & Chr(34) & "This is a test" & Chr(34) & "}"` – Raymond Wu Jul 14 '21 at 13:34
  • Similar Q: https://stackoverflow.com/questions/68245279/visual-basic-sent-data-to-api-as-json-object/68248679#68248679 – Tim Williams Jul 14 '21 at 15:02

0 Answers0