Sidebar

How do I use the QIE Management API and curl on a Windows environment?

0 votes
311 views
asked Sep 9, 2022 by david-f-5427 (1,600 points)
The curl examples in the QIE Management API documentation fail when used on a Windows environment. Can you provide working examples for Windows?

1 Answer

0 votes

The example curl calls in the QIE Management API documentation are valid for Linux and Mac environments. Users have 3 options for using the curl utility on a Windows environment for making calls to the QIE Management API.

1) Windows command-line

The curl utility is included on all versions of Windows as of build 17063 (see https://docs.microsoft.com/en-us/virtualization/community/team-blog/2017/20171219-tar-and-curl-come-to-windows). 

Here's a sample call:

curl -H "apiToken:abc123" --request POST http://qieserver:9999/channel/start -d "{\"zoneName\":\"myZoneName\",\"channelName\":\"myChannelName\"}"

NOTES:
    - must wrap entire -d payload in double quotes
    - must use escaped double quotes for JSON key/value pairs inside the -d payload

2) Cygwin

The syntax for making calls to the curl utility in cygwin are the same as described above for Windows command-line. You will need to download and install Cygwin.

3) Windows Powershell

Invoking curl from a Windows Powershell is actually an alias to Powershell's Invoke-WebRequest utility. This utility requires a different syntax for calls and returns a different payload.

Here's a sample call:

curl -H @{"apiToken"="abc123"} -Method POST http://qieserver:9999/channel/start -Body '{"zoneName":"myZoneName","channelName":"myChannelName"}' | Select-Object -Expand RawContent

NOTES:
    - must specify -Method POST instead of --request POST
    - must specify -Body instead of -d
    - must wrap entire -Body payload in single quotes
    - must use double quotes for JSON key/value pairs inside the -Body payload
    - must pipe to Select-Object -Expand RawContent to get the full payload response

Also know that you can call the Windows curl command-line utility (outlined in step #1 above) from Powershell by invoking curl.exe instead of just curl.

answered Sep 9, 2022 by david-f-5427 (1,600 points)
...