Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

184
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda