Skip to content

Commit d0dfeb0

Browse files
authored
Merge pull request #6161 from segmentio/lizkane222-patch-1
Update source-functions.md with Public API Key details and other small changes
2 parents 612650b + 17aabef commit d0dfeb0

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

src/connections/functions/source-functions.md

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -297,35 +297,47 @@ You can test your code directly from the editor in two ways: either by receiving
297297

298298
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.
299299

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`
303305

304306
### Testing source functions with a webhook
305307

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._
307310

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_`
309320

310321
### Testing source functions manually
311322

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`
313326

314327
![Test HTTPS Request](images/test-manual.png){:width="500"}
315328

316329
## Save and deploy the function
317330

318-
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.
321333

322334
If you're editing an existing function, you can **Save** changes without updating instances of the function that are already deployed and running.
323335

324336
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.
325337

326338
## Source functions logs and errors
327339

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).
329341

330342
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.
331343

@@ -383,7 +395,7 @@ If you are a **Workspace Owner** or **Functions Admin**, you can manage your sou
383395
384396
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.
385397

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.
387399

388400
Copy and paste this URL into the upstream tool or service to send data to this source.
389401

@@ -422,5 +434,4 @@ Segment alphabetizes payload fields that come in to **deployed** source function
422434

423435
#### Can I use a Source Function in place of adding a Tracking Pixel to my code?
424436

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

Comments
 (0)