I'm trying to get a config file from our GitHub using the get contents api.
This returns a JSON containing the file content encoded as a base64 string.
I'd like to get it as text
Steps I've taken
- get initial api response: 
 - curl -H 'Authorization: token MY_TOKEN' \ https://github.com/api/v3/repos/MY_OWNER/MY_REPO/contents/MY_FILE
 this returns a JSON response with a field- "content": "encoded content ..."
- get the encoded string: 
 add- <prev command> | grep -F "content\":"
 this gets the content, but there's still the- "content":string, the- "chars and a comma at the end
- cut the extras: 
 - <prev command> | cut -d ":" -f 2 | cut -d "\"" -f 2
- decode: 
 - <prev command | base64 --decode>
final command:
curl -H 'Authorization: token MY_TOKEN' \
 https://github.com/api/v3/repos/MY_OWNER/MY_REPO/contents/MY_FILE | \
 grep -F "content\":" | cut -d ":" -f 2 | cut -d "\"" -f 2 | base64 --decode
Issues:
- the resulting string (before the - base64 --decode) decodes in an online decoder (not well -> see next item), but fails to do so in bash. The response being- "Invalid character in input stream." 
- When decoding the string in an online decoder, some (not all) of the file is in gibberish, and not the original text. I've tried all the available charsets. 
Notes:
- I've tried removing the last 2 (newline) chars with sed 's/..$//', but this has no effect.
- If I select the output with the mouse and copy paste it to a echo MY_ECODED_STRING_PASTED_HERE | base64 --decodecommand, it has the same effect as the online tool, that is, it decodes as gibberish.
 
     
    