First, please note that I had to replace the URL you have in your commands with <URL> because stackexchange thought I was spamming and wouldn't let me post.
OK, you have two questions here:
1) How do you take the output of one command and make it an argument of another command?
answer: The most canonical method would be to use shell's command substitution by replacing your argument in the second command with $( <first command> ) like so:
curl -D - --request POST <URL> --data-urlencode token=$( curl -v --request POST <URL> --data-urlencode "username=usr]” --data-urlencode "password=[pass]” )
However, for readability purposes, you really should do this in separate lines by saving the output from the first command and reusing it like so:
token=$( curl -v --request POST <URL> --data-urlencode "username=usr]” --data-urlencode "password=[pass]” ) curl -D - --request POST <URL> --data-urlencode token="$token"
Also, for completeness and because you asked specifically how to "pipe", you could use the xargs command instead of shell's command substitution:
curl -v --request POST <URL> --data-urlencode "username=usr]” --data-urlencode "password=[pass]” | xargs "curl -D - --request POST <URL> --data-urlencode token="{}
However, as you noted, your output from the first command isn't quite what you're looking for as your token; thus the above solutions would not work as you expect, which brings us to your next question:
2) How can we isolate just "value_of_token" from the entire JSON output?
Without getting into some JSON API, a simple pipelining of grep, head and cut should do the job:
token=$( curl -v --request POST <URL> --data-urlencode "username=usr]” --data-urlencode "password=[pass]” ) | grep '"token":' | head -1 | cut -d ':' -f 2 | cut -d '"' -f 2 curl -D - --request POST <URL> --data-urlencode token="$token"
Note, the head -1 is just in case there happen to be multiple token lines from the output, in which case only the first is used.
You should know that this isn't a very robust solution if this application is important. If it is, you should really check the return code of and do more extensive validation of the output from the first curl command so that you don't get some unexpected results; but that would require a larger script and is beyond the scope of this question.