0

I'm trying to get a cURL script to input my variables in a --data section. I'm fairly new to this, but it's just inserting the variables names.

The background is this script is called to hit an API in our ticketing system to create a new job. I am finding the ticket that is created has the subject "${DESCRIPTION}" and not "problem description".

#!/bin/bash
# This will log a ticket in Ticketing System


DESCRIPTION='Problem Description'
SUBJECT='Problem Subject'

curl --location --request POST 'https://XXXXX.domain.com/helpdesk/tickets.json' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic XXXXXXXXXXXXXXXXXXXXXXXXXXXXX' \
--data '{
        "helpdesk_ticket":
        {
                "description": "${DESCRIPTION}",
                "subject": "${SUBJECT}",
                "email": "email@domain.com",
                "priority": 1,
                "status": 2

        },
                "cc_emails": ""

        }'
tripleee
  • 175,061
  • 34
  • 275
  • 318
Stephen Pefanis
  • 305
  • 1
  • 3
  • 16
  • Does this answer your question? [Difference between single and double quotes in Bash](https://stackoverflow.com/questions/6697753/difference-between-single-and-double-quotes-in-bash) – tripleee Mar 23 '21 at 07:44

1 Answers1

0

As per always, got this working just after I posted....

The solution was to wrap the variable in "'".

#!/bin/bash
# This will log a ticket in Ticketing System


DESCRIPTION='Problem Description'
SUBJECT='Problem Subject'

curl --location --request POST 'https://XXXXX.domain.com/helpdesk/tickets.json' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic XXXXXXXXXXXXXXXXXXXXXXXXXXXXX' \
--data '{
         "helpdesk_ticket":
    {
            "description": "'"$DESCRIPTION"'",
            "subject": "'"$SUBJECT"'",
                "email": "email@domain.com",
                "priority": 1,
                "status": 2

        },
                "cc_emails": ""

        }'
Stephen Pefanis
  • 305
  • 1
  • 3
  • 16