<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js"></script> <script> function getGistFile(gist, filename) { $.ajax({ url: 'https://api.github.com/gists/' + gist, type: 'GET', dataType: 'jsonp', success: function(gistdata) { var content = gistdata.data.files[filename].content; console.log(content); }, error: function(e) { console.log(e); } }); } getGistFile('c3e130c75097c407112937921a885d2c', 'file2.txt'); //Using Gist ID from the response above, we edit the Gist with Ajax PATCH request $.ajax({ url: 'https://api.github.com/gists/c3e130c75097c407112937921a885d2c', type: 'PATCH', beforeSend: function(xhr) { xhr.setRequestHeader("Authorization", "token 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"); }, data: '{"description": "updated gist via ajax","public": true,"files": {"file2.txt": {"content": "I ediasdsadsated this one!"}}}' }).done(function(response) { console.log(response); }); </script>