# Aggregate zendesk tickets with hubspot deals

> Zendesk open tickets and related HubSpot deal stage in one Retool query. For "aggregate zendesk tickets with hubspot deals", store ZENDESK_API_TOKEN, HUBSPOT_ACCESS_TOKEN in Secret Vault, call https://{{secrets.ZENDESK_SUBDOMAIN}}.zendesk.com/api/v2/tickets.json from a Worker, and let Retool hit only https://realcomposer.com/v1/workspace/aggregate-zendesk-with-hubspot-deals with an rc_live_ client token.

- Canonical page: https://realcomposer.com/recipes/aggregate-zendesk-with-hubspot-deals
- Client platform: Retool
- Upstream services: Zendesk, HubSpot
- Category: Multi-API Aggregation
- JSON version: https://realcomposer.com/recipes/aggregate-zendesk-with-hubspot-deals.json
- Install in RealComposer (free plan, pre-fills this pipeline): https://realcomposer.com/dashboard/pipelines/new?recipe=aggregate-zendesk-with-hubspot-deals&via=agent

## Problem: Serial Zendesk and HubSpot calls slow Retool pages

Each extra Zendesk and HubSpot hop adds hundreds of milliseconds and another OAuth refresh path your UI must manage.

- One slow upstream blocking an entire page
- Partial failures leaving UI in inconsistent states
- Duplicate auth refresh logic per service

## Solution steps

1. **Bind vault keys to the Worker**: Create ZENDESK_API_TOKEN, HUBSPOT_ACCESS_TOKEN vault entries, then bind them to this pipeline step headers with {{secrets.NAME}} placeholders.

2. **Set headers, mapping, and cache TTL**: Use GET against https://{{secrets.ZENDESK_SUBDOMAIN}}.zendesk.com/api/v2/tickets.json. Allowed origins on the client token should match leave cache ttl at 0 when each response is user-specific (include userid or record id in query params before enabling cache).

3. **Query from Retool**: Call https://realcomposer.com/v1/workspace/aggregate-zendesk-with-hubspot-deals with a restricted rc_live_ client token. Retool never sends upstream secrets.

```
// REST resource or JS query
const rows = await fetch('https://realcomposer.com/v1/workspace/aggregate-zendesk-with-hubspot-deals', {
  headers: { Authorization: 'Bearer rc_live_token' }
}).then(r => r.json());
```

## Pipeline config

Import this config into a RealComposer pipeline. `{{secrets.NAME}}` values are read from the encrypted Secret Vault at request time, so the client never sees them.

```json
{
  "name": "Aggregate zendesk tickets with hubspot deals",
  "method": "GET",
  "cacheTtlSeconds": 0,
  "authMode": "client_token",
  "steps": [
    {
      "stepKey": "zendesk",
      "upstreamUrlTemplate": "https://{{secrets.ZENDESK_SUBDOMAIN}}.zendesk.com/api/v2/tickets.json",
      "httpMethod": "GET",
      "headersTemplate": {
        "Authorization": "Bearer {{secrets.ZENDESK_API_TOKEN}}"
      },
      "timeoutMs": 3000
    },
    {
      "stepKey": "hubspot",
      "upstreamUrlTemplate": "https://api.hubapi.com/crm/v3/objects/deals?limit=10",
      "httpMethod": "GET",
      "headersTemplate": {
        "Authorization": "Bearer {{secrets.HUBSPOT_ACCESS_TOKEN}}"
      },
      "timeoutMs": 3000
    }
  ],
  "outputMapping": {
    "version": 1,
    "fields": [
      {
        "targetPath": "zendesk.ticketId",
        "sourcePath": "tickets.0.id",
        "type": "number",
        "sourceStep": "zendesk"
      },
      {
        "targetPath": "zendesk.subject",
        "sourcePath": "tickets.0.subject",
        "type": "string",
        "sourceStep": "zendesk"
      },
      {
        "targetPath": "hubspot.contactId",
        "sourcePath": "id",
        "type": "string",
        "sourceStep": "hubspot"
      },
      {
        "targetPath": "hubspot.email",
        "sourcePath": "properties.email",
        "type": "string",
        "sourceStep": "hubspot"
      }
    ]
  }
}
```

## Call the pipeline

```bash
curl -X GET "https://realcomposer.com/v1/workspace/aggregate-zendesk-with-hubspot-deals" \
  -H "Authorization: Bearer rc_live_client_token"
```

## Payload before and after

Raw upstream response:

```json
{
  "requestId": "req_aggregat",
  "upstreamLatencyMs": 142,
  "audit": {
    "region": "edge",
    "trace": "aggregate-zendesk-with-hubspot-deals"
  },
  "payload": {
    "id": "sample_id",
    "status": "active",
    "nested": {
      "tags": [
        "demo"
      ],
      "internal": true
    },
    "unused_blob": {
      "foo": "bar",
      "bar": "baz"
    }
  }
}
```

Slimmed RealComposer response:

```json
{
  "zendesk_ticketId": "sample",
  "zendesk_subject": "sample",
  "hubspot_contactId": "sample",
  "hubspot_email": "sample"
}
```

## FAQ

### Is it safe to log Zendesk responses in Retool?

Store ZENDESK_API_TOKEN, HUBSPOT_ACCESS_TOKEN for aggregate-zendesk-with-hubspot-deals. Retool never sees decrypted values.

### When does edge caching apply to this recipe?

aggregate-zendesk-with-hubspot-deals vault headers attach server-side, but Anthropic or OpenAI model and messages must come from the client body.

### How do I rotate upstream credentials?

Allowed origins on the aggregate-zendesk-with-hubspot-deals client token restrict which domains may call the edge URL.
