Tutorial Β· Facebook Marketplace

πŸ“˜ TypeScript Step-by-step

How to scrape Facebook Marketplace items
with TypeScript.

Extract item data from Facebook Marketplace. Real code, real responses, real production patterns β€” paste it into your project and ship.

Overview

Learn how to scrape Facebook Marketplace items using TypeScript. This comprehensive guide will walk you through the entire process, from setup to implementation.

What You'll Learn

  • β€’ Setting up your development environment
  • β€’ Installing the required HTTP client
  • β€’ Authenticating with the ScrapeCreators API
  • β€’ Making requests to Facebook Marketplace
  • β€’ Handling responses and errors
  • β€’ Best practices for production use

What You'll Get

  • β€’ Access to items data
  • β€’ JSON formatted responses
  • β€’ Real-time data access
  • β€’ Scalable solution
  • β€’ Error handling patterns
  • β€’ Performance optimization tips

Prerequisites

1. API Key

First, you'll need a ScrapeCreators API key to authenticate your requests.

Sign up at app.scrapecreators.com to get your free API key with 100 requests.

2. Development Environment

Make sure you have the following installed:

  • β€’ TypeScript and its dependencies
  • β€’ A code editor (VS Code, Sublime, etc.)
  • β€’ Basic understanding of API requests
  • β€’ Command line interface access

Step 1: Install HTTP Client

Axios is a promise-based HTTP client for TypeScript/JavaScript

npm
npm install axios

Step 2: API Implementation

Now let's make a request to the Facebook Marketplace API using TypeScript. Replace YOUR_API_KEY with your actual API key.

TypeScript
import axios from 'axios';

interface ScrapeParams {
    id: string;
    url: string;
}

const API_KEY = 'YOUR_API_KEY';

async function scrape(params: ScrapeParams): Promise<any> {
    try {
        const response = await axios.get(`https://api.scrapecreators.com/v1/facebook/marketplace/item?id=1656586118821988&url=https://www.facebook.com/marketplace/item/1656586118821988/`, {
            headers: {
                'x-api-key': API_KEY,
                'Content-Type': 'application/json'
            },
        });

        console.log('Response:', response.data);
        return response.data;
    } catch (error) {
        console.error('Error:', error.response?.data || error.message);
        throw error;
    }
}

// Usage
const params: ScrapeParams = {
    id: '1656586118821988',
    url: 'https://www.facebook.com/marketplace/item/1656586118821988/'
};

scrape(params);

Step 3: Testing Your Code

API Parameters

This endpoint accepts the following parameters:

idOptional(string)

Facebook Marketplace item id

Example: 1656586118821988

urlOptional(string)

Facebook Marketplace item URL

Example: https://www.facebook.com/marketplace/item/1656586118821988/

Run Your Code

Execute your script to test the API connection. You should see a JSON response with Facebook Marketplace items data.

βœ… Success: You should receive a structured JSON response containing the requested data.

Expected Response

Here's an example of the JSON response you'll receive:

Sample Response
{
  "success": true,
  "credits_remaining": 49997831215,
  "id": "1656586118821988",
  "url": "https://www.facebook.com/marketplace/item/1656586118821988/",
  "title": "Specialized Hardrock GSX - Super Clean Vintage Restomod - INCLUDES FREE TUNE UP",
  "description": "Was going to hang on to this one bc I absolutely love how it looks, but the 20” frame is just bit too large for me. Riders over 6’ would be comfy on this one. Currently in a 3x7 set up with an XT derailleur at the rear. Looks great in person. Come ride it!  These never last long. \n\nCASH ONLY, PLEASE. NEAR 183/BRAKER.  \n\n$380 OBO. \n\nKey points:\n\n- Maxxis DTH tires (26”)\n- Shimano Deore XT rear derailleur \n- Shimano front derailleur\n- vintage Specialized steel frame (20”)\n- vintage Sakae triple crankset (170mm)\n- vintage Sakae SR Custom handlebar\n- vintage Suntour stem shifter\n- vintage Shimano brakes\n- Specialized Avatar 143 saddle\n- new chain\n- fresh cables\n- fresh housing\n- fresh grease and lube\n- fresh lube in cable housings\n- fresh handlebar tape\n- drive train cleaned and lubed\n- derailluers adjusted and fine tuned\n- brakes adjusted and fine tuned\n- deep cleaning/detail\n- frame polished\n- frame waxed\n- INCLUDES ONE FREE TUNE UP\n",
  "creation_time": "2026-05-15T16:57:39.000Z",
  "location_text": "Austin, TX",
  "location": {
    "latitude": 30.401916503906,
    "longitude": -97.761840820312
  },
  "price": {
    "formatted_amount_zeros_stripped": "$380",
    "amount_with_offset_in_currency": 38000,
    "amount": 380,
    "currency": "USD"
  },
  "strikethrough_price": null,
  "category_id": "1658310421102081",
  "attributes": [
    {
      "attribute_name": "Condition",
      "value": "used_good",
      "label": "Used - Good"
    },
    {
      "attribute_name": "Bicycle Type",
      "value": "Mountain Bike",
      "label": "Mountain Bike"
    },
    {
      "attribute_name": "Material",
      "value": "Steel",
      "label": "Steel"
    }
  ],
  "photos": [
    {
      "id": "2810586442651711",
      "url": "https://scontent-bos5-1.xx.fbcdn.net/v/t39.84726-6/701290950_2810586459318376_3780262866029042186_n.jpg?stp=dst-jpg_s960x960_tt6&_nc_cat=111&ccb=1-7&_nc_sid=92e707&_nc_ohc=ROKufyRtfXsQ7kNvwGcXi_k&_nc_oc=Adr-1I--Ur89Efziu4LbR01Gx7vv7Ky2iQDaspacjs93wQf7O21Zucf8Bqk7JnAV9us&_nc_zt=14&_nc_ht=scontent-bos5-1.xx&_nc_gid=I5XX4xnX65bx3IZ1QXZ0oQ&_nc_ss=7e289&oh=00_Af4qBsmM1VtSMQvu_Uq9lP5B3sZDkmH3d7tcnkb4qJrfvQ&oe=6A0D43D6",
      "width": 960,
      "height": 720,
      "accessibility_caption": "No photo description available."
    }
  ],
  "is_hidden": false,
  "is_live": true,
  "is_pending": false,
  "is_sold": false,
  "is_viewer_seller": false,
  "is_shipping_offered": false,
  "is_buy_now_enabled": false,
  "messaging_enabled": true,
  "delivery_types": [
    "IN_PERSON"
  ],
  "share_uri": "https://www.facebook.com/marketplace/item/1656586118821988/",
  "seller": null
}

Verify Response Structure

Check that your response includes the expected fields:

  • βœ“success(boolean)
  • βœ“credits_remaining(number)
  • βœ“id(string)
  • βœ“url(string)
  • βœ“title(string)
  • ... and 20 more fields

Best Practices

1

Error Handling

Implement comprehensive error handling and retry logic for failed requests. Log errors properly for debugging.

2

Caching

Cache responses when possible to reduce API calls and improve performance. Consider data freshness requirements.

3

Security

Never expose your API key in client-side code. Use environment variables and secure key management practices.

Performance Tips

Batch Requests

When scraping multiple items, consider batching requests to maximize throughput while staying within rate limits.

Async Processing

Use asynchronous processing in TypeScript to handle multiple requests concurrently and improve overall performance.

Common Use Cases

Market Research

Analyze Facebook Marketplace items to understand market trends, competitor analysis, and audience insights.

Content Analytics

Track performance metrics, engagement rates, and content trends across Facebook Marketplace items.

Lead Generation

Identify potential customers and business opportunities throughFacebook Marketplace data analysis.

Troubleshooting

Common Errors

401 Unauthorized

Check your API key is correct and properly formatted in the x-api-key header.

402 Payment Required

You ran out of credits and need to buy more.

404 Not Found

The resource might not exist or be private.

500 Server Error

Temporary server issue. Implement retry logic with exponential backoff.

Frequently Asked Questions

How much does it cost to scrape Facebook Marketplace items?

ScrapeCreators offers 100 free API calls to get started. After that, pricing starts at $10 for 5k requests with volume discounts available.

Is it legal to scrape Facebook Marketplace data?

Scraping publicly available data is fair game, and we only collect public data. So anything that you can see in an incognito browser is what we collect.

How fast can I scrape Facebook Marketplace items?

There is no rate limit! So you can scrape as fast as you want!

What data format does the API return?

All API responses are returned in JSON format, making it easy to integrate with any programming language or application.

Can I use this with other TypeScript frameworks?

Yes! This tutorial focuses on core TypeScript HTTP concepts that work with any framework. The API calls remain the same regardless of your specific TypeScript setup.

How do I handle large datasets?

For large datasets, implement pagination, use streaming responses where available, and consider storing data in a database for efficient querying.

Related Tutorials

Ready to ship?

Get the API key. Run the code.

100 free API calls. No credit card. Same endpoint, same response shape.

Same endpoint, different language

Pick another stack.