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
+18-16Lines changed: 18 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -297,44 +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
-
- Navigate here to [create a Public API Token]([url](https://app.segment.com/goto-my-workspace/settings/access-management/tokens)), or follow these steps : In your Segment Workspace, navigate to Settings → Workspace settings → Access Management tab → Token tab. On the right, click the `+ Create Token` button. Create a description for the token and assign access. Click `Create` and make sure to save the access token before clicking `Done`.
303
-
- For POST calls, you'll need to use this Public API token in the Authorization Header, as `Bearer Token : public_api_token`
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`
304
305
305
306
### Testing source functions with a webhook
306
307
307
-
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).
308
-
_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 would be routed through your Webhook destination and continue on to the source function: Source → Webhook destination → Source Function._
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._
309
310
310
311
From the source function editor, copy the provided webhook URL (endpoint) from the "Auto-fill via Webhook" dialog.
311
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._
312
313
313
-
In order to test the source function, you must (1) send a `POST` request to the source function's provided endpoint (webhook URL), (2) include an event `body`, and (3) the request must include these Headers :
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:
314
318
-`Content-Type : application/json` or `Content-Type : application/x-www-form-urlencoded`
315
319
-`Authorization : Bearer _your_public_api_token_`
316
320
317
321
### Testing source functions manually
318
322
319
-
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.
320
-
The `Content-Type` Header is required when testing the function :
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:
321
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.
328
-
329
-
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.
330
333
331
334
If you're editing an existing function, you can **Save** changes without updating instances of the function that are already deployed and running.
332
335
333
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.
334
337
335
338
## Source functions logs and errors
336
339
337
-
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).
338
341
339
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.
340
343
@@ -392,7 +395,7 @@ If you are a **Workspace Owner** or **Functions Admin**, you can manage your sou
392
395
393
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.
394
397
395
-
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.
396
399
397
400
Copy and paste this URL into the upstream tool or service to send data to this source.
398
401
@@ -431,5 +434,4 @@ Segment alphabetizes payload fields that come in to **deployed** source function
431
434
432
435
#### Can I use a Source Function in place of adding a Tracking Pixel to my code?
433
436
434
-
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.
435
-
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