//native
type Persona = {
apiKey: string;
};
/**
* Update an Inquiry
* Updates an existing Inquiry.
Note that if you use webhooks, updates to inquiries that are not in progress can result in data getting out of sync. For example, updating a completed Inquiry will not cause your Inquiry completed webhook to retrigger.
Inquiries represent a snapshot of data collected from an individual, so we generally do not recommend updating an Inquiry's data after the Inquiry has been finalized.
*/
export async function main(
auth: Persona,
inquiry_id: string,
body: {
data?: {
attributes?: {
note?: string;
fields?:
| {}
| ({
birthdate?: string;
"name-first"?: string;
"name-middle"?: string;
"name-last"?: string;
"phone-number"?: string;
"email-address"?: string;
} & {
"address-street-1"?: string;
"address-street-2"?: string;
"address-city"?: string;
"address-subdivision"?: string;
"address-postal-code"?: string;
} & { "address-country-code"?: string });
tags?: string[];
};
};
},
include?: string,
fields?: string,
Key_Inflection?: string,
Idempotency_Key?: string,
Persona_Version?: string,
) {
const url = new URL(
`https://api.withpersona.com/api/v1/inquiries/${inquiry_id}`,
);
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: "PATCH",
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