Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

182
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!