Unable to replace variable inside curl query
Asked by federico:

I would like to execute a curl query inside my bitbucket pipeline.  
The issue I have is using the variable in the pipeline.  
Here is my code

```

- |-
curl --location --request POST "https://xxx.atlassian.net/rest/api/3/issue/"${TICKET_NAME}"/comment" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Basic $JIRA_API_TOKEN" \
-H "Cookie: atlassian.xsrf.token=$JIRA_COOKIE_TOKEN" \
--data-raw "{ \"body\": {\"type\": \"doc\",\"version\": 1,\"content\": [{\"type\": \"paragraph\",\"content\": [{\"text\": \"$PREVIEW_LINK\",\"type\": \"text\"}]}]}}"
```

The problem is \`TICKET_NAME\`, \`PREVIEW_LINK\`, \`JIRA_COOKIE_TOKEN\`, \`JIRA_API_TOKEN\` are not replaced....

I tried
> "<https://xxx.atlassian.net/rest/api/3/issue/>"${TICKET_NAME}"/comment"  
> "<https://xxx.atlassian.net/rest/api/3/issue/$TICKET_NAME/comment>"  
> "[https://xxx.atlassian.net/rest/api/3/issue/\\](https://xxx.atlassian.net/rest/api/3/issue/\)"$TICKET_NAME\\"/comment"  
> "<https://xxx.atlassian.net/rest/api/3/issue/>"$TICKET_NAME"/comment"

But nothing seems to work

This work inm my BASH

```
- >-
curl --location --request POST "https://adasiaholdings.atlassian.net/rest/api/3/issue/$TICKET_NAME/comment" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: Basic $JIRA_API_TOKEN" \
-H "Cookie: atlassian.xsrf.token=$JIRA_COOKIE_TOKEN" \
--data-raw "{ \"body\": {\"type\": \"doc\",\"version\": 1,\"content\": [{\"type\": \"paragraph\",\"content\": [{\"text\": \""$PREVIEW_LINK"\",\"type\": \"text\"}]}]}}"
```

but return
> \> curl: (3) URL using bad/illegal format or missing URL  
> curl: (3) URL using bad/illegal format or missing URL  
> curl: (3) URL using bad/illegal format or missing URL  
> curl: (3) URL using bad/illegal format or missing URL  
> curl: (3) URL using bad/illegal format or missing URL  
> curl: (3) URL using bad/illegal format or missing URL  
> curl: (3) URL using bad/illegal format or missing URL  
> curl: (3) URL using bad/illegal format or missing URL  
> curl: (3) URL using bad/illegal format or missing URL  
> curl: (3) nested brace in URL position 11:  
> { "body": {"type": "doc","version": 1,"content": \[{"type": "paragraph","content": \[{"text": "","type": "text"}\]}\]}}

in the pipeline


Answers:
author: Theodora Boudale
body: Hi [@federico](/t5/user/viewprofilepage/user-id/4320765),

Please use ${TICKET_NAME}, ${PREVIEW_LINK}, ${JIRA_COOKIE_TOKEN} and ${JIRA_API_TOKEN}

The ${TICKET_NAME} in the URL shouldn't be within quotes.

Below is a curl command (with a few different variables) that works for me in Pipelines:

```
- curl -v --request POST --url "https://XXXX.atlassian.net/rest/api/3/issue/${issueKey}/comment" --user "${JiraEmail}:${JiraToken}" --header 'Accept:application/json' --header 'Content-Type:application/json' --data-raw "{\"body\":{\"type\":\"doc\",\"version\":1,\"content\":[{\"type\":\"paragraph\",\"content\":[{\"text\":\""${PREVIEW_LINK}"\",\"type\":\"text\"}]}]}}"
```

Please feel free to let me know if that works for you or if you're still seeing errors.

Kind regards,  
Theodora


Tags: bitbucket-cloud

cloud