Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

JSON via CURL in atlassian/ssh-run:0.8.1

Jan Guardian September 4, 2024

Guys, please, spare my sanity. I'm trying to run a curl command with atlassian/ssh-run:0.8.1 as follows to no avail:

curl --request POST --url https://api.cloudflare.com/client/v4/zones/$CLOUDFLARE_ZONE/purge_cache --header "Content-Type: application/json" --header "X-Auth-Key: $CLOUDFLARE_APIKEY" --header "X-Auth-Email: $CLOUDFLARE_EMAIL" --data "{"purge_everything": true}"

The request fails with the message from the endpoint saying that "Request must contain one of "purge_everything". Obviously, it has to do something with escaping the quotes in the JSON that is being sent.

I tried it all: backslashes, single quotes, double and tripple single and double quotes — nothing seems to work. 

Please, tell me how to send JSON with curl through atlassian/ssh-run:0.8.1

 

1 answer

1 vote
Jim Knepley - ReleaseTEAM
Atlassian Partner
September 4, 2024

I think it's most legible if you quote it like this:

--data '{"purge_everything": true}'

 

Although it's not relevant to this example, I like to programmatically generate JSON documents using "jq" in a shell, or the "json" library in Python. They do the various required quoting and escaping correctly so I don't have to worry about it, particularly for user-provided inputs.

Jan Guardian September 4, 2024

While it is legible indeed it does not work when run as a command in atlassian/ssh-run:0.8.1

 

 

Jim Knepley - ReleaseTEAM
Atlassian Partner
September 5, 2024

Can you please be more specific? You're calling "Purge Cached Content" from the CloudFlare API, yes?

If it's the same response from CloudFlare, does it work with other clients like Python or Postman?

Your original request: 

--data "{"purge_everything": true}"

...failed because the shell interpreted the data parameter as "{"

Single quotes interpret the entire string as one parameter (at the expense of variable expansion, which you aren't using).

The double-quote alternative would be escaping the double quotes in the JSON document like this:

--data "{\"purge_everything\": true}"

...which I believe is less expressive of your intent than the single-quoted version.

Like Igor Stoyanov likes this

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events