Ebay Search API (Async)

This endpoint will retrieve products for a specified search term from Ebay search page and transform it into usable JSON.

Single Query request:

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import javax.net.ssl.HttpsURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
public class Main {
    public static void main(String[] args) {
        try {
            String apiKey = "APIKEY";
            String jsonInputString = "{"
                + "\"apiKey\": \"" + apiKey + "\", "
                + "\"query\": \"QUERY\", "
                + "\"country_code\": \"COUNTRY_CODE\", "
                + "\"tld\": \"TLD\", "
                + "\"sort_by\": \"SORT_BY\", "
                + "\"page\": \"PAGE\", "
                + "\"items_per_page\": \"ITEMS_PER_PAGE\", "
                + "\"seller_id\": \"SELLER_ID\", "
                + "\"condition\": \"CONDITION\", "
                + "\"buying_format\": \"BUYING_FORMAT\", "
                + "\"show_only\": \"SHOW_ONLY\", "
                + "\"callback\": {"
                + "    \"type\": \"webhook\", "
                + "    \"url\": \"YYYY\""
                + "}}";

            URL url = new URL("https://async.scraperapi.com/structured/ebay/search");
            HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
            connection.setRequestMethod("POST");
            connection.setRequestProperty("Content-Type", "application/json");
            connection.setRequestProperty("Accept", "*/*");
            connection.setDoOutput(true);
            try (OutputStream os = connection.getOutputStream()) {
                byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8);
                os.write(input, 0, input.length);
            }
            int responseCode = connection.getResponseCode();
            StringBuilder response = new StringBuilder();
            BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String readLine;
            while ((readLine = in.readLine()) != null) {
                response.append(readLine);
            }
            in.close();
            if (responseCode == HttpURLConnection.HTTP_OK) {
                System.out.println("Response: " + response.toString());
            } else {
                throw new Exception("Error in API Call: Response code " + responseCode + "\nbody: " + response.toString());
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

Multiple Query request:

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import javax.net.ssl.HttpsURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
public class Main {
    public static void main(String[] args) {
        try {
            String apiKey = "APIKEY";
            String jsonInputString = "{"
                + "\"apiKey\": \"" + apiKey + "\", "
                + "\"queries\": [\"QUERY1\", \"QUERY2\"], "
                + "\"country_code\": \"COUNTRY_CODE\", "
                + "\"tld\": \"TLD\", "
                + "\"sort_by\": \"SORT_BY\", "
                + "\"page\": \"PAGE\", "
                + "\"items_per_page\": \"ITEMS_PER_PAGE\", "
                + "\"seller_id\": \"SELLER_ID\", "
                + "\"condition\": \"CONDITION\", "
                + "\"buying_format\": \"BUYING_FORMAT\", "
                + "\"show_only\": \"SHOW_ONLY\", "
                + "\"callback\": {"
                + "    \"type\": \"webhook\", "
                + "    \"url\": \"YYYY\""
                + "}}";

            URL url = new URL("https://async.scraperapi.com/structured/ebay/search");
            HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
            connection.setRequestMethod("POST");
            connection.setRequestProperty("Content-Type", "application/json");
            connection.setRequestProperty("Accept", "*/*");
            connection.setDoOutput(true);
            try (OutputStream os = connection.getOutputStream()) {
                byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8);
                os.write(input, 0, input.length);
            }
            int responseCode = connection.getResponseCode();
            StringBuilder response = new StringBuilder();
            BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String readLine;
            while ((readLine = in.readLine()) != null) {
                response.append(readLine);
            }
            in.close();
            if (responseCode == HttpURLConnection.HTTP_OK) {
                System.out.println("Response: " + response.toString());
            } else {
                throw new Exception("Error in API Call: Response code " + responseCode + "\nbody: " + response.toString());
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

Sample Response

Single Query Request:

{                          
  "id": "28cd7eb4-b1a1-4f99-b843-c9c8217d8a46",
  "attempts": 0,           
  "status": "running",     
  "statusUrl": "https://async.scraperapi.com/jobs/28cd7eb4-b1a1-4f99-b843-c9c8217d8a46",
  "query": "iphone",    
  "sort_by": "price_lowest",  
  "supposedToRunAt": "2024-11-11T10:18:01.316Z"
}

Multiple Query Request:

[                                                                                                                                                                                                                                                                                                                             
  {
    "id": "cb102a9b-d294-4172-b1b2-1c5b9f4b47df",
    "attempts": 0,
    "status": "running",
    "statusUrl": "https://async.scraperapi.com/jobs/cb102a9b-d294-4172-b1b2-1c5b9f4b47df",
    "query": "iphone",
    "sort_by": "price_lowest"
  },
  {
    "id": "e4abe7b8-9f71-4bcd-ae43-f2479aff013a",
    "attempts": 0,
    "status": "running",
    "statusUrl": "https://async.scraperapi.com/jobs/e4abe7b8-9f71-4bcd-ae43-f2479aff013a",
    "query": "android",
    "sort_by": "price_lowest"
  }
]

Last updated