LogoLogo
Release NotesDataPipelineFAQs
NodeJS
NodeJS
  • Making Requests
    • API Endpoint Method
    • Proxy Port Method
    • SDK Method
    • Async Requests Method
      • How to use
      • Callbacks
      • API Parameters
      • Async Batch Requests
      • Decoding
    • Structured Data Collection Method
      • Amazon Product Page API
      • Amazon Search API
      • Amazon Offers API
      • Amazon Reviews API
      • Ebay Product Page API
      • Ebay Search API
      • Google SERP API
      • Google News API
      • Google Jobs API
      • Google Shopping API
      • Google Maps Search API
      • Redfin Agent Details API
      • Redfin 'For Rent' Listings API
      • Redfin 'For Sale' Listings API
      • Redfin Listing Search API
      • Walmart Search API
      • Walmart Category API
      • Walmart Product API
      • Walmart Reviews API
    • Async Structured Data Collection Method
      • Amazon Product Page API (Async)
      • Amazon Search API (Async)
      • Amazon Offers API (Async)
      • Amazon Reviews API (Async)
      • Ebay Product Page API (Async)
      • Ebay Search API (Async)
      • Google Search API (Async)
      • Google News API (Async)
      • Google Jobs API (Async)
      • Google Shopping API (Async)
      • Google Maps Search API (Async)
      • Redfin Agent Details API (Async)
      • Redfin 'For Rent' Listings API (Async)
      • Redfin 'For Sale' Listings API (Async)
      • Redfin Listing Search API (Async)
      • Walmart Search API (Async)
      • Walmart Category API (Async)
      • Walmart Product API (Async)
      • Walmart Reviews API (Async)
    • Making POST/PUT Requests
    • Customizing Requests
      • Amazon ZIP Code Targeting
      • Cached Results
      • Cost Control
      • Custom Headers
      • Device Type
      • Geotargeting
      • Geotargeting (Premium)
      • Parameters as Headers
      • Premium Residential/Mobile Proxy Pools
      • Rendering Javascript
        • Render Instruction Set
        • Screenshot Capture🆕
      • Sessions
  • Handling and Processing Responses
    • API Status Codes
    • Output Formats
      • JSON Response - Autoparse 📜
      • LLM Output Formats đź’»
    • Response Encoding and Content-Type
  • Dashboard & Billing
    • API Key
    • Credit Usage
    • Delete Account
    • Invoice History
    • Billing Email
    • Billing Address
    • VAT Number
    • Payment Method
    • Cancel Subscription
  • Credits and Requests
  • Account Information
  • Documentation Overview
Powered by GitBook

Quick links

  • Homepage
  • Dashboard
  • Pricing
  • Contact Sales

Resources

  • Developer Guides
  • Blog
  • Contact Support
  • Learning Hub
On this page

Was this helpful?

  1. Making Requests
  2. Async Requests Method

Callbacks

Using a status URL is a great way to test the API or get started quickly, but some customer environments may require some more robust solutions, so we implemented callbacks. Currently only webhook callbacks are supported but we are planning to introduce more over time (e.g. direct database callbacks, AWS S3, etc).

An example of using a webhook callback:

const axios = require('axios');

(async() => {
const { data } = await axios({
data: {
apiKey: 'API_KEY',
callback: {
type: 'webhook',
url: 'https://yourcompany.com/scraperapi'
},
url: 'https://example.com'
},
headers: { 'Content-Type': 'application/json' },
method: 'POST',
url: 'https://async.scraperapi.com/jobs'
});

console.log(data);
})();

Using a callback you don’t need to use the status URL (although you still can) to fetch the status and results of the job. Once the job is finished the provided webhook URL will be invoked by our system with the same content as the status URL provides.

Just replace the https://yourcompany.com/scraperapi URL with your preferred endpoint. You can even add basic auth to the URL in the following format: https://user:pass@yourcompany.com/scraperapi

By default, we'll call the webhook URL you provide for successful requests. If you'd like to receive data on failed attempts too, you will have to include the expectsUnsuccessReport: true parameter in your request structure.

An example of using callbacks that report on the failed attempts as well:

const axios = require('axios');

(async () => {
const { data } = await axios({
data: {
apiKey: 'API_KEY',
url: 'https://httpbin.org/status/500',
callback: {
type: 'webhook',
url: 'YYYYY'
},
expectsUnsuccessReport: true
},
headers: { 'Content-Type': 'application/json' },
method: 'POST',
url: 'https://async.scraperapi.com/jobs'
});

console.log(data);
})();

Response:

{
  id: 'db726d84-2609-4709-93cb-88c4a9fa4288',
  attempts: 50,
  status: 'failed',
  statusUrl: 'https://async.scraperapi.com/jobs/db726d84-2609-4709-93cb-88c4a9fa4288',
  failReason: 'failed_due_to_timeout',
  url: 'http://httpbin.org/status/500'
}

Note: The system will try to invoke the webhook URL 3 times, then it cancels the job. So please make sure that the webhook URL is available through the public internet and will be capable of handling the traffic that you need.

PreviousHow to useNextAPI Parameters

Last updated 1 month ago

Was this helpful?

Hint: is a free online service to test webhooks without requiring you to build a complex infrastructure.

Webhook.site