Sessions

To reuse the same proxy for multiple requests, simply use the session_number parameter by setting it equal to a unique integer for every session you want to maintain (e.g. session_number=123). This will allow you to continue using the same proxy for each request with that session number. To create a new session simply set the session_number parameter with a new integer to the API. The session value can be any integer. Sessions expire 15 minutes after the last usage.

  • API REQUEST

import fetch from 'node-fetch';

fetch('http://api.scraperapi.com/?api_key=APIKEY&url=http://httpbin.org/ip&session_number=123')
.then(response => {
console.log(response)
})
.catch(error => {
console.log(error)
})
  • PROXY MODE

const axios = require('axios');
axios.get('http://httpbin.org/ip', {
  method: 'GET',
  proxy: {
    host: 'proxy-server.scraperapi.com',
    port: 8001,
    auth: {
      user: 'scraperapi.session_number=123',
      password: 'APIKEY'  
    },
    protocol: 'http'
  }
})
  .then(response => {
    console.log(response)
  })
  .catch(error => {
    console.log(error)
  });
  • SDK Method

// remember to install the library: npm install scraperapi-sdk --save
const scraperapiClient = require('scraperapi-sdk')('APIKEY')
scraperapiClient.get('http://httpbin.org/ip', {session_number: 123})
.then(response => {
  console.log(response)
})
.catch(error => {
  console.log(error)
})

Last updated