Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

125
Views
Creating a Git Hub Repositories using Ajax JQuery not working

I am trying to create a GitHub repository using AJAX from JQuery, but it is not working, my code is here:

    $.ajax({

    url: "https://api.github.com/my-user/repos",
    headers: { 'Authorization' : 'token my-token' },
    method: 'POST',
    data:{
      "name": "new-repos",
      "description" : "New-repos",
      "auto_init": true, 
      "private": false,

    },
    dataType: 'json',
    contentType: 'application/json',
    processData: false,
    success: function (data, textStatus, request) {
    var html_content_header = "";
    var obj_header=request.getAllResponseHeaders();

     $('#header').html(JSON.stringify(request.getAllResponseHeaders()));


var html_content_text = "";
     Object.getOwnPropertyNames(data).forEach(
  function (val, idx, array) {
    html_content_text=html_content_text+val + ' -> ' + data[val]+ '<br>';
  }
);
     $('#text').html(html_content_text);
    },
    error: function(xhr, status, error) {

  alert(xhr.status);
}
});

It shows this error in console:

POST https://api.github.com/my-user/repos 404 (Not Found)

And in my error alert:

404

I followed the guide of getting started by GitHub https://developer.github.com/guides/getting-started/, but instead of using CURL, i was using AJAX from JQuery.

Everything was going smoothly, until i tried creating a new repository. I have verified that my token has the correct scopes.

I kind of guess that it does not found the URL.

Is there some kind of limitation using AJAX from JQuery and GitHub?

Am i writing wrong the URL?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The GitHub API for creating a repo is

POST /user/repos

Not "my-user/repo"

See "GitHub API AJAX POST returning 422" for a full example: no trailing ',' in data, and use data: JSON.stringify:

$.ajax({
      url: 'https://api.github.com/repos/USERNAME/REPONAME/issues',
      type: 'POST',
      dataType: 'json',
      headers: {
        Authorization: 'token MY_PERSONAL_TOKEN'
      },
      data: JSON.stringify({
        "title": "Found a bug",
        "description": "Bug description"
      }),
      success: function (response) {
        console.log(response);
      }
    });
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!