PRIV ProtocolPRIV Docs
API Reference

Data Marketplace API

API for the PRIV data marketplace - browse, list, and purchase data listings.

Endpoints for the PRIV data marketplace where users can buy and sell anonymized data.

All marketplace endpoints require authentication. Purchases require a user API key with linked wallet.


List Data Listings

GET/api/v1/data/listings

Browse available data listings in the marketplace.

Query Parameters

ParameterTypeRequiredDescription
data_typestringNoFilter by type: browsing, defi, nft, social, location
min_pricenumberNoMinimum price in PRIV
max_pricenumberNoMaximum price in PRIV
limitnumberNoResults per page (default: 20, max: 100)
offsetnumberNoPagination offset (default: 0)

Response

{
  "success": true,
  "data": {
    "listings": [
      {
        "id": "lst_abc123",
        "seller_id": "usr_xyz789",
        "title": "DeFi Trading Patterns - Q1 2024",
        "description": "Anonymized swap data from major DEXs",
        "data_type": "defi",
        "price_priv": 50,
        "sample_data": {
          "preview": true,
          "fields": ["timestamp", "event_type", "token_pair", "amount_range"]
        },
        "total_records": 10000,
        "is_active": true,
        "created_at": "2024-01-15T00:00:00.000Z",
        "updated_at": "2024-01-15T00:00:00.000Z"
      }
    ],
    "pagination": {
      "total": 150,
      "limit": 20,
      "offset": 0,
      "has_more": true
    }
  }
}

Data Types

TypeDescription
browsingWeb browsing patterns and interests
defiDeFi trading and swap data
nftNFT collection and trading patterns
socialSocial media engagement data
locationAnonymized location patterns

Example

curl "https://api.privlabs.io/v1/data/listings?data_type=defi&max_price=100&limit=10" \
  -H "Authorization: Bearer pk_live_xxx"

Purchase Data

POST/api/v1/data/purchase

Purchase access to a data listing using PRIV tokens.

Request Body

{
  "listing_id": "lst_abc123"
}

Request Fields

FieldTypeRequiredDescription
listing_idstringYesUUID of the listing to purchase

Response

{
  "success": true,
  "data": {
    "purchase_id": "pur_xyz789",
    "listing_id": "lst_abc123",
    "listing_title": "DeFi Trading Patterns - Q1 2024",
    "price_paid": 50,
    "access_token": "dat_AbCdEfGhIjKlMnOpQrStUvWxYz012345",
    "expires_at": "2024-02-15T00:00:00.000Z",
    "status": "completed",
    "message": "Purchase successful! Use the access token to retrieve data."
  }
}

Response Fields

FieldTypeDescription
purchase_idstringUnique purchase identifier
listing_idstringPurchased listing ID
price_paidnumberAmount paid in PRIV
access_tokenstringToken to access the purchased data
expires_atstringAccess expiration (30 days from purchase)
statusstringPurchase status: completed, pending, failed

Purchase Requirements

  • User must have sufficient PRIV balance
  • Cannot purchase own listings
  • Cannot purchase same listing twice while access is active

Purchases are atomic and cannot be reversed. Ensure you have reviewed the listing details before purchasing.

Error Responses

CodeMessageDescription
400Insufficient PRIV balanceUser doesn't have enough PRIV
400Cannot purchase your own data listingSeller cannot buy own data
400You already have active accessAlready purchased and not expired
404Data listing not foundInvalid listing ID

JavaScript Example

Complete Purchase Flow

// 1. Browse listings
const listingsRes = await fetch('/api/v1/data/listings?data_type=defi&limit=10', {
  headers: { 'Authorization': `Bearer ${apiKey}` },
});

const { data: { listings } } = await listingsRes.json();
console.log('Available listings:', listings.length);

// 2. Select and purchase a listing
const selectedListing = listings[0];

const purchaseRes = await fetch('/api/v1/data/purchase', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${userToken}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    listing_id: selectedListing.id,
  }),
});

const purchase = await purchaseRes.json();

if (purchase.success) {
  console.log('Purchase successful!');
  console.log('Access token:', purchase.data.access_token);
  console.log('Expires:', purchase.data.expires_at);
} else {
  console.error('Purchase failed:', purchase.error.message);
}

Security Features

The purchase endpoint implements multiple safeguards:

FeatureDescription
Atomic TransactionsBalance deduction and purchase creation are atomic
Duplicate PreventionDatabase constraints prevent double purchases
Race Condition ProtectionOptimistic locking prevents concurrent purchase issues
IdempotencySame request within 30s window returns same result

Data Access

After purchase, use the access_token to retrieve the data through the Data Wallet Marketplace endpoints:

  • Listings: /api/v1/marketplace/wallet/listings/{id}
  • Purchases: /api/v1/marketplace/wallet/purchases/{id}
  • Download: /api/v1/marketplace/wallet/purchases/{id}/download

See the Marketplace API for details on accessing purchased data.