You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/connections/functions/source-functions.md
+24-13Lines changed: 24 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -297,35 +297,47 @@ You can test your code directly from the editor in two ways: either by receiving
297
297
298
298
The advantage of testing your source function with webhooks is that all incoming data is real, so you can test behavior while closely mimicking the production conditions.
299
299
300
-
Note that Segment has updated the webhook URL to `api.segmentapis.com/functions`. To use webhooks with your function:
301
-
- You must [generate a public API token](https://docs.segmentapis.com/tag/Getting-Started/#section/Get-an-API-token){:target="_blank"}.
302
-
- For POST calls, you'll need to use this API token in the header.
300
+
Note: Segment has updated the webhook URL to `api.segmentapis.com/functions`. To use webhooks with your function, you must:
301
+
-[Generate a public API token](https://docs.segmentapis.com/tag/Getting-Started/#section/Get-an-API-token){:target="_blank"}.
302
+
-[Create a Public API Token]([url](https://app.segment.com/goto-my-workspace/settings/access-management/tokens)), or follow these steps:
303
+
In your Segment Workspace, navigate to Settings → Workspace settings → Access Management → Token. Click `+ Create Token`. Create a description for the token and assign access. Click `Create` and save the access token before clicking `Done`.
304
+
- For POST calls, use this Public API token in the Authorization Header, as `Bearer Token : public_api_token`
303
305
304
306
### Testing source functions with a webhook
305
307
306
-
You can use webhooks to test the source function either by sending requests manually (using any HTTP client such as cURL or Insomnia) or by pasting the webhook into an external server that supports webhooks (such as Slack).
308
+
You can use webhooks to test the source function either by sending requests manually (using any HTTP client such as cURL, Postman, or Insomnia), or by pasting the webhook into an external server that supports webhooks (such as Slack).
309
+
_A common Segment use case is to connect a Segment [webhooks destination](https://segment.com/docs/connections/destinations/catalog/webhooks/) or [webhook actions destination](https://segment.com/docs/connections/destinations/catalog/actions-webhook/) to a test source, where the Webhook URL/endpoint that is used corresponds to the provided source function's endpoint, then you can trigger test events to send directly to that source, which are routed through your Webhook destination and continue on to the source function: Source → Webhook destination → Source Function._
307
310
308
-
From the source function editor, copy the webhook URL from the "Auto-fill via Webhook" dialog. To trigger the source function, send the request using the `POST` method, with the `Content-Type` header set to `application/json` or `application/x-www-form-urlencoded`.
311
+
From the source function editor, copy the provided webhook URL (endpoint) from the "Auto-fill via Webhook" dialog.
312
+
_**Note** : When a new source is created that utilizes a source function, the new source's endpoint (webhook URL) will differ from the URL that is provided in the source function's test environment._
313
+
314
+
To test the source function:
315
+
1. Send a `POST` request to the source function's provided endpoint (webhook URL)
316
+
2. Include an event `body`
317
+
3. The request must include these Headers:
318
+
-`Content-Type : application/json` or `Content-Type : application/x-www-form-urlencoded`
319
+
-`Authorization : Bearer _your_public_api_token_`
309
320
310
321
### Testing source functions manually
311
322
312
-
You can also manually construct the headers and body of an HTTPS request right inside the editor and test with this data without using webhooks.
323
+
You can also manually construct the headers and body of an HTTPS request inside the editor and test with this data without using webhooks.
324
+
The `Content-Type` Header is required when testing the function:
325
+
-`Content-Type : application/json` or `Content-Type : application/x-www-form-urlencoded`
Once you finish building your source function, click **Configure** to name it, then click **Create Function** to save it.
319
-
320
-
Once you do that, the source function appears on the **Functions** page in your workspace's catalog.
331
+
After you finish building your source function, click **Configure** to name it, then click **Create Function** to save it.
332
+
The source function appears on the **Functions** page in your workspace's catalog.
321
333
322
334
If you're editing an existing function, you can **Save** changes without updating instances of the function that are already deployed and running.
323
335
324
336
You can also choose to **Save & Deploy** to save the changes, and then choose which already-deployed functions to update with your changes. You might need [additional permissions](#source-functions-permissions) to update existing functions.
325
337
326
338
## Source functions logs and errors
327
339
328
-
Your function might encounter errors that you missed during testing, or you might intentionally throw errors in your code (for example, if the incoming request is missing required fields).
340
+
Your function may encounter errors that you missed during testing, or you might intentionally throw errors in your code (for example, if the incoming request is missing required fields).
329
341
330
342
If your function throws an error, execution halts immediately. Segment captures the incoming request, any console logs the function printed, and the error, and displays this information in the function's **Errors** tab. You can use this tab to find and fix unexpected errors.
331
343
@@ -383,7 +395,7 @@ If you are a **Workspace Owner** or **Functions Admin**, you can manage your sou
383
395
384
396
From the [Functions tab](https://app.segment.com/goto-my-workspace/functions/catalog){:target="_blank"}, click **Connect Source** and follow the prompts to set it up in your workspace.
385
397
386
-
Once configured, find the webhook URL - either on the **Overview** or **Settings → Endpoint** page.
398
+
After configuring, find the webhook URL - either on the **Overview** or **Settings → Endpoint** page.
387
399
388
400
Copy and paste this URL into the upstream tool or service to send data to this source.
389
401
@@ -422,5 +434,4 @@ Segment alphabetizes payload fields that come in to **deployed** source function
422
434
423
435
#### Can I use a Source Function in place of adding a Tracking Pixel to my code?
424
436
425
-
No. Tracking Pixels operate client-side only and need to be loaded onto your website directly. Source Functions operate server-side only, and aren't able to capture or implement client-side tracking code. If the tool you're hoping to integrate is server-side, then you can use a Source Function to connect it to Segment.
426
-
437
+
No. Tracking Pixels operate client-side only and need to be loaded onto your website directly. Source Functions operate server-side only, and aren't able to capture or implement client-side tracking code. If the tool you're hoping to integrate is server-side, then you can use a Source Function to connect it to Segment.
0 commit comments