I created a bash script to change the value of a specific line on multiple gists. Still, when passing the new content variable over Curl, I get the following error:
{
"message": "Problems parsing JSON",
"documentation_url": "https://docs.github.com/rest/reference/gists/#update-a-gist"
}
Here is the code:
#!/bin/bash
# Replace <access_token> with your personal access token
access_token="<access_token>"
# Read the file containing the gist IDs (one ID per line)
while read -r gist_id; do
# Fetch the gist data using the GitHub REST API
gist_data=$(curl -s -H "Authorization: token $access_token" "https://api.github.com/gists/$gist_id")
# Extract the filename and content of the gist
filename=$(echo "$gist_data" | jq -r '.files | keys[]')
content=$(echo "$gist_data" | jq -r ".files[\"$filename\"].content")
# Update the desired line of the content using sed
# Replace <line_number> and <new_content> with your desired values
new_content="<new_content>"
line_number=<line_number>
content=$(echo "$content" | sed "${line_number}s/.*/$new_content/")
# Update the gist using the GitHub REST API
# Replace <gist_description> with your desired description
curl -s -X PATCH -H "Authorization: token $access_token" -d "{\"description\":\"<gist_description>\",\"files\":{\"$filename\":{\"content\":\"$content\"}}}" "https://api.github.com/gists/$gist_id" > /dev/null
done < "gist_ids.txt"