marginwalker Posted November 3, 2018 Posted November 3, 2018 (edited) Hi there, I have the following workflow, and I can get the global variable "bearer" (in green) to work, but using a variable defined in args and vars (in red), I can't seem to pass it through - Any ideas? curl "https://beta.todoist.com/API/v8/tasks" \ -X POST \ --data '{"project_id": 2187691249, "content": "{query}", "due_string": "$xyz", "due_lang": "en", "priority": 4}' \ -H "Content-Type: application/json" \ -H "X-Request-Id: $(uuidgen)" \ -H "Authorization: Bearer $bearer" Would be keen to find out what I'm doing wrong here, as I can't seem to get it to work Edited November 3, 2018 by marginwalker
vitor Posted November 3, 2018 Posted November 3, 2018 Hello @marginwalker, When asking for help with a Workflow, please upload it somewhere as we can’t properly help you without access to it. Debugging can already be hard with access to the code, and you’re asking us to guess yours from a description. There are multiple places where your code or Workflow setup may be going wrong. Without looking at it we’re shooting in the dark. Read the Reporting Problems with Workflows topic, as it gives a nice overview on how to build an effective report.
marginwalker Posted November 3, 2018 Author Posted November 3, 2018 Hi @vitor - It's not really the workflow I need help with - I just don't know how to call variables into a bash script. If I have variable 'xyz' how would I call that into a bash script?
deanishe Posted November 3, 2018 Posted November 3, 2018 Your —data option is wrapped in single quotes. Bash doesn’t expand variables in single quotes.
marginwalker Posted November 3, 2018 Author Posted November 3, 2018 Thank you @deanishe - Unfortunately it needs single quotes, are there any known workarounds to this?
marginwalker Posted November 3, 2018 Author Posted November 3, 2018 Workaround found - Exported to a text file, and then ran bash file.txt - Thanks for the help
deanishe Posted November 3, 2018 Posted November 3, 2018 59 minutes ago, marginwalker said: Unfortunately it needs single quotes, are there any known workarounds to this? It doesn't need single quotes. Use double quotes and escape the other double quotes within them.
vitor Posted November 3, 2018 Posted November 3, 2018 2 minutes ago, deanishe said: Use double quotes and escape the other double quotes within them. Like so: --data "{\"project_id\": 2187691249, \"content\": \"{query}\", \"due_string\": \"$xyz\", \"due_lang\": \"en\", \"priority\": 4}" 19 minutes ago, marginwalker said: Workaround found - Exported to a text file, and then ran bash file.txt That makes no sense. There’s no reason why that would work. Also, for bash files the typical extension is sh.
marginwalker Posted November 4, 2018 Author Posted November 4, 2018 @vitor Thanks for that. I tried it your way - Unfortunately, the input needs single quotes, so escaping just isn't working. I'm getting errors every way i try. Instead what I did was build out the query with the variables using "write text file", and run it using bash. I'm not sure why you're upset that it works, but it does.
marginwalker Posted November 4, 2018 Author Posted November 4, 2018 3 hours ago, deanishe said: It doesn't need single quotes. Use double quotes and escape the other double quotes within them. I swear - as soon as I use double quotes, even with hard-coded values, I'm getting an error. Change back to single - No error.
marginwalker Posted November 4, 2018 Author Posted November 4, 2018 3 hours ago, vitor said: Like so: --data "{\"project_id\": 2187691249, \"content\": \"{query}\", \"due_string\": \"$xyz\", \"due_lang\": \"en\", \"priority\": 4}" Nevermind - FINALLY got this to work... Thanks for the help... However, I am curious - I actually quite like my workaround - What would be a reason not to use it?
deanishe Posted November 4, 2018 Posted November 4, 2018 42 minutes ago, marginwalker said: What would be a reason not to use it? It’s unnecessary. Also, we don’t understand exactly what you mean.
marginwalker Posted November 4, 2018 Author Posted November 4, 2018 (edited) @deanishe I used the "write text file" functionality like this - ({clipboard}, {time}, {date} and {query} all ignore the single quote rules) (My query was copied to the clipboard in the previous step curl "https://beta.todoist.com/API/v8/tasks" \ -X POST \ --data '{clipboard}' \ -H "Content-Type: application/json" \ -H "X-Request-Id: {time}{date}" \ -H "Authorization: Bearer {var:bearer}" The output is "task.txt" Then I use bash task.txt It runs Edited November 4, 2018 by marginwalker
deanishe Posted November 4, 2018 Posted November 4, 2018 Right, got you. You're using Alfred's macros, not shell variables. 13 minutes ago, marginwalker said: {clipboard}, {time}, {date} and {query} all ignore the single quote rules Naturally: That's a bash/shell rule. Those are Alfred macros. bash never even sees them.
vitor Posted November 4, 2018 Posted November 4, 2018 9 hours ago, marginwalker said: actually quite like my workaround - What would be a reason not to use it? 8 hours ago, deanishe said: It’s unnecessary. And it’s slower and more resource intensive (it has to save a file and call it); it’s more complex (needs extra steps and extra Alfred nodes); and goes against convention (using a txt) making it harder for others (or you in the future) to debug.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now