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

95
Visualizações
Django API call from extern Website via AJAX Javascript

i am working for the first time with Django Framework. A service provider is using django i can see the data only with an active Cookie on their API Docs.

We received now an API Token to call for the data on the framework.

I am trying to call the data with the Token via AJAX but i receive everytime the same console log "401 (Unauthorized)".

$.ajax({
    type: 'POST',
    headers: {
        'X-CSRFTOKEN': "XXXXXXXXXXXXXXX",
        'Content-Type': 'application/json'
    },
    url: 'www.service-provider.url/api/...',


    success: function () {
        console.log("ok");
    },
    error: function () {
        console.log("error");
    }
});

Sorry i'm a beginner at this point and have no idea where to begin with. I've searched for solution on the inet but couldn't find anything that would work.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Okay i got it! Before the token api key there must be "Token ...".

 $.ajax({
        type: 'GET',
        url: 'https://my-url.com/api/1.0/?format=json',
        
        headers:{
              "Content-Type": 'application/json',
              "Authorization": 'Token XXXXXXXXXXXXXXXXXXXXX',
              
        },
        
        success: function(data){
            console.log(data);
        }
    
    });
about 4 years ago · Juan Pablo Isaza 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