简体   繁体   中英

Bash script - cURL with variables

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

        }'

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

        }'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM