Curl Execute Command

Post Reply
Farva
Newbie
Posts: 7
Joined: Wed Jul 07, 2021 11:14 pm

Curl Execute Command

Post by Farva »

I am having trouble getting my curl commands to go through succesully using the execute command element. Below is the curl and a image of the element settings. Also is there a way to execute a curl command and get a json back using execute command element?

C:\curl.exe -k --location --request PATCH "https://websitename.com/fmi/data/v1/dat ... /records/1" --header "Content-Type: application/json" --header "Authorization: Bearer 9115494870f34db8ba58855895b92e65303eade4defff2c22223" --data-raw "{\"fieldData\": {\"Switch_AutoGLO_InProcess\": "2"}}"
Screen Shot 2021-07-21 at 2.43.52 PM.png
Screen Shot 2021-07-21 at 2.43.52 PM.png (42.18 KiB) Viewed 4986 times
freddyp
Advanced member
Posts: 1008
Joined: Thu Feb 09, 2012 3:53 pm

Re: Curl Execute Command

Post by freddyp »

For longer and more complex commands it is recommended to use a .bat file. Place the command in a .bat file and in "Command or path" point to that file.

In order to get the JSON output into a file you must specify an output file and the path to the output file has to come from Switch as a parameter and then you have to tell Switch to continue with that output file:
  • Add --output %1 to the curl command in the .bat file
  • In the "Arguments" property specify: "%2" (the quotes are important to avoid problems with spaces)
  • In the "Output" property choose "File at path" so Switch knows that the command will output a file and not a folder, or nothing, or display some other behavior
Why %1 in the .bat file and %2 in the Arguments? %2 in the Arguments is a variable that will be replaced by Switch by a path to a file (check out the tooltip help for a description of the 3 possibilities). When passing arguments to a .bat file separated by spaces the first argument is %1 inside the .bat file, the second one %2 etc. As the Switch %2 is the first (and only) argument its value is represented by %1 in the .bat file.
jan_suhr
Advanced member
Posts: 586
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: Curl Execute Command

Post by jan_suhr »

And if you need to create the .bat file on the fly with Switch variables you can use this app to make .bat files and then run them with Execute Command.

https://www.enfocus.com/en/appstore/pro ... and-friend
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps
Farva
Newbie
Posts: 7
Joined: Wed Jul 07, 2021 11:14 pm

Re: Curl Execute Command

Post by Farva »

I do need to use variables in the .bat file. Do you have a example of how to set up the execute command to use the output from the command line friend?
jan_suhr
Advanced member
Posts: 586
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: Curl Execute Command

Post by jan_suhr »

The resulting .bat file is used as a command in Execute Command.

See attached flow. You save the .bat file to a folder on disc and Execute Command picks it up from there and run the .bat
In the example I use a .sh file (Shell script)

The Hold Job elements is there for the job to wait for the script file to be generated. It has a delay for 3 seconds.

The Inject Job at the end deletes the .bat file from the folder on disc after execution.
Snag_f744125.png
Snag_f744125.png (49.9 KiB) Viewed 4960 times
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps
Post Reply