Alteryx Server Discussions

Find answers, ask questions, and share expertise about Alteryx Server.

Invoke Alteryx Server API through Windows Command Line (cURL)

bauml003
5 - Atom

I am attempting to call an Alteryx Server App Workflow (hereto called 'myfavoriteworkflow') via the command line using cURL. The workflow requires six inputs from the user, which are available on the user's machine in an Access database. The Access database needs to be functional whilst the workflow is running (takes 20 seconds to run once it is first in queue on server, usually less than a minute from start to result, but users need to do a few things while the workflow executes) so I cannot call the workflow from there.

 

The inputs are currently writing from Access to a file called currentquery.txt. When the text of this file is placed in the Swagger API documentation, successfully executes the workflow. I am able to use cURL to call other aspects of this workflow via cURL (such as getting the questions) successfully. I am attempting to attach this output, however, my company's firewalls prevent it, so I shall paste it here instead: 

Access Output: {"questions":[{"name": "input_1","value": "93W4"},{"name": "input_2","value": "1234"},{"name": "input_3","value": "93W4REMSTD"},{"name": "input_4","value": "80105926"},{"name": "input_5", "value": "00487020160"},{"name": "input_6","value": "5236"}], "priority": "string"}

 

The API Documentation (swagger) indicates that this is the input format for the application: 

{"questions": [{"name": "string","value": "string"}],"priority": "string"}

 

A successful API query I can run (a GET request) looks like this (and successfully returns the questions for the workflow:  

curl --header "Accept: application/json" --header "Authorization:Bearer %Token%" https://alteryxserverlink.com/webapi/v1/workflows/myfavoriteworkflow/questions 
 
When I attempt to utilize the following attempts to queue and process a query using the API, I receive various errors (indented below each entry): 
Try 1: curl   -X POST     --header "Accept: application/json" --header "Authorization: Bearer %token%"        -d "%query%"     https://alteryxserverlink.com/webapi/v1/workflows/myfavoriteworkflow/jobs
%query% is the output mentioned above
Terminal Response: curl: (3) unmatched close brace/bracket in URL position 97:
Position 97 is this bracket: . . . . W4"} . . . .
 
Try 2curl -X POST --header "Accept: application/json" --header "Authorization: Bearer %token%" https://alteryxserverlink.com/webapi/v1/workflows/myfavoriteworkflow/jobs -d "{\"questions\":[{\"name\": \"input_1\",\"value\": \"93W4\"},{\"name\": \"input_2\",\"value\": \"1234\"},{\"name\": \"input_3\",\"value\": \"93W4REMSTD\"},{\"name\": \"input_4\",\"value\": \"80105926\"},{\"name\": \"input_5\", \"value\": \"00487020160\"},{\"name\": \"input_6\",\"value\": \"5236\"}], \"priority\": \"string\"}"
Terminal Response: successful query. Workflow runs, but errors since inputs are empty
 
Try 3curl -X POST --header "Accept: application/json" --header "Authorization: Bearer %token%" https://alteryxserverlink.com/webapi/v1/workflows/myfavoriteworkflow/jobs -d "{^"questions^":[{^"name^": ^"input_1^",^"value^": ^"93W4^"},{^"name^": ^"input_2^",^"value^": ^"1234^"},{^"name^": ^"input_3^",^"value^": ^"93W4REMSTD^"},{^"name^": ^"input_4^",^"value^": ^"80105926^"},{^"name^": ^"input_5^", ^"value^": ^"00487020160^"},{^"name^": ^"input_6^",^"value^": ^"5236^"}], ^"priority^": ^"string^"}"
Terminal Response: successful query. Workflow runs, but errors since inputs are empty
 
Try 4curl -X POST --header "Accept: application/json" --header "Authorization: Bearer %token%" https://alteryxserverlink.com/webapi/v1/workflows/myfavoriteworkflow/jobs -d @C:\Users\%USERNAME%\AppData\Local\AlteryxAPIConnect\currentquery.txt
Terminal Response: successful query. Workflow runs, but errors since inputs are empty
 
Try 5:  curl -X POST --header "Accept: application/json" --header "Authorization: Bearer %token%" https://alteryxserverlink.com/webapi/v1/workflows/myfavoriteworkflow/jobs -d @C:\Users\%USERNAME%\AppData\Local\AlteryxAPIConnect\currentquery.txt
In this scenario, the file has escapes for all the quotes (as in example 2). I also tried escapes for all the quotes (as in example 3). 
Terminal Response: successful query. Workflow runs, but errors since inputs are empty
 
For most of these, if I run this using --trace-ascii - tag, it shows that the data is passed as follows (and when I paste this into the swagger, sans the line numbers, it successfully queues and passes the variables: 
=> Send data, 271 bytes (0x10f)
0000: {"questions":[{"name": "input_1","value": "93W4"},{"name": "inpu
0040: t_2","value": "1234"},{"name": "input_3","value": "93W4REMSTD"},
0080: {"name": "input_4","value": "80105926"},{"name": "input_5", "val
00c0: ue": "00487020160"},{"name": "input_6","value": "5236"}], "prior
0100: ity": "string"}
 
Does anyone have a working cURL in command line that has to pass multiple variables? Does anyone have any other insights or things I could try? I have a working Python script, however, my users do not have ability to install Python due to restrictions, in addition to management preferring to stick with 'native install' methods (like command line) despite limitations. 
 
Thank you for any insights! 
4 REPLIES 4
fmvizcaino
17 - Castor
17 - Castor

Hi @bauml003 ,

 

I have never built something like this so I don`t have much to say.

But one small detail is related to the "priority": "string".

  • priority (string): Optional. Specify the priority for running the schedule. Choose from the following options: "Low", "Medium", "High", and "Critical". If not specified, the default value will be ‘Low’.

That doesn`t answer why you can run the workflow on Swagger and not through your curl process, but it is worth trying to fix.

 

Best,

Fernando Vizcaino 

gklas
6 - Meteoroid

Are you the owner of the workflow?

bauml003
5 - Atom

Yes, I am the owner of the workflow. 

gklas
6 - Meteoroid

There is a bug (fixed in next release) where you will get a 'Not Authorized' response if you are not the owner of the workflow, but you have the ability to run the workflow.  Outside of @fmvizcaino's comment on the priority setting, your json looks fine.