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

183
Visualizações
How to get single value from request response

I started writing a program that will automate user actions, by now it's meant to be an easier menu to make faster actions by just sending requests to the official website by clicks on my own page. (something like web-bot but not exactly). My problem is when i send login request in response i get back user_id, server, session_id etc. And I need to save that session_id to make the other actions. How can i save this to variable. All in JavaScript.

I was looking in the internet since yesterday for an answer and i still can't find (or understand) how to get this I tried function login(){ fetch('url', { method: 'POST', headers: { //headers }, body: //my Id's }) })

//There's the problem to solve .then(res => res.text()) .then(data => obj = data) .then(() => console.log(obj)) console.log(body.session_id);

// I even tried the substring but 1. It won't work as I want because There are sometimes //more and less letters. 2. I get and error "Cannot read properties of undefined (reading //'substr')"

`session = obj;
session_id = session.substring(291,30)
console.log(session_id)`
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

It looks like you're using the text() method on the Response object returned from fetch(), which will give you a string representation of the response.

You probably want to be using the json() method instead, and from that you can get your session_id.

This guide has some more useful information that may help you: https://javascript.info/fetch

about 4 years ago · Juan Pablo Isaza Relatório

0

Ok it works now with

`async function login(){ let session = await fetch('url', {
    //code
}
let result = await session.json();
console.log(result);
session_id = result.data.user.session_id;
user_id = result.data.user.id;`
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