Coder Social home page Coder Social logo

Comments (13)

mohamedhayibor avatar mohamedhayibor commented on May 23, 2024 1

Tried the curl with my token, it spits out:

{
  "message": "Not Found",
  "documentation_url": "https://docs.github.com/rest"
}

Thank you very much. I contacted support and referenced the issue.

from core.js.

gr2m avatar gr2m commented on May 23, 2024 1

Try this:

octokit
  .request("GET /")
  .then(console.log, console.log);

If you get a 404 error, the token is invalid. If it logs the response, look for

    'x-oauth-scopes': 'gist',

in the response header. My guess is that either the token you pass in auth: token is invalid, or it does not have the gist scope.

from core.js.

gr2m avatar gr2m commented on May 23, 2024

Most likely the token does not have the β€œgist” scope. Can you log the full error?

from core.js.

mohamedhayibor avatar mohamedhayibor commented on May 23, 2024
HttpError: Bad credentials
    at /Users/mo/..../note/node_modules/@octokit/request/dist-node/index.js:66:23
    at processTicksAndRejections (node:internal/process/task_queues:93:5)
    at async /Users/mo/..../note/cli.js:94:5
  • I only specifically allowed the "gist" scope.

from core.js.

gr2m avatar gr2m commented on May 23, 2024

I was not able to reproduce the problem.

const octokit = new Octokit({
  auth: "MY TOKEN",
});

octokit
  .request("POST /gists", {
    files: {
      "test.txt": {
        content: "test",
      },
    },
  })
  .then(console.log, console.log);

Here is the gist it created

https://gist.github.com/gr2m/8941225b4aa0e8136b35911915beca9e

Can you please log the error and share what it logs?

await octokit.request('POST /gists', {
  files: saveGist
}).catch(console.log)

from core.js.

mohamedhayibor avatar mohamedhayibor commented on May 23, 2024
RequestError [HttpError]: Bad credentials
    at /Users/mo/..../note/node_modules/@octokit/request/dist-node/index.js:66:23
    at processTicksAndRejections (node:internal/process/task_queues:93:5) {
  status: 401,
  headers: {
    'access-control-allow-origin': '*',
    'access-control-expose-headers': 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset',
    connection: 'close',
    'content-length': '80',
    'content-security-policy': "default-src 'none'",
    'content-type': 'application/json; charset=utf-8',
    date: 'Tue, 24 Nov 2020 09:06:41 GMT',
    'referrer-policy': 'origin-when-cross-origin, strict-origin-when-cross-origin',
    server: 'GitHub.com',
    status: '401 Unauthorized',
    'strict-transport-security': 'max-age=31536000; includeSubdomains; preload',
    vary: 'Accept-Encoding, Accept, X-Requested-With',
    'x-content-type-options': 'nosniff',
    'x-frame-options': 'deny',
    'x-github-media-type': 'github.v3; format=json',
    'x-github-request-id': 'D0C7:9CC2:735169:904C40:5FBCCD21',
    'x-ratelimit-limit': '60',
    'x-ratelimit-remaining': '54',
    'x-ratelimit-reset': '1606211195',
    'x-ratelimit-used': '6',
    'x-xss-protection': '1; mode=block'
  },
  request: {
    method: 'POST',
    url: 'https://api.github.com/gists',
    headers: {
      accept: 'application/vnd.github.v3+json',
      'user-agent': 'octokit-core.js/3.2.1 Node.js/15.2.1 (darwin; x64)',
      authorization: 'token [REDACTED]',
      'content-type': 'application/json; charset=utf-8'
    },
    body: '{"files":{"test.txt":{"content":"test"}}}',
    request: { hook: [Function: bound bound register] }
  },
  documentation_url: 'https://docs.github.com/rest'
}

I tried with a new token only allowed gists, same problem.

Thanks a lot for taking a look btw.

from core.js.

gr2m avatar gr2m commented on May 23, 2024

Can you try to reproduce the problem using curl?

Try

curl -XPOST -H"Authorization: token [TOKEN HERE]" https://api.github.com/gist -d ''{"files":{"test.txt":{"content":"test"}}}''

If you still see the error, I'd suggest to contact support: support.github.com/contact. You can reference this issue and share the request ID: D0C7:9CC2:735169:904C40:5FBCCD21. They have tools to look it up and find out exactly what is happening. I'm out of ideas I'm afraid

from core.js.

kwacky1 avatar kwacky1 commented on May 23, 2024
curl -XPOST -H"Authorization: token [TOKEN HERE]" https://api.github.com/gist -d ''{"files":{"test.txt":{"content":"test"}}}''

That should be gists not gist πŸ˜‰ -- hence the "Not Found"

curl -XPOST -H"Authorization: token [TOKEN HERE]" https://api.github.com/gists -d '{"files":{"test.txt":{"content":"test"}}}'

from core.js.

gr2m avatar gr2m commented on May 23, 2024

oopsie, thanks Simon! Can you try that again Mohamed?

from core.js.

mohamedhayibor avatar mohamedhayibor commented on May 23, 2024

Awesome. The curl works. But I still don't know why using the library fails:

const octokit = new Octokit({
  auth: token,
});

octokit.request('POST /gists', {
    files: {
      "test.txt": {
        content: "test"
      }
    }
}).then(console.log, console.log);

from core.js.

mohamedhayibor avatar mohamedhayibor commented on May 23, 2024

Thanks a lot @gr2m

from core.js.

timrogers avatar timrogers commented on May 23, 2024

@nayebare Can you try instantiating Octokit like this? What you're doing right not doesn't look quite right:

let octokit = new Octokit({ auth: process.env.GITHUB_TOKEN })

from core.js.

timrogers avatar timrogers commented on May 23, 2024

If you console.log(process.env.GITHUB_TOKEN), does anything show up?

from core.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.