|
| 1 | +import { Tabs, Callout, Steps } from "nextra/components"; |
| 2 | + |
| 3 | +# Mailchimp |
| 4 | + |
| 5 | +The Mailchimp auth provider enables tools and agents to call [Mailchimp Marketing APIs](https://mailchimp.com/developer/marketing/api/) on behalf of a user using OAuth 2.0 authentication. |
| 6 | + |
| 7 | +<Callout> |
| 8 | + Want to quickly get started with Mailchimp in your agent or AI app? The |
| 9 | + pre-built [Arcade Mailchimp Marketing MCP Server](/mcp-servers/productivity/mailchimp-marketing-api) |
| 10 | + is what you want! |
| 11 | +</Callout> |
| 12 | + |
| 13 | +### What's documented here |
| 14 | + |
| 15 | +This page describes how to use and configure Mailchimp auth with Arcade. |
| 16 | + |
| 17 | +This auth provider is used by: |
| 18 | + |
| 19 | +- The [Arcade Mailchimp Marketing MCP Server](/mcp-servers/productivity/mailchimp-marketing-api), which provides pre-built tools for interacting with Mailchimp |
| 20 | +- Your [app code](#using-mailchimp-auth-in-app-code) that needs to call the Mailchimp API |
| 21 | +- Or, your [custom tools](#using-mailchimp-auth-in-custom-tools) that need to call the Mailchimp API |
| 22 | + |
| 23 | +## Configuring Mailchimp auth |
| 24 | + |
| 25 | +<Callout type="info"> |
| 26 | + When using your own app credentials, make sure you configure your project to |
| 27 | + use a [custom user |
| 28 | + verifier](/home/auth/secure-auth-production#build-a-custom-user-verifier). |
| 29 | + Without this, your end-users will not be able to use your app or agent in |
| 30 | + production. |
| 31 | +</Callout> |
| 32 | + |
| 33 | +In a production environment, you will most likely want to use your own Mailchimp app credentials. This way, your users will see your application's name requesting permission. |
| 34 | + |
| 35 | +Before showing how to configure your Mailchimp app credentials, let's go through the steps to create a Mailchimp app. |
| 36 | + |
| 37 | +### Create a Mailchimp app |
| 38 | + |
| 39 | +To integrate with Mailchimp's API, you'll need to register an OAuth application: |
| 40 | + |
| 41 | +<Steps> |
| 42 | + |
| 43 | +#### Log into your Mailchimp account |
| 44 | + |
| 45 | +1. Navigate to [mailchimp.com](https://mailchimp.com) and log in to your account |
| 46 | +2. Go to **Account** > **Extras** > **Registered Apps** |
| 47 | +3. Alternatively, you can directly access the [Registered Apps page](https://admin.mailchimp.com/account/oauth2/) |
| 48 | + |
| 49 | +#### Register a new OAuth application |
| 50 | + |
| 51 | +1. Click on **Register an App** |
| 52 | +2. Fill in the required details: |
| 53 | + - **Application Name**: Choose a descriptive name for your application |
| 54 | + - **Company/Organization**: Enter your company or organization name |
| 55 | + - **Website URL**: Your application's website URL |
| 56 | + - **Description**: Brief description of your application |
| 57 | + - **Redirect URI**: Add the redirect URL generated by Arcade (see configuration section below) |
| 58 | + - This is the URL where Mailchimp will redirect users after authorization |
| 59 | + - For development, you can use `http://localhost:9099/oauth/callback` or your Arcade instance URL |
| 60 | + |
| 61 | +#### Save your credentials |
| 62 | + |
| 63 | +1. After registration, you'll receive your **Client ID** and **Client Secret** |
| 64 | +2. **Important**: Copy and save these credentials immediately in a secure location |
| 65 | +3. You can always view your Client ID later, but the Client Secret should be stored securely |
| 66 | + |
| 67 | +</Steps> |
| 68 | + |
| 69 | +For detailed instructions, refer to Mailchimp's [OAuth 2.0 documentation](https://mailchimp.com/developer/marketing/guides/access-user-data-oauth-2/) and [API documentation](https://mailchimp.com/developer/marketing/api/). |
| 70 | + |
| 71 | +Next, add the Mailchimp app to Arcade. |
| 72 | + |
| 73 | +## Configuring your own Mailchimp Auth Provider in Arcade |
| 74 | + |
| 75 | +<Tabs items={["Dashboard GUI", "Configuration File"]}> |
| 76 | +<Tabs.Tab> |
| 77 | + |
| 78 | +### Configure Mailchimp Auth Using the Arcade Dashboard GUI |
| 79 | + |
| 80 | +<Steps> |
| 81 | + |
| 82 | +#### Access the Arcade Dashboard |
| 83 | + |
| 84 | +To access the Arcade Cloud dashboard, go to [api.arcade.dev/dashboard](https://api.arcade.dev/dashboard). If you are self-hosting, by default the dashboard will be available at http://localhost:9099/dashboard. Adjust the host and port number to match your environment. |
| 85 | + |
| 86 | +#### Navigate to the OAuth Providers page |
| 87 | + |
| 88 | +- Under the **OAuth** section of the Arcade Dashboard left-side menu, click **Providers**. |
| 89 | +- Click **Add OAuth Provider** in the top right corner. |
| 90 | +- Select the **OAuth 2.0** tab at the top. |
| 91 | + |
| 92 | +#### Enter the provider details |
| 93 | + |
| 94 | +- Choose a unique **ID** for your provider (e.g. "arcade-mailchimp"). |
| 95 | +- Optionally enter a **Description**. |
| 96 | +- Enter the **Client ID** and **Client Secret** from your Mailchimp app. |
| 97 | +- Configure the OAuth 2.0 endpoints: |
| 98 | + - **Authorization URL**: `https://login.mailchimp.com/oauth2/authorize` |
| 99 | + - **Token URL**: `https://login.mailchimp.com/oauth2/token` |
| 100 | +- Note the **Redirect URL** generated by Arcade. This must be set as your Mailchimp app's Redirect URI. |
| 101 | + |
| 102 | +#### Create the provider |
| 103 | + |
| 104 | +Hit the **Create** button and the provider will be ready to be used. |
| 105 | + |
| 106 | +</Steps> |
| 107 | + |
| 108 | +</Tabs.Tab> |
| 109 | + |
| 110 | +<Tabs.Tab> |
| 111 | + |
| 112 | +### Configure Mailchimp Auth Using Configuration File |
| 113 | + |
| 114 | +<Callout type="info"> |
| 115 | + This method is only available when you are [self-hosting the |
| 116 | + engine](/home/deployment/on-prem-mcp) |
| 117 | +</Callout> |
| 118 | + |
| 119 | +<Steps> |
| 120 | + |
| 121 | +#### Set environment variables |
| 122 | + |
| 123 | +Set the following environment variables: |
| 124 | + |
| 125 | +```bash |
| 126 | +export MAILCHIMP_CLIENT_ID="<your client ID>" |
| 127 | +export MAILCHIMP_CLIENT_SECRET="<your client secret>" |
| 128 | +``` |
| 129 | + |
| 130 | +Or, you can set these values in a `.env` file: |
| 131 | + |
| 132 | +```bash |
| 133 | +MAILCHIMP_CLIENT_ID="<your client ID>" |
| 134 | +MAILCHIMP_CLIENT_SECRET="<your client secret>" |
| 135 | +``` |
| 136 | + |
| 137 | +#### Edit the Engine configuration |
| 138 | + |
| 139 | +Edit the `engine.yaml` file and add a new item to the `auth.providers` section: |
| 140 | + |
| 141 | +```yaml |
| 142 | +auth: |
| 143 | + providers: |
| 144 | + - id: arcade-mailchimp |
| 145 | + description: Mailchimp OAuth 2.0 provider |
| 146 | + enabled: true |
| 147 | + type: oauth2 |
| 148 | + client_id: ${env:MAILCHIMP_CLIENT_ID} |
| 149 | + client_secret: ${env:MAILCHIMP_CLIENT_SECRET} |
| 150 | + oauth2: |
| 151 | + authorize_request: |
| 152 | + endpoint: "https://login.mailchimp.com/oauth2/authorize" |
| 153 | + params: |
| 154 | + response_type: code |
| 155 | + client_id: "{{client_id}}" |
| 156 | + redirect_uri: "{{redirect_uri}}" |
| 157 | + state: "{{state}}" |
| 158 | + token_request: |
| 159 | + endpoint: "https://login.mailchimp.com/oauth2/token" |
| 160 | + params: |
| 161 | + grant_type: authorization_code |
| 162 | + client_id: "{{client_id}}" |
| 163 | + client_secret: "{{client_secret}}" |
| 164 | + redirect_uri: "{{redirect_uri}}" |
| 165 | + response_content_type: application/json |
| 166 | +``` |
| 167 | +
|
| 168 | +</Steps> |
| 169 | +
|
| 170 | +</Tabs.Tab> |
| 171 | +</Tabs> |
| 172 | +
|
| 173 | +When you use tools that require Mailchimp auth using your Arcade account credentials, Arcade will automatically use this Mailchimp OAuth provider. If you have multiple Mailchimp providers, see [using multiple auth providers of the same type](/home/auth-providers#using-multiple-providers-of-the-same-type) for more information. |
| 174 | +
|
| 175 | +## Using Mailchimp auth in app code |
| 176 | +
|
| 177 | +Use the Mailchimp auth provider in your own agents and AI apps to get a user token for the Mailchimp API. See [authorizing agents with Arcade](/home/auth/how-arcade-helps) to understand how this works. |
| 178 | +
|
| 179 | +Use `client.auth.start()` to get a user token for the Mailchimp API: |
| 180 | + |
| 181 | +<Tabs items={["Python", "JavaScript"]} storageKey="preferredLanguage"> |
| 182 | +<Tabs.Tab> |
| 183 | + |
| 184 | +```python {8-12} |
| 185 | +from arcadepy import Arcade |
| 186 | +
|
| 187 | +client = Arcade() # Automatically finds the `ARCADE_API_KEY` env variable |
| 188 | + |
| 189 | +user_id = "{arcade_user_id}" |
| 190 | + |
| 191 | +# Start the authorization process |
| 192 | +auth_response = client.auth.start( |
| 193 | + user_id=user_id, |
| 194 | + provider="arcade-mailchimp" |
| 195 | +) |
| 196 | + |
| 197 | +if auth_response.status != "completed": |
| 198 | + print("Please complete the authorization challenge in your browser:") |
| 199 | + print(auth_response.url) |
| 200 | + |
| 201 | +# Wait for the authorization to complete |
| 202 | +auth_response = client.auth.wait_for_completion(auth_response) |
| 203 | + |
| 204 | +token = auth_response.context.token |
| 205 | +# Do something interesting with the token... |
| 206 | +``` |
| 207 | + |
| 208 | +</Tabs.Tab> |
| 209 | + |
| 210 | +<Tabs.Tab> |
| 211 | + |
| 212 | +```javascript {8-11} |
| 213 | +import { Arcade } from "@arcadeai/arcadejs"; |
| 214 | + |
| 215 | +const client = new Arcade(); |
| 216 | + |
| 217 | +const userId = "{arcade_user_id}"; |
| 218 | + |
| 219 | +// Start the authorization process |
| 220 | +const authResponse = await client.auth.start(userId, "arcade-mailchimp"); |
| 221 | + |
| 222 | +if (authResponse.status !== "completed") { |
| 223 | + console.log("Please complete the authorization challenge in your browser:"); |
| 224 | + console.log(authResponse.url); |
| 225 | +} |
| 226 | + |
| 227 | +// Wait for the authorization to complete |
| 228 | +authResponse = await client.auth.waitForCompletion(authResponse); |
| 229 | + |
| 230 | +const token = authResponse.context.token; |
| 231 | +// Do something interesting with the token... |
| 232 | +``` |
| 233 | + |
| 234 | +</Tabs.Tab> |
| 235 | + |
| 236 | +</Tabs> |
| 237 | + |
| 238 | +### Getting the API endpoint |
| 239 | + |
| 240 | +Mailchimp requires you to determine the correct API endpoint for each user. After obtaining the access token, make a request to the metadata endpoint: |
| 241 | + |
| 242 | +<Tabs items={["Python", "JavaScript"]} storageKey="preferredLanguage"> |
| 243 | +<Tabs.Tab> |
| 244 | + |
| 245 | +```python |
| 246 | +import httpx |
| 247 | + |
| 248 | +# Get the user's API endpoint |
| 249 | +async with httpx.AsyncClient() as client: |
| 250 | + metadata_response = await client.get( |
| 251 | + "https://login.mailchimp.com/oauth2/metadata", |
| 252 | + headers={"Authorization": f"Bearer {token}"} |
| 253 | + ) |
| 254 | + metadata = metadata_response.json() |
| 255 | + api_endpoint = metadata["api_endpoint"] |
| 256 | + |
| 257 | +# Now use the api_endpoint for all API calls |
| 258 | +# Example: f"{api_endpoint}/3.0/lists" |
| 259 | +``` |
| 260 | + |
| 261 | +</Tabs.Tab> |
| 262 | + |
| 263 | +<Tabs.Tab> |
| 264 | + |
| 265 | +```javascript |
| 266 | +// Get the user's API endpoint |
| 267 | +const metadataResponse = await fetch( |
| 268 | + "https://login.mailchimp.com/oauth2/metadata", |
| 269 | + { |
| 270 | + headers: { Authorization: `Bearer ${token}` } |
| 271 | + } |
| 272 | +); |
| 273 | +const metadata = await metadataResponse.json(); |
| 274 | +const apiEndpoint = metadata.api_endpoint; |
| 275 | + |
| 276 | +// Now use the apiEndpoint for all API calls |
| 277 | +// Example: `${apiEndpoint}/3.0/lists` |
| 278 | +``` |
| 279 | + |
| 280 | +</Tabs.Tab> |
| 281 | + |
| 282 | +</Tabs> |
| 283 | + |
| 284 | +## Using Mailchimp auth in custom tools |
| 285 | + |
| 286 | +You can use the pre-built [Arcade Mailchimp Marketing MCP Server](/mcp-servers/productivity/mailchimp-marketing-api) to quickly build agents and AI apps that interact with Mailchimp. |
| 287 | + |
| 288 | +If the pre-built tools in the Mailchimp MCP Server don't meet your needs, you can author your own [custom tools](/home/build-tools/create-a-mcp-server) that interact with the Mailchimp API. |
| 289 | + |
| 290 | +Use the `OAuth2()` auth class to specify that a tool requires authorization with Mailchimp. The `context.authorization.token` field will be automatically populated with the user's Mailchimp token: |
| 291 | + |
| 292 | +```python {8-12,24} |
| 293 | +from typing import Annotated |
| 294 | + |
| 295 | +import httpx |
| 296 | +from arcade_tdk import ToolContext, tool |
| 297 | +from arcade_tdk.auth import OAuth2 |
| 298 | + |
| 299 | + |
| 300 | +@tool( |
| 301 | + requires_auth=OAuth2(provider_id="arcade-mailchimp") |
| 302 | +) |
| 303 | +async def get_mailchimp_lists( |
| 304 | + context: ToolContext, |
| 305 | +) -> Annotated[dict, "The user's Mailchimp lists."]: |
| 306 | + """ |
| 307 | + Retrieve all mailing lists from the authenticated user's Mailchimp account. |
| 308 | + """ |
| 309 | + # First, get the API endpoint for this user |
| 310 | + async with httpx.AsyncClient() as client: |
| 311 | + metadata_response = await client.get( |
| 312 | + "https://login.mailchimp.com/oauth2/metadata", |
| 313 | + headers={"Authorization": f"Bearer {context.authorization.token}"} |
| 314 | + ) |
| 315 | + api_endpoint = metadata_response.json()["api_endpoint"] |
| 316 | + |
| 317 | + # Now get the lists |
| 318 | + response = await client.get( |
| 319 | + f"{api_endpoint}/3.0/lists", |
| 320 | + headers={"Authorization": f"Bearer {context.authorization.token}"} |
| 321 | + ) |
| 322 | + response.raise_for_status() |
| 323 | + return dict(response.json()) |
| 324 | +``` |
| 325 | + |
| 326 | +<Callout type="info"> |
| 327 | + **Important**: Mailchimp access tokens do not expire unless the user revokes access. However, it's good practice to handle potential errors gracefully and provide users with options to re-authenticate if necessary. |
| 328 | +</Callout> |
| 329 | + |
| 330 | +For more details about Mailchimp's authentication, refer to the [Mailchimp OAuth 2.0 documentation](https://mailchimp.com/developer/marketing/guides/access-user-data-oauth-2/). |
| 331 | + |
0 commit comments