Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

126
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda