Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 3
Message 1 of 2

List of Organization - working from postman, same Auth Token gives 403 forbidden error

Solved! Go to Solution.

List of Organization is working and showing me list of organziation in Postman, when i use the same token in code i get an error 403 forbidden. Here is the code:

 

async GetOrganizations4Login(login: string) {
try{
const postData =
  `{"query": "query {
        viewer {
           name
               organizations(last: 10) {
                 nodes {
                   name
               }
             }
           }
      }",
"variables":{}
}`;

const options =
{
host : 'api.github.com',
method: 'POST',
port: 443,
path: '/graphql',
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer 51987338eac0ada924844c76c4",
"Accept" : "application/vnd.github.machine-man-preview+json",
"Content-Length": Buffer.byteLength(postData),
"cache-control": "no-cache"
}
};
 
let post_req = await https.request (options, (res: any) => {
console.log (res);
});
post_req.write (postData);
post_req.end ();
 
} catch (ex) {
console.log (ex)
}
}
 
I tried putting the word "Bearer" and without anything in front of Token, but everytime i get 403, same is working from Postman.
 
What am i missing?
 
Appriciate your help.
1 Reply
Solution
Copilot Lvl 3
Message 2 of 2

Re: List of Organization - working from postman, same Auth Token gives 403 forbidden error

Found the issue! When i used 'request' library i saw the whole error string, which told me it needs a user-agent in header.  

 

Once I added a user-agent header got everything working fine. 

 

HTH