Search code examples
apiauthenticationgithubaxiosgithub-api-v3

Github API v3, post issues / authentication


I am working on a project making a Kanban board using the Github API v3. I have no problem with get methods, but when it comes to post methods i get a 404 response, and from what i read in the documentation, this seems to be a authentication error.

I am using personal token for authentication, and have successfully posted through postman, but when i try to post through my own application i get the error.

Link to project if anyone's interested : https://github.com/ericyounger/Kanban-Electron

Below is the code used for posting to github.

Might there be a problem with my code below? Or might it be settings in relation with the token?

postIssue(json){

        let packed = this.packPost(json);
        return Axios.post(`https://api.github.com/repos/${this.user}/${this.repo}/issues`, packed);
    }

    packPost(json) {
        return {
            method: "POST",
            headers: {
                "Authorization": `token ${this.tokenAuth}`,
                "Content-Type": "application/json"
            },
            body: JSON.stringify({title: json.title})
        };
    }

This is what i receive:

{message: "Not Found", documentation_url: "https://developer.github.com/v3/issues/#create-an-issue"}
message: "Not Found"
documentation_url: "https://developer.github.com/v3/issues/#create-an-issue"

Console log error message


Solution

  • This did the trick :)

        postIssue(json){
            const headers = {
                'Content-Type': 'application/json',
                'Accept': 'application/vnd.github.v3.raw',
                "Authorization": `token ${this.tokenAuth}`,
            };
    
            return Axios.post(`https://api.github.com/repos/${this.user}/${this.repo}/issues`, json , {headers: headers});
        }