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

257
Visualizações
Issue with POST request with API oauth2 / return: error 415

I have some issues with an API with oauth2 authentication. After I get the token, and I want to sent my POST request but it still gives me a 415 error (Unsupported Media Type). I'm sure my payload's fields are good because I tried with postman and it works, but I don't know if I have to JSON stringify the header (the payload I think, but I'm not sure at 100%). I run my code on Google apps script so I thought the problem came from apps script, but I can get the token and send GET request on it.

    function post_pers() {
     var url = "(my url)";
     var data = {
      "id": 32,
      "nom": "apij",
      "prenom": "joseph",
      "civiliteLongue": "Monsieur",
      "idTypePersonne": "PERSTPHYSIQUE  ",
      "ligne1Adresse": " ",
      "ligne2Adresse": " ",
      "ligne3Adresse": " ",
      "codePostal": " ",
      "commune": " ",
      "idPays": "FR",
      "iban": " ",
      "bic": " ",
      "titulaireCompte": " ",
      "domiciliationBanque": " ",
      "assujettiTva": true,
      "mediaPrefere": "Mail",
    }
    var payload = JSON.stringify(data);
    Logger.log("payload; "+payload)
    Logger.log("data; "+data)
     
     var header1 = {
    "accept": "application/json",
    "authorization": "Bearer (my access token)",
    "content-type": "application/json"
    }
    var header = JSON.stringify(header1);
    Logger.log("header; "+header)
    Logger.log("header1; "+header1)

    var options = {
        "method": "POST",
        "header": header,
        "payload": payload
    }
     var response = UrlFetchApp.fetch(url, options);
     Logger.log(response)
      }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

415 is unsupported media. This is usually due to Content-Type header typos. Your script is stringifying headers, which would make header unreadable by the server. Try

var options = {
    "method": "POST",
    "header": /*header*/header1,
    "payload": payload
}
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