//native
type Persona = {
apiKey: string;
};
/**
* Create a Webhook
* Creates a new webhook with response defaults.
*/
export async function main(
auth: Persona,
body: {
data: {
attributes: {
url: string;
"enabled-events":
| "*"
| "account.created"
| "account.redacted"
| "account.archived"
| "account.restored"
| "account.consolidated"
| "account.tag-added"
| "account.tag-removed"
| "case.created"
| "case.assigned"
| "case.resolved"
| "case.reopened"
| "case.updated"
| "document.created"
| "document.submitted"
| "document.processed"
| "document.errored"
| "inquiry.created"
| "inquiry.expired"
| "inquiry.completed"
| "inquiry.failed"
| "inquiry.marked-for-review"
| "inquiry.approved"
| "inquiry.declined"
| "inquiry.transitioned"
| "inquiry-session.started"
| "inquiry-session.expired"
| "inquiry-session.canceled"
| "report/address-lookup.ready"
| "report/address-lookup.errored"
| "report/adverse-media.matched"
| "report/adverse-media.ready"
| "report/adverse-media.errored"
| "report/business-adverse-media.matched"
| "report/business-adverse-media.ready"
| "report/business-adverse-media.errored"
| "report/business-watchlist.ready"
| "report/business-watchlist.matched"
| "report/business-watchlist.errored"
| "report/email-address.ready"
| "report/email-address.errored"
| "report/phone-number.ready"
| "report/phone-number.errored"
| "report/profile.ready"
| "report/profile.errored"
| "report/politically-exposed-person.matched"
| "report/politically-exposed-person.ready"
| "report/politically-exposed-person.errored"
| "report/watchlist.matched"
| "report/watchlist.ready"
| "report/watchlist.errored"
| "selfie.created"
| "selfie.submitted"
| "selfie.processed"
| "selfie.errored"
| "transaction.created"
| "transaction.labeled"
| "transaction.redacted"
| "transaction.status-updated"
| "verification.created"
| "verification.submitted"
| "verification.passed"
| "verification.failed"
| "verification.requires-retry"
| "verification.canceled"[];
"api-version"?:
| "2023-01-05"
| "2022-09-01"
| "2021-08-18"
| "2021-07-05"
| "2021-02-21"
| "2020-05-18";
"api-key-inflection"?: "camel" | "kebab" | "snake";
"api-attributes-blocklist"?: string[];
"file-access-token-expires-in"?: number;
"payload-filter"?: { data?: {} };
"custom-http-headers"?: {
Authorization?: string;
"Calling-Application"?: string;
"CF-Access-Client-Id"?: string;
"CF-Access-Client-Secret"?: string;
"X-API-Key"?: string;
};
};
};
},
include?: string,
fields?: string,
Key_Inflection?: string,
Idempotency_Key?: string,
Persona_Version?: string,
) {
const url = new URL(`https://api.withpersona.com/api/v1/webhooks`);
for (const [k, v] of [
["include", include],
["fields", fields],
]) {
if (v !== undefined && v !== "" && k !== undefined) {
url.searchParams.append(k, v);
}
}
const headers: Record<string, string> = {
Authorization: `Bearer ${auth.apiKey}`,
"Content-Type": "application/json",
};
if (Key_Inflection) {
headers["Key-Inflection"] = Key_Inflection;
}
if (Idempotency_Key) {
headers["Idempotency-Key"] = Idempotency_Key;
}
if (Persona_Version) {
headers["Persona-Version"] = Persona_Version;
}
const response = await fetch(url, {
method: "POST",
headers,
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 428 days ago