Hubspot doc gen

From CraftOS-dev/craftbot-agent-bundles · View interactive version

Hubspot doc gen is an AI agent skill from the GitHub repository CraftOS-dev/craftbot-agent-bundles. Generate proposals, quotes, and contracts from HubSpot deal data — HubSpot Quotes (native CPQ-lite for SMB), PandaDoc + HubSpot integration (richer proposals), DocuSign-embedded-in-HubSpot (legacy enterprise), DocSpring custom PDF rendering. Trigger on deal stage change via HubSpot Workflows + webho

How to use this skill

Skill file

HubSpot-to-doc generation — Quotes / PandaDoc / DocuSign / DocSpring

This skill ships HubSpot-centric doc generation. The dominant 2026 stack: HubSpot Quotes for native SMB; PandaDoc + HubSpot for richer/enterprise; custom DocSpring/HTML for unique formats.

When to use

User says:

Companion skills:

Setup

# HubSpot CRM API v3
# Required env: HUBSPOT_ACCESS_TOKEN (private app token) OR OAuth refresh
# Base: https://api.hubapi.com
# Docs: https://developers.hubspot.com/docs/api/overview

# Optional: HubSpot Quotes API
# Same auth; endpoints under /crm/v3/objects/quotes

# PandaDoc REST (recommended doc backend for HubSpot)
# Required env: PANDADOC_API_KEY

# DocSpring (custom PDF generation)
# Required env: DOCSPRING_API_TOKEN

# Optional: DocuSign for embedded signing in HubSpot
# Required env: DOCUSIGN_INTEGRATION_KEY, DOCUSIGN_USER_ID, DOCUSIGN_ACCOUNT_ID

pip install requests

Common recipes

Recipe 1: Pick the doc backend

| Backend | Best for | Pricing tier (approx 2026) | Strengths |

|---|---|---|---|

| HubSpot Quotes (native) | SMB; HubSpot Sales Hub Pro+ | Bundled | Zero-integration; data lives in HubSpot |

| PandaDoc + HubSpot | Mid-market; richer proposals | $19-65/user/mo | Templates, pricing tables, e-sign in one |

| DocuSign Gen + HubSpot | DocuSign-native shops | DocuSign+Gen tier | Strong CLM downstream |

| DocSpring + HubSpot | Custom-formatted PDFs | $50-300/mo | Pure PDF render — bring your own UI |

| Proposify / Qwilr + HubSpot | Design-led proposals | $25-49/user/mo | Beautiful proposal UX |

Default for SMB: HubSpot Quotes. Default for mid-market: PandaDoc + HubSpot.

Recipe 2: HubSpot — fetch a deal + associated objects

# Get deal + properties + line items + primary contact + company
curl "https://api.hubapi.com/crm/v3/objects/deals/$DEAL_ID?associations=line_items,contacts,companies&properties=dealname,amount,closedate,pipeline,dealstage" \
  -H "Authorization: Bearer $HUBSPOT_ACCESS_TOKEN"

Iterate associations to pull line item details:

for LI in $(jq -r '.associations.line_items.results[].id'); do
  curl "https://api.hubapi.com/crm/v3/objects/line_items/$LI?properties=name,quantity,price,hs_total_discount" \
    -H "Authorization: Bearer $HUBSPOT_ACCESS_TOKEN"
done

Recipe 3: HubSpot Quotes — create a native quote (Quotes API)

curl -X POST https://api.hubapi.com/crm/v3/objects/quotes \
  -H "Authorization: Bearer $HUBSPOT_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "properties": {
      "hs_title": "Acme Corp - Q2 2026",
      "hs_expiration_date": "2026-07-15",
      "hs_currency": "USD",
      "hs_payment_enabled": "true",
      "hs_esign_enabled": "true",
      "hs_terms": "Net 30. Subject to MSA.",
      "hs_proposal_template": "PROPOSAL_TEMPLATE_ID"
    },
    "associations": [
      { "to": {"id": "DEAL_ID"}, "types": [{"associationCategory":"HUBSPOT_DEFINED","associationTypeId":64}] }
    ]
  }'

Then associate line items by similar POST to /crm/v3/objects/quotes/$QUOTE_ID/associations/line_items/$LI_ID/quote_to_line_item.

Recipe 4: HubSpot Quotes — set delivery + send

# Mark quote as Approved → URL becomes public
curl -X PATCH https://api.hubapi.com/crm/v3/objects/quotes/$QUOTE_ID \
  -H "Authorization: Bearer $HUBSPOT_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"properties":{"hs_status":"APPROVED"}}'

# Get the public URL
curl "https://api.hubapi.com/crm/v3/objects/quotes/$QUOTE_ID?properties=hs_public_url_key" \
  -H "Authorization: Bearer $HUBSPOT_ACCESS_TOKEN" | jq -r '.properties.hs_public_url_key'
# → https://app.hubspot.com/documents/.../<public_key>

Recipe 5: PandaDoc — create document from HubSpot deal (recommended)

import requests

# 1) Fetch deal
deal = requests.get(
    f"https://api.hubapi.com/crm/v3/objects/deals/{DEAL_ID}?associations=line_items,contacts",
    headers={"Authorization": f"Bearer {HUBSPOT_TOKEN}"}
).json()

# 2) Create PandaDoc from template (pre-built in PandaDoc UI)
pdoc = requests.post(
    "https://api.pandadoc.com/public/v1/documents",
    headers={"Authorization": f"API-Key {PANDADOC_KEY}"},
    json={
        "name": f"Proposal - {deal['properties']['dealname']}",
        "template_uuid": PANDADOC_TEMPLATE_UUID,
        "recipients": [{
            "email": primary_contact_email,
            "first_name": primary_contact_first,
            "last_name": primary_contact_last,
            "role": "client"
        }],
        "tokens": [
            {"name": "deal.name", "value": deal["properties"]["dealname"]},
            {"name": "deal.amount", "value": deal["properties"]["amount"]},
            {"name": "deal.close_date", "value": deal["properties"]["closedate"]},
        ],
        "pricing_tables": [{
            "name": "Pricing",
            "sections": [{
                "title": "Subscription",
                "rows": [
                    {"options": {}, "data": {
                        "name": li["properties"]["name"],
                        "qty": li["properties"]["quantity"],
                        "price": li["properties"]["price"]
                    }}
                    for li in line_items
                ]
            }]
        }],
        "metadata": {"hubspot_deal_id": DEAL_ID}
    }
).json()

Recipe 6: PandaDoc — send + capture document URL

doc_id = pdoc["id"]
# Wait for processing
while requests.get(f"https://api.pandadoc.com/public/v1/documents/{doc_id}",
                   headers={"Authorization": f"API-Key {PANDADOC_KEY}"}).json()["status"] == "document.uploaded":
    time.sleep(2)
# Send
requests.post(
    f"https://api.pandadoc.com/public/v1/documents/{doc_id}/send",
    headers={"Authorization": f"API-Key {PANDADOC_KEY}"},
    json={"message": "Please review and sign.", "silent": False}
)

Recipe 7: PandaDoc webhook → write back to HubSpot deal

# PandaDoc fires document_state_changed events
@app.post("/webhooks/pandadoc")
async def pdoc_webhook(payload: dict):
    if payload["event"] == "document_state_changed" and payload["data"]["status"] == "document.completed":
        deal_id = payload["data"]["metadata"]["hubspot_deal_id"]
        # Move HubSpot deal to "Closed Won"
        requests.patch(
            f"https://api.hubapi.com/crm/v3/objects/deals/{deal_id}",
            headers={"Authorization": f"Bearer {HUBSPOT_TOKEN}"},
            json={"properties": {"dealstage": "closedwon"}}
        )
        # Attach signed PDF as a note + file
        pdf_url = payload["data"]["pdf_url"]
        # Recipe 8 — attach

Recipe 8: Attach a file to a HubSpot deal

# Upload file
FILE_ID=$(curl -X POST https://api.hubapi.com/files/v3/files \
  -H "Authorization: Bearer $HUBSPOT_ACCESS_TOKEN" \
  -F "file=@signed-proposal.pdf" \
  -F "folderPath=/Signed Proposals" \
  -F 'options={"access":"PRIVATE"}' \
  | jq -r '.id')

# Attach to deal via note
curl -X POST https://api.hubapi.com/crm/v3/objects/notes \
  -H "Authorization: Bearer $HUBSPOT_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d "{
    \"properties\": {
      \"hs_note_body\": \"Signed proposal attached.\",
      \"hs_attachment_ids\": \"$FILE_ID\",
      \"hs_timestamp\": $(date +%s)000
    },
    \"associations\": [{\"to\":{\"id\":\"$DEAL_ID\"},\"types\":[{\"associationCategory\":\"HUBSPOT_DEFINED\",\"associationTypeId\":214}]}]
  }"

Recipe 9: HubSpot Workflow → webhook trigger

In HubSpot → Workflows → Create:

  1. Trigger: Deal stage = "Proposal Sent" (custom stage).
  2. Action: Send webhook to https://your-app/webhooks/hubspot-proposal.
  3. Payload includes deal ID + contact ID.
  4. Your endpoint runs Recipe 5 to create the PandaDoc proposal.

Recipe 10: DocSpring — render HTML template + HubSpot data → PDF

# DocSpring expects a pre-uploaded template with form-field tokens
curl -X POST https://api.docspring.com/api/v1/templates/$TEMPLATE_ID/submissions \
  -u $DOCSPRING_API_TOKEN: \
  -H "Content-Type: application/json" \
  -d '{
    "data": {
      "customer_name": "Acme Corp",
      "deal_amount": 240000,
      "term_months": 36
    },
    "test": false
  }'
# Response includes download_url for the rendered PDF

Recipe 11: DocuSign send + embed signed PDF on HubSpot deal

# After Recipe 5/6 OR direct DocuSign send
# DocuSign Connect webhook fires on Completed
# Pull cert + combined PDF (see e-signature-docusign-adobe-sign-pandadoc)
# Then Recipe 8 — attach to HubSpot deal

Recipe 12: Bulk proposal regeneration (e.g., quarterly rebrand)

# Re-render all OPEN proposals after brand update
deals = requests.get(
    "https://api.hubapi.com/crm/v3/objects/deals?properties=dealname,amount&associations=line_items",
    headers={"Authorization": f"Bearer {HUBSPOT_TOKEN}"}
).json()
for d in deals["results"]:
    if d["properties"]["dealstage"] in ("appointmentscheduled", "qualifiedtobuy", "presentationscheduled"):
        # Recipe 5 — re-create PandaDoc with new template version
        ...

Examples

Example 1: SMB native — HubSpot Quotes only

Goal: 15-rep SaaS shop ships quotes natively, no extra tools.

Steps:

  1. Build a Proposal Template in HubSpot UI (Settings → Quotes).
  2. Add custom Quote properties (currency, terms).
  3. Reps create Quote from Deal → publish → public URL.
  4. Buyer signs + pays (HubSpot Payments).
  5. Quote object stores artifact + status.

Result: Zero-cost doc gen for HubSpot-resident teams.

Example 2: Mid-market — PandaDoc + HubSpot + DocuSign hand-off

Goal: Better template variety + analytics; existing DocuSign for execution.

Steps:

  1. Recipe 9 — HubSpot workflow on stage change.
  2. Recipe 5 — create PandaDoc with template + tokens.
  3. Recipe 6 — send to client.
  4. PandaDoc analytics tracked in PandaDoc; final signed PDF re-routed to DocuSign for audit.
  5. Recipe 8 — attach signed PDF to deal.

Result: Best-of-breed with HubSpot as system of record.

Example 3: Custom legal contract template → DocSpring

Goal: Custom MSA with unique branding; needs precise PDF layout.

Steps:

  1. Author HTML/CSS for MSA in DocSpring UI.
  2. Recipe 10 — render via DocSpring with HubSpot data.
  3. Send via DocuSign envelope.
  4. Recipe 8 — archive on deal.

Result: Pixel-perfect bespoke contracts driven by HubSpot pipeline.

Edge cases / gotchas

Sources

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.