//native
type Klaviyo = {
apiKey: string;
};
/**
* Get Segment
* Get a segment with the given segment ID.*Rate limits*:Burst: `75/s`Steady: `700/m`Rate limits when using the `additional-fields[segment]=profile_count` parameter in your API request:Burst: `1/s`Steady: `15/m`To learn more about how the `additional-fields` parameter impacts rate limits, check out our [Rate limits, status codes, and errors](https://developers.klaviyo.com/en/v2024-10-15/docs/rate_limits_and_error_handling) guide.
*/
export async function main(
auth: Klaviyo,
id: string,
additional_fields_segment_: string | undefined,
fields_flow_: string | undefined,
fields_segment_: string | undefined,
fields_tag_: string | undefined,
include: string | undefined,
revision: string,
) {
const url = new URL(`https://a.klaviyo.com/api/segments/${id}`);
for (const [k, v] of [
["additional-fields[segment]", additional_fields_segment_],
["fields[flow]", fields_flow_],
["fields[segment]", fields_segment_],
["fields[tag]", fields_tag_],
["include", include],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
revision: revision,
"Accept": "application/vnd.api+json",
Authorization: "Klaviyo-API-Key " + auth.apiKey,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 428 days ago