Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

CURL variables and problems parsing JSON

My script is creating pull requests using the github API:

./my-script.sh my-repo my-branch

#!/bin/bash

Repo=$1
Branch=$2

cd $Repo
 
get_data() {
cat <<EOF
    {
        "title": "PR title",
        "head": $Branch,
        "base": "development",
        "body": "PR description"
    }
EOF
}

echo $(get_data) # <----------------- I can see my value of the variable $Branch here

curl -X POST \
    -H "Accept: application/vnd.github.v3+json" \
    -d "$(get_data)" \ # <----------------- But here I'm facing "Problems parsing JSON"
    -u my_user:my_token \
    https://api.github.com/repos/my_user/$Repo/pulls

open https://github.com/my_user/$Repo/pulls

How can I set my variable into the curl correctly?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

$Branch needs to be quoted as well:

get_data() {
  cat <<EOF
    {
        "title": "PR title",
        "head": "$Branch",
        "base": "development",
        "body": "PR description"
    }
  EOF
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading