4

Im trying to update an existing gist using Octokit. I can successfully get the gist but I cannot update the gist. It always throws an httpError: Not Found.

Heres my code:

const request = require('request-promise');
const Octokit = require('@octokit/rest');

const octokit = new Octokit({
  auth: `PersonalAccessToken`
});

async function main () {
  const stats = await request({
    uri: `https://myurl.com`,
    json: true
  })

  await updateGist(stats)
}

async function updateGist(stats) {
  let gist
  try {
    gist = await octokit.gists.get({
      gist_id: `myGistID`
    });
    console.log("Get Gist successful!")
  } catch (error) {
    console.error(`Unable to get gist\n${error}`)
  }
 try{
    const filename = Object.keys(gist.data.files)[0];
    await octokit.gists.update({
        gist_id: "myGistID",
        files: {
          [filename]: {
            filename: `myFileName`,
            content: lines.join("\n")
          }
        }
      });
    } catch (error) {
      console.error(`Unable to update gist\n${error}`);
    }
}

And when I run this I get this on my terminal. Unable to update gist HttpError: Not Found

What am I doing wrong here?

Suvin Nimnaka Sukka
  • 341
  • 1
  • 7
  • 21

0 Answers0