|  | 
|  | 1 | +import { Steps, Tabs } from 'nextra/components' | 
|  | 2 | + | 
|  | 3 | +# Running workflows for your end users | 
|  | 4 | + | 
|  | 5 | +Just like you can build and run internal [workflows](/docs/workflows/) for your team, **you can run workflows for [your end users](/connect/api#external-users), too**. | 
|  | 6 | + | 
|  | 7 | +Whether you're building well-defined integrations or more-autonomous AI agents, workflows provide a powerful set of tools for running [code](/code) or [pre-defined actions](/workflows/actions) on behalf of your users. Pipedream's UI makes it easy to build, test, and [debug](/workflows/inspect) workflows. | 
|  | 8 | + | 
|  | 9 | +## What are workflows? | 
|  | 10 | + | 
|  | 11 | +<div className="mt-4"> | 
|  | 12 | +<img width="500px" src="https://res.cloudinary.com/pipedreamin/image/upload/v1730935490/docs/pCBdtm7Ca9CdPHTe76PwfzddY_qowz2v.avif" /> | 
|  | 13 | +</div> | 
|  | 14 | + | 
|  | 15 | +Workflows are sequences of [steps](/workflows/steps) [triggered by an event](/workflows/triggers), like an HTTP request, or new rows in a Google sheet. | 
|  | 16 | + | 
|  | 17 | +You can use [pre-built actions](/workflows/actions/) or custom [Node.js](/code/nodejs/), [Python](/code/python/), [Golang](/code/go/), or [Bash](/code/bash/) code in workflows and connect to any of our {process.env.PUBLIC_APPS} integrated apps. | 
|  | 18 | + | 
|  | 19 | +Workflows also have built-in: | 
|  | 20 | + | 
|  | 21 | +- [Flow control](/workflows/control-flow) | 
|  | 22 | +- [Concurrency and throttling](/workflows/concurrency-and-throttling) | 
|  | 23 | +- [Key-value stores](/data-stores) | 
|  | 24 | +- [Error handling](/workflows/errors) | 
|  | 25 | +- [VPCs](/workflows/vpc) | 
|  | 26 | +- [And more](https://pipedream.com/pricing) | 
|  | 27 | + | 
|  | 28 | +Read [the quickstart](/quickstart/) to learn more. | 
|  | 29 | + | 
|  | 30 | +## How to run workflows for your end users | 
|  | 31 | + | 
|  | 32 | +<Steps> | 
|  | 33 | + | 
|  | 34 | +### Create an OAuth client | 
|  | 35 | + | 
|  | 36 | +To run workflows for end users, you'll need to first [create an OAuth client](/rest-api/auth#creating-an-oauth-client). This client will be used to authenticate requests to your workflow. | 
|  | 37 | + | 
|  | 38 | +### Create a workflow | 
|  | 39 | + | 
|  | 40 | +[Create a new workflow](/workflows#how-do-i-create-a-new-workflow) or open an existing one. | 
|  | 41 | + | 
|  | 42 | +### Add an HTTP trigger, configure OAuth | 
|  | 43 | + | 
|  | 44 | +1. Add an [HTTP trigger](/workflows/triggers#http) to your workflow | 
|  | 45 | +2. [Configure **OAuth** authorization](/workflows/triggers#oauth) on the trigger | 
|  | 46 | + | 
|  | 47 | +### Configure accounts to use your end users' auth | 
|  | 48 | + | 
|  | 49 | +When you configure [pre-built actions](/workflows/actions) or [custom code that connects to third-party APIs](/code/nodejs/auth), you can link accounts in one of two ways: | 
|  | 50 | + | 
|  | 51 | +1. **Use your own account**: If you're connecting to an API that uses your own app's API key or developer account — for example, a workflow that connects to the OpenAI API — click the **Connect an [app] account** button to link your own, static account. | 
|  | 52 | + | 
|  | 53 | +<div className="my-4"> | 
|  | 54 | +<img width="300px" src="https://res.cloudinary.com/pipedreamin/image/upload/v1730936163/docs/Screenshot_2024-11-06_at_3.35.58_PM_a4evmq.png" /> | 
|  | 55 | +</div> | 
|  | 56 | + | 
|  | 57 | +2. **Use your end users' auth**: If you're building a workflow that connects to your end users' accounts — for example, a workflow that sends a message to a user's Slack account — you can select the option to **Use end user's auth via Connect**: | 
|  | 58 | + | 
|  | 59 | +<div className="my-4"> | 
|  | 60 | +<img width="300px" src="https://res.cloudinary.com/pipedreamin/image/upload/v1730936776/docs/Screenshot_2024-11-06_at_3.46.10_PM_mxjvla.png" /> | 
|  | 61 | +</div> | 
|  | 62 | + | 
|  | 63 | +This looks up the end user's account for this app, based on the user ID you provide [when invoking the workflow](#invoke-the-workflow). | 
|  | 64 | + | 
|  | 65 | +When you're done with the workflow, **Deploy** it. | 
|  | 66 | + | 
|  | 67 | +### Connect a test account | 
|  | 68 | + | 
|  | 69 | +You can connect a static account to the workflow step to test it, but to run an end-to-end test as an end user, you'll need to [invoke the workflow](#invoke-the-workflow) with a user ID that has linked a Connect account. | 
|  | 70 | + | 
|  | 71 | +You'll see all accounts by end user ID in [the **Users** tab](/connect#users) of your Connect dashboard. If you already have a test account linked, get the external user ID and [invoke the workflow](#invoke-the-workflow). | 
|  | 72 | + | 
|  | 73 | +If you've don't have a test account, create one: | 
|  | 74 | + | 
|  | 75 | +- If you've already [added Connect to your app](/connect), run through your own app's integrations flow and link test accounts for the apps you're using. | 
|  | 76 | +- You can also run [the Connect example app](/connect/quickstart) to quickly connect an account for any app. | 
|  | 77 | + | 
|  | 78 | +### Invoke the workflow | 
|  | 79 | + | 
|  | 80 | +If you haven't already, [install the Pipedream SDK](/connect/api#installing-the-typescript-sdk): | 
|  | 81 | + | 
|  | 82 | +```bash | 
|  | 83 | +npm install @pipedream/sdk | 
|  | 84 | +``` | 
|  | 85 | + | 
|  | 86 | +To invoke workflows, you'll need: | 
|  | 87 | + | 
|  | 88 | +1. The OAuth client ID and secret from **Step 1** | 
|  | 89 | +2. Your [Project ID](/projects#finding-your-projects-id) | 
|  | 90 | +3. Your workflow's HTTP endpoint URL | 
|  | 91 | +4. The [external user ID](/connect/api#external-users) of the user you'd like to run the workflow for | 
|  | 92 | + | 
|  | 93 | +```javascript | 
|  | 94 | +import { createBackendClient } from "@pipedream/sdk"; | 
|  | 95 | + | 
|  | 96 | +const client = createBackendClient({ | 
|  | 97 | +  environment: "development", // change to production if running for a test production account, or in production | 
|  | 98 | +  credentials: { | 
|  | 99 | +    clientId: "your-client-id",  | 
|  | 100 | +    clientSecret: "your-client-secret" | 
|  | 101 | +  }, | 
|  | 102 | +  projectId: "your-project-id" | 
|  | 103 | +}); | 
|  | 104 | + | 
|  | 105 | +const response = await client.invokeWorkflowForExternalUser( | 
|  | 106 | +  "your-workflow-endpoint-url", | 
|  | 107 | +  "your-external-user-id", | 
|  | 108 | +  { | 
|  | 109 | +    method: "POST", | 
|  | 110 | +    body: { | 
|  | 111 | +      message: "Hello World" | 
|  | 112 | +    } | 
|  | 113 | +  } | 
|  | 114 | +) | 
|  | 115 | +``` | 
|  | 116 | + | 
|  | 117 | +</Steps> | 
|  | 118 | + | 
|  | 119 | +## Errors | 
0 commit comments