Skip to main content

A Python utility to fetch complete Salesforce reports, bypassing the 2000-row limit. Supports custom API versions.

Project description

sf-report-fetcher

A Python utility to fetch complete Salesforce reports, bypassing the 2000-row limit using smart pagination.

The Problem

Salesforce's Report API has a limitation where it won't return more than 2000 rows per request. While there are various workarounds suggested online (like using multiple reports or offset-based pagination), none of them work reliably for large reports.

The Solution

This package implements a smart pagination strategy using column-based filtering. Instead of using offset pagination (which Salesforce doesn't support), it:

  1. Fetches the first batch of data
  2. Uses the last value of a specified column as a filter
  3. Fetches the next batch where the column value is greater than the last seen value
  4. Repeats until all data is retrieved

Installation

pip install sf-report-fetcher

Basic Usage

from salesforce_report_fetcher import SalesforceReportFetcher

# Initialize the fetcher
fetcher = SalesforceReportFetcher(
    access_token="your_salesforce_access_token",
    instance_url="https://your-instance.salesforce.com"
)

# Fetch all data from a report
report_id = "00OxxxxxxxxxxxxxxxxX"  # Your Salesforce report ID
id_column = "Id"  # Any ordered column in your report (usually Id or CreatedDate)

# Get the data
columns, rows = fetcher.fetch_all_report_data(report_id, id_column)

# Work with the data
print(f"Retrieved {len(rows)} rows")
for row in rows:
    for col_name, value in zip(columns, row):
        print(f"{col_name}: {value}")

Advanced Usage

Specifying Salesforce API Version

You can specify which Salesforce API version to use:

# Use specific API version
fetcher = SalesforceReportFetcher(
    access_token="your_token",
    instance_url="https://instance.salesforce.com",
    api_version="47.0"  # Specify your desired API version
)

Getting Report Metadata

# Get report metadata (cached)
metadata = fetcher.get_metadata(report_id)
print("Available fields:", [field['label'] for field in metadata['reportType']['fields']])

Executing Reports with Custom Metadata

# Execute report with custom metadata
custom_metadata = {
    "reportFilters": [
        {
            "column": "CreatedDate",
            "operator": "greaterThan",
            "value": "2024-01-01"
        }
    ]
}
results = fetcher.execute_report(report_id, custom_metadata)

Configuration Options

Parameter Description Default
access_token Your Salesforce access token Required
instance_url Your Salesforce instance URL Required
api_version Salesforce API version to use "57.0"

Requirements

  • Python 3.7+
  • requests

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT License - feel free to use this in your projects!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sf_report_fetcher-0.1.0.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sf_report_fetcher-0.1.0-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file sf_report_fetcher-0.1.0.tar.gz.

File metadata

  • Download URL: sf_report_fetcher-0.1.0.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for sf_report_fetcher-0.1.0.tar.gz
Algorithm Hash digest
SHA256 07605a194206bc4d3e60dfe002d99c3d66a7c2603c2a1ec9fcd8e0143857893b
MD5 028552e1244716aeee103762b2381e54
BLAKE2b-256 4bfd62c7a62edae82ba4900f8d9d5547ff6b7d18a48445d18697259154199758

See more details on using hashes here.

File details

Details for the file sf_report_fetcher-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sf_report_fetcher-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0ea07241c0a2ab577122b254865d7e2aa51b92d7bd7968713c5a8000a4b30671
MD5 b97a71983b1cfc4ebc2b5d47da9ea1ad
BLAKE2b-256 f16c9ab068cdeb0c58f932a86d23e71201d158d28b94825550af9143fe90b876

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page