Skip to content

Commit 505f170

Browse files
Adding info re: emitting to workflows (#15442)
1 parent 8aac563 commit 505f170

File tree

3 files changed

+134
-13
lines changed

3 files changed

+134
-13
lines changed

docs-v2/pages/connect/api.mdx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,9 @@ curl -X POST https://api.pipedream.com/v1/connect/rate_limits \
205205

206206
**Example usage**
207207

208-
```
209-
# The response will include a rate limit token. Pass it as a header in your downstream requests to the Connect API.
208+
```bash
209+
# The response will include a rate limit token.
210+
# Pass it as a header in your downstream requests to the Connect API.
210211
# Below is an example request that runs the "List Commits" action for the Gitlab app.
211212

212213
curl -X POST "https://api.pipedream.com/v1/connect/{your_project_id}/actions/run" \
@@ -2009,7 +2010,7 @@ curl -X POST "https://api.pipedream.com/v1/connect/{your_project_id}/actions/run
20092010

20102011
#### Deploy a trigger
20112012

2012-
Deploy a trigger component for a Pipedream Connect user in a project.
2013+
Deploy a trigger component that will emit events to a webhook or workflow for a Pipedream Connect user.
20132014

20142015
```text
20152016
POST /triggers/deploy
@@ -2039,12 +2040,22 @@ which you want to execute the action.
20392040

20402041
---
20412042

2042-
`webhook_url` **string**
2043+
`webhook_url` **string** (_optional_)
20432044

20442045
The URL to which the trigger will send events.
20452046

20462047
---
20472048

2049+
`workflow_url` **string** (_optional_)
2050+
2051+
The Pipedream workflow ID to which you want to emit events (ex, `p_1234567`).
2052+
2053+
<Callout type="warning">
2054+
The workflow must be in the same Pipedream project as the trigger.
2055+
</Callout>
2056+
2057+
---
2058+
20482059
`dynamic_props_id` **string** (_optional_)
20492060

20502061
The ID of the last prop reconfiguration (if applicable).

docs-v2/pages/connect/workflows.mdx

Lines changed: 117 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,16 @@ Read [the quickstart](/quickstart/) to learn more.
3838

3939
[Create a new workflow](/workflows#how-do-i-create-a-new-workflow) or open an existing one.
4040

41-
### Add an HTTP trigger, configure OAuth
41+
### Add an HTTP trigger
4242

43-
1. Add an [HTTP trigger](/workflows/triggers#http) to your workflow.
44-
2. [Configure **OAuth** authorization](/workflows/triggers#oauth) on the trigger.
43+
To get started building workflows for your end users:
4544

46-
<Callout type="info">
47-
To securely run workflows for end users, **configuring OAuth authorization on the trigger is optional but strongly recommended.** [Create a Pipedream OAuth client](/rest-api/auth#creating-an-oauth-client) to authenticate requests to the Pipedream API and workflows.
48-
</Callout>
45+
1. Add an [HTTP trigger](/workflows/triggers#http) to your workflow
46+
2. Generate a test event with the required headers:
47+
- `x-pd-environment: development`
48+
- `x-pd-external-user-id: {your_external_user_id}`
49+
50+
See the [Triggering your workflow](#triggering-your-workflow) section below for details on securing your workflow with OAuth and deploying triggers on behalf of your end users.
4951

5052
### Configure accounts to use your end users' auth
5153

@@ -235,7 +237,7 @@ curl -X POST https://{your-endpoint-url} \
235237
We plan to improve this interface in the future, and potentially allow developers to store end user metadata and configuration data alongside the connected account for your end users, so you won't need to pass the data at runtime. [Let us know](https://pipedream.com/support) if that's a feature you'd like to see.
236238
</Callout>
237239

238-
## Testing workflow steps
240+
## Testing
239241

240242
To test a step using the connected account of one of your end users in the builder, you'll need a few things to be configured so that your workflow knows which account to use.
241243

@@ -252,6 +254,114 @@ To test a step using the connected account of one of your end users in the build
252254

253255
<Image src="https://res.cloudinary.com/pipedreamin/image/upload/v1733533298/pd-connect-headers_c1x7an.png" alt="Include required headers" width={600} height={529} />
254256

257+
## Triggering your workflow
258+
259+
You have two options for triggering workflows that run on behalf of your end users:
260+
261+
1. [Invoke via HTTP webhook](#http-webhook)
262+
2. [Deploy an event source](#deploy-an-event-source) (Slack, Gmail, etc.)
263+
264+
### HTTP Webhook
265+
266+
The most common way to trigger workflows is via HTTP webhook. We strongly recommend [creating a Pipedream OAuth client](/rest-api/auth#creating-an-oauth-client) and authenticating inbound requests to your workflows.
267+
268+
To get started, you'll need:
269+
270+
- [OAuth client ID and secret](/rest-api/auth#creating-an-oauth-client) (optional but recommended)
271+
- Your [project ID](/projects#finding-your-projects-id)
272+
- Your workflow's HTTP endpoint URL
273+
- The [external user ID](/connect/api#external-users) of your end user
274+
- The [Connect environment](/connect/environments)
275+
276+
<Tabs items={['TypeScript', 'Node.js', 'HTTP (cURL)']}>
277+
<Tabs.Tab>
278+
```typescript
279+
import { createBackendClient, HTTPAuthType } from "@pipedream/sdk/server";
280+
281+
// These secrets should be saved securely and passed to your environment
282+
const pd = createBackendClient({
283+
environment: "development", // change to production if running for a test production account, or in production
284+
credentials: {
285+
clientId: "{oauth_client_id}",
286+
clientSecret: "{oauth_client_secret}",
287+
},
288+
projectId: "{your_project_id}"
289+
});
290+
291+
await pd.invokeWorkflowForExternalUser(
292+
"{your_endpoint_url}", // pass the endpoint ID or full URL here
293+
"{your_external_user_id}" // The end user's ID in your system
294+
{
295+
method: "POST",
296+
body: {
297+
message: "Hello World"
298+
}
299+
},
300+
HTTPAuthType.OAuth // Will automatically send the Authorization header with a fresh token
301+
)
302+
```
303+
</Tabs.Tab>
304+
<Tabs.Tab>
305+
```javascript
306+
import { createBackendClient } from "@pipedream/sdk/server";
307+
308+
// These secrets should be saved securely and passed to your environment
309+
const client = createBackendClient({
310+
environment: "development", // change to production if running for a test production account, or in production
311+
credentials: {
312+
clientId: "{oauth_client_id}",
313+
clientSecret: "{oauth_client_secret}"
314+
},
315+
projectId: "{your_project_id}"
316+
});
317+
318+
const response = await client.invokeWorkflowForExternalUser(
319+
"{your_endpoint_url}", // pass the endpoint ID or full URL here
320+
"{your_external_user_id}" // The end user's ID in your system
321+
{
322+
method: "POST",
323+
body: {
324+
message: "Hello World"
325+
}
326+
}
327+
)
328+
```
329+
</Tabs.Tab>
330+
<Tabs.Tab>
331+
```bash
332+
# First, obtain an OAuth access token
333+
curl -X POST https://api.pipedream.com/v1/oauth/token \
334+
-H "Content-Type: application/json" \
335+
-d '{
336+
"grant_type": "client_credentials",
337+
"client_id": "{oauth_client_id}",
338+
"client_secret": "{oauth_client_secret}"
339+
}'
340+
341+
# The response will include an access_token. Use it in the Authorization header below.
342+
343+
curl -X POST https://{your-endpoint-url} \
344+
-H "Content-Type: application/json" \
345+
-H "Authorization: Bearer {access_token}" \
346+
-H 'X-PD-External-User-ID: {your_external_user_id}' \
347+
-H 'X-PD-Environment: development' \ # 'development' or 'production'
348+
-d '{
349+
"message": "Hello, world"
350+
}'
351+
```
352+
</Tabs.Tab>
353+
</Tabs>
354+
355+
### Deploy an event source
356+
357+
You can [programmatically deploy triggers via the API](/connect/api#deploy-a-trigger) to have events from integrated apps (like [new Slack messages](/apps/slack/triggers/new-message-in-channels) or [new emails in Gmail](/apps/gmail/triggers/new-email-received)) trigger your workflow. This allows you to:
358+
359+
- Deploy triggers for specific users from your application
360+
- Configure trigger parameters per-user
361+
- Manage deployed triggers via the API
362+
363+
See the [API documentation](/connect/api#deploy-a-trigger) for detailed examples of deploying and managing triggers.
364+
255365
## Troubleshooting
256366

257367
For help debugging issues with your workflow, you can return verbose error messages to the caller by configuring the HTTP trigger to **Return a custom response from your workflow**.

pnpm-lock.yaml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)