0

I am trying to push some data to my Tiddlywiki via api so I can create a new tiddler. I can pass almost all the data, but if the value "text" has spaces inside it breaks the curl command trying to pass multiple urls.

This is the actual command:

curl -X PUT -i "http://192.168.1.166:8080/recipes/default/tiddlers/$title" -H "X-Requested-With: TiddlyWiki" --data $(jq -nc --arg tags "$tag" --arg text "'${content}'" '{ $tags, $text }')

I tried at first using $variables, inside brackets, even inside multiple "'"$var"'" following others questions here. But most of them quickly recommended using jq so I gave it a try.

I learned how to create some keys with the bash¡s variables contents, and If I pipe all of this I can get it to work only if I replace spaces with other characters...I tried %20 or scaping the space \ with sed whitout success. (%20 is replaced literally so not helpful)

Any recommendations at all, I will follow any other path you could bring to it.

Thanks.

EDIT: I tried using --data-urlencode "text=${var}" but it wasnt filled, only variable expanded was the title. The others didnt show at all.

API'S INFO: https://tiddlywiki.com/static/WebServer%2520API%253A%2520Put%2520Tiddler.html

I forgot to mention that I am using zsh shell...

nerd_noob
  • 3
  • 4
  • If I'm understanding correctly I believe you are wanting to "url encode" your json string. Some good options here: [How to urlencode data for curl command?](https://stackoverflow.com/questions/296536/how-to-urlencode-data-for-curl-command) – JNevill Nov 02 '22 at 18:06
  • Thanks for your help, I tried using --data-urlencode with $vars and json strings piping jq but didnt succes. – nerd_noob Nov 02 '22 at 18:48
  • `--arg text "'${content}'"` looks like a double quoting error but we can't know what the API expects. – tripleee Nov 03 '22 at 04:33
  • I tried "${content}" too. I tried with single quotes thinking that it would expand the variable maintaning the spaces in the meantime. My actual problem is to get CURL to understand that $content is a block of text, not separated identities. Sorry for my English, I feel limited to express my difficulties. – nerd_noob Nov 03 '22 at 10:38
  • Added some info to the initial post. – nerd_noob Nov 03 '22 at 11:45

1 Answers1

0

You need to quote the output of the command substitution: --data "$(jq ...)". Without this, curl thinks the words after the first one are individual URLs to connect to. You should also remove the single quotes from --arg text "'${content}'", otherwise they'll be added to the text itself.

yut23
  • 2,624
  • 10
  • 18