Variable in curl adds backslashes to string
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I am trying to use curl based on some variables to create customers in Stripe, but when I assign the token to a variable it is giving me an error on Stripe saying that it does not exist. However, if I put the text in directly it works. How can I use the $TOKEN
variable, is there something changing the value that I don't realize?
Michael$ curl https://api.stripe.com/v1/customers -u $access_token: -d source=tok_1CjvRiDZ5DqZ0yaUVWXXXXXX
"error":
"code": "token_already_used",
"doc_url": "https://stripe.com/docs/error-codes/token-already-used",
"message": "You cannot use a Stripe token more than once: tok_1CjvRiDZ5DqZ0yaUVWXXXXXX.",
"type": "invalid_request_error"
Michael$ curl https://api.stripe.com/v1/customers -u $access_token: -d source=$TOKEN
"error":
"code": "resource_missing",
"doc_url": "https://stripe.com/docs/error-codes/resource-missing",
"message": "No such token: "tok_1CjvRiDZ5DqZ0yaUVWXXXXXX"",
"param": "source",
"type": "invalid_request_error"
$TOKEN
is assigned like this
OUTPUT="$(curl https://api.stripe.com/v1/tokens -u $access_token: -d customer=$external_customer_id)"
TOKEN="$(echo $OUTPUT | jq .id)"
shell-script json jq
add a comment |Â
up vote
1
down vote
favorite
I am trying to use curl based on some variables to create customers in Stripe, but when I assign the token to a variable it is giving me an error on Stripe saying that it does not exist. However, if I put the text in directly it works. How can I use the $TOKEN
variable, is there something changing the value that I don't realize?
Michael$ curl https://api.stripe.com/v1/customers -u $access_token: -d source=tok_1CjvRiDZ5DqZ0yaUVWXXXXXX
"error":
"code": "token_already_used",
"doc_url": "https://stripe.com/docs/error-codes/token-already-used",
"message": "You cannot use a Stripe token more than once: tok_1CjvRiDZ5DqZ0yaUVWXXXXXX.",
"type": "invalid_request_error"
Michael$ curl https://api.stripe.com/v1/customers -u $access_token: -d source=$TOKEN
"error":
"code": "resource_missing",
"doc_url": "https://stripe.com/docs/error-codes/resource-missing",
"message": "No such token: "tok_1CjvRiDZ5DqZ0yaUVWXXXXXX"",
"param": "source",
"type": "invalid_request_error"
$TOKEN
is assigned like this
OUTPUT="$(curl https://api.stripe.com/v1/tokens -u $access_token: -d customer=$external_customer_id)"
TOKEN="$(echo $OUTPUT | jq .id)"
shell-script json jq
1
How do you assign the token to the variable. Any double quotes should not be part of the value (which they would be if you escape them).
â Kusalananda
Jul 3 at 21:15
I assign the token from a curl call, I will add the details
â Michael St Clair
Jul 3 at 21:15
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am trying to use curl based on some variables to create customers in Stripe, but when I assign the token to a variable it is giving me an error on Stripe saying that it does not exist. However, if I put the text in directly it works. How can I use the $TOKEN
variable, is there something changing the value that I don't realize?
Michael$ curl https://api.stripe.com/v1/customers -u $access_token: -d source=tok_1CjvRiDZ5DqZ0yaUVWXXXXXX
"error":
"code": "token_already_used",
"doc_url": "https://stripe.com/docs/error-codes/token-already-used",
"message": "You cannot use a Stripe token more than once: tok_1CjvRiDZ5DqZ0yaUVWXXXXXX.",
"type": "invalid_request_error"
Michael$ curl https://api.stripe.com/v1/customers -u $access_token: -d source=$TOKEN
"error":
"code": "resource_missing",
"doc_url": "https://stripe.com/docs/error-codes/resource-missing",
"message": "No such token: "tok_1CjvRiDZ5DqZ0yaUVWXXXXXX"",
"param": "source",
"type": "invalid_request_error"
$TOKEN
is assigned like this
OUTPUT="$(curl https://api.stripe.com/v1/tokens -u $access_token: -d customer=$external_customer_id)"
TOKEN="$(echo $OUTPUT | jq .id)"
shell-script json jq
I am trying to use curl based on some variables to create customers in Stripe, but when I assign the token to a variable it is giving me an error on Stripe saying that it does not exist. However, if I put the text in directly it works. How can I use the $TOKEN
variable, is there something changing the value that I don't realize?
Michael$ curl https://api.stripe.com/v1/customers -u $access_token: -d source=tok_1CjvRiDZ5DqZ0yaUVWXXXXXX
"error":
"code": "token_already_used",
"doc_url": "https://stripe.com/docs/error-codes/token-already-used",
"message": "You cannot use a Stripe token more than once: tok_1CjvRiDZ5DqZ0yaUVWXXXXXX.",
"type": "invalid_request_error"
Michael$ curl https://api.stripe.com/v1/customers -u $access_token: -d source=$TOKEN
"error":
"code": "resource_missing",
"doc_url": "https://stripe.com/docs/error-codes/resource-missing",
"message": "No such token: "tok_1CjvRiDZ5DqZ0yaUVWXXXXXX"",
"param": "source",
"type": "invalid_request_error"
$TOKEN
is assigned like this
OUTPUT="$(curl https://api.stripe.com/v1/tokens -u $access_token: -d customer=$external_customer_id)"
TOKEN="$(echo $OUTPUT | jq .id)"
shell-script json jq
edited Jul 3 at 21:30
Gilles
502k1179891515
502k1179891515
asked Jul 3 at 21:11
Michael St Clair
1084
1084
1
How do you assign the token to the variable. Any double quotes should not be part of the value (which they would be if you escape them).
â Kusalananda
Jul 3 at 21:15
I assign the token from a curl call, I will add the details
â Michael St Clair
Jul 3 at 21:15
add a comment |Â
1
How do you assign the token to the variable. Any double quotes should not be part of the value (which they would be if you escape them).
â Kusalananda
Jul 3 at 21:15
I assign the token from a curl call, I will add the details
â Michael St Clair
Jul 3 at 21:15
1
1
How do you assign the token to the variable. Any double quotes should not be part of the value (which they would be if you escape them).
â Kusalananda
Jul 3 at 21:15
How do you assign the token to the variable. Any double quotes should not be part of the value (which they would be if you escape them).
â Kusalananda
Jul 3 at 21:15
I assign the token from a curl call, I will add the details
â Michael St Clair
Jul 3 at 21:15
I assign the token from a curl call, I will add the details
â Michael St Clair
Jul 3 at 21:15
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
jq
gives the output quoted, as would be appropriate for JSON.
$ echo ' "foo": "foobar" ' | jq .foo
"foobar"
The quotes end up as part of the contents of TOKEN
, and are not removed when the variable is expanded. (They're just ordinary characters at that point.)
However, there's an option just for this:
--raw-output
/-r
:
With this option, if the filterôs result is a string then
it will be written directly to standard output rather than
being formatted as a JSON string with quotes. This can be
useful for making jq filters talk to non-JSON-based systems.
So, use TOKEN="$(echo "$OUTPUT" | jq -r .id)"
instead.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
jq
gives the output quoted, as would be appropriate for JSON.
$ echo ' "foo": "foobar" ' | jq .foo
"foobar"
The quotes end up as part of the contents of TOKEN
, and are not removed when the variable is expanded. (They're just ordinary characters at that point.)
However, there's an option just for this:
--raw-output
/-r
:
With this option, if the filterôs result is a string then
it will be written directly to standard output rather than
being formatted as a JSON string with quotes. This can be
useful for making jq filters talk to non-JSON-based systems.
So, use TOKEN="$(echo "$OUTPUT" | jq -r .id)"
instead.
add a comment |Â
up vote
2
down vote
accepted
jq
gives the output quoted, as would be appropriate for JSON.
$ echo ' "foo": "foobar" ' | jq .foo
"foobar"
The quotes end up as part of the contents of TOKEN
, and are not removed when the variable is expanded. (They're just ordinary characters at that point.)
However, there's an option just for this:
--raw-output
/-r
:
With this option, if the filterôs result is a string then
it will be written directly to standard output rather than
being formatted as a JSON string with quotes. This can be
useful for making jq filters talk to non-JSON-based systems.
So, use TOKEN="$(echo "$OUTPUT" | jq -r .id)"
instead.
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
jq
gives the output quoted, as would be appropriate for JSON.
$ echo ' "foo": "foobar" ' | jq .foo
"foobar"
The quotes end up as part of the contents of TOKEN
, and are not removed when the variable is expanded. (They're just ordinary characters at that point.)
However, there's an option just for this:
--raw-output
/-r
:
With this option, if the filterôs result is a string then
it will be written directly to standard output rather than
being formatted as a JSON string with quotes. This can be
useful for making jq filters talk to non-JSON-based systems.
So, use TOKEN="$(echo "$OUTPUT" | jq -r .id)"
instead.
jq
gives the output quoted, as would be appropriate for JSON.
$ echo ' "foo": "foobar" ' | jq .foo
"foobar"
The quotes end up as part of the contents of TOKEN
, and are not removed when the variable is expanded. (They're just ordinary characters at that point.)
However, there's an option just for this:
--raw-output
/-r
:
With this option, if the filterôs result is a string then
it will be written directly to standard output rather than
being formatted as a JSON string with quotes. This can be
useful for making jq filters talk to non-JSON-based systems.
So, use TOKEN="$(echo "$OUTPUT" | jq -r .id)"
instead.
answered Jul 3 at 21:26
ilkkachu
47.3k668130
47.3k668130
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f453314%2fvariable-in-curl-adds-backslashes-to-string%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
How do you assign the token to the variable. Any double quotes should not be part of the value (which they would be if you escape them).
â Kusalananda
Jul 3 at 21:15
I assign the token from a curl call, I will add the details
â Michael St Clair
Jul 3 at 21:15