Code & Snippets

PitchBook ID Lookup.

Resolve a company's PitchBook ID from its name or website via the PitchBook search API — drop-in for a Zapier 'Run Python' step.

Sourcing
Python · 31 lines
C.1

Download

Grab the source file. Drop it into your service, set the required environment variables, and deploy.

Download pitchbook_id.pyPython · 31 lines
C.2

How it works

The gist

Given a company's name and/or website (typically pulled from Attio), call PitchBook's search API and return the matching record so a downstream step can grab the PitchBook ID and stitch it back onto the CRM record.

The flow

  1. Inputs come in. api_key, company_name, company_website — passed via input_data (Zapier "Run Python" convention, but any host that supplies a dict works).
  2. Pick the better signal. Website beats name for disambiguation, so use it when present; otherwise fall back to name.
  3. Authenticated GET to PitchBook search with the PB-Token header.
  4. Raise on API errors — auth/network failures should fail loud so the automation surfaces them instead of writing garbage back to Attio.
  5. Return the JSON for the next step (parse out the ID, write it back to the company record in Attio, etc.).

Why this exists

PitchBook IDs are the join key between Attio and every PitchBook-backed enrichment. Resolving them once at the moment a company enters the CRM makes every downstream lookup deterministic.

C.3

Source

Full source, exactly as shipped. The download above is byte-identical.

pitchbook_id.pyPython
"""
Get a company's PitchBook ID

Designed to run inside a Zapier "Run Python" step (or any environment that
exposes an `input_data` dict). Given a company name and/or website pulled
from Attio, query PitchBook's search API and return the matching record so
downstream steps can grab the PitchBook ID.
"""

import requests

api_key = input_data['api_key']                 # PB API key
company_name = input_data.get('company_name')   # from Attio
company_website = input_data.get('company_website')  # from Attio

# Choose website if available, else name
search_query = company_website if company_website else company_name

headers = {
    'Authorization': f"PB-Token {api_key}"
}

url = f"https://api.pitchbook.com/search?query={search_query}"

resp = requests.get(url, headers=headers)

# If the API itself errors, keep raising (likely auth/network issue)
resp.raise_for_status()

output = resp.json()