0

Get customer by external ID

by
Published Oct 17, 2025

Retrieves a customer based on their unique external ID. The `externalId` is typically the ID of the customer within your database or an external service. This provides a unique way to create and identify users by mapping a unique customer ID in Kustomer to a unique customer ID in an external system. Any one of the following roles is required for this endpoint: |Legacy Role|Equivalent Permission Set Role| |-----|--------| |org.user.customer.read|org.permission.customer.read|

Script kustomer Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Kustomer = {
3
  apiKey: string;
4
};
5
/**
6
 * Get customer by external ID
7
 * Retrieves a customer based on their unique external ID.
8

9
The `externalId` is typically the ID of the customer within your database or an external service.
10

11
This provides a unique way to create and identify users by mapping a unique customer ID in Kustomer to a unique customer ID in an external system.
12

13
Any one of the following roles is required for this endpoint:
14

15
|Legacy Role|Equivalent Permission Set Role|
16
|-----|--------|
17
|org.user.customer.read|org.permission.customer.read|
18
 */
19
export async function main(auth: Kustomer, externalId: string) {
20
  const url = new URL(
21
    `https://api.kustomerapp.com/v1/customers/externalId=${externalId}`,
22
  );
23

24
  const response = await fetch(url, {
25
    method: "GET",
26
    headers: {
27
      Authorization: "Bearer " + auth.apiKey,
28
    },
29
    body: undefined,
30
  });
31
  if (!response.ok) {
32
    const text = await response.text();
33
    throw new Error(`${response.status} ${text}`);
34
  }
35
  return await response.json();
36
}
37