Variable in curl adds backslashes to string

The name of the pictureThe name of the pictureThe name of the pictureClash 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)"






share|improve this question

















  • 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














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)"






share|improve this question

















  • 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












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)"






share|improve this question













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)"








share|improve this question












share|improve this question




share|improve this question








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












  • 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










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.






share|improve this answer





















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );








     

    draft saved


    draft discarded


















    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






























    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.






    share|improve this answer

























      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.






      share|improve this answer























        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.






        share|improve this answer













        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.







        share|improve this answer













        share|improve this answer



        share|improve this answer











        answered Jul 3 at 21:26









        ilkkachu

        47.3k668130




        47.3k668130






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            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













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay