//native
type Persona = {
apiKey: string;
};
/**
* Create a Report
* Creates a new Report of any type.
*/
export async function main(
auth: Persona,
body: {
data?:
| {
type?: "report/address-lookup";
attributes: {
"account-id"?: string;
"reference-id"?: string;
"report-template-id"?: string;
} & {
query: {
addressee?: string;
"address-street-1": string;
"address-street-2"?: string;
"address-city": string;
"address-subdivision": string;
"address-postal-code": string;
"address-country-code": string;
};
};
}
| {
type?: "report/adverse-media";
attributes: {
"account-id"?: string;
"reference-id"?: string;
"report-template-id"?: string;
} & {
query: {
"name-first"?: string;
"name-middle"?: string;
"name-last"?: string;
term?: string;
birthdate?: string;
"country-code"?: string;
};
};
}
| {
type?: "report/business-adverse-media";
attributes: {
"account-id"?: string;
"reference-id"?: string;
"report-template-id"?: string;
} & { query: { term: string } };
}
| {
type?: "report/business-lookup";
attributes: {
"account-id"?: string;
"reference-id"?: string;
"report-template-id"?: string;
} & {
query: {
"business-name": string;
"phone-number"?: string;
website?: string;
ein?: string;
"address-street-1"?: string;
"address-street-2"?: string;
"address-city"?: string;
"address-subdivision"?: string;
"address-postal-code"?: string;
"address-country-code"?: string;
"associated-people"?: {
"name-full"?: string;
"name-first"?: string;
"name-last"?: string;
titles?: string[];
}[];
};
};
}
| {
type?: "report/business-watchlist";
attributes: {
"account-id"?: string;
"reference-id"?: string;
"report-template-id"?: string;
} & { query: { term: string; "address-country-code"?: string } };
}
| {
type?: "report/crypto-address-watchlist";
attributes: {
"account-id"?: string;
"reference-id"?: string;
"report-template-id"?: string;
} & { query: { "crypto-address": string } };
}
| {
type?: "report/email-address";
attributes: {
"account-id"?: string;
"reference-id"?: string;
"report-template-id"?: string;
} & { query: { "email-address": string } };
}
| {
type?: "report/phone-number";
attributes: {
"account-id"?: string;
"reference-id"?: string;
"report-template-id"?: string;
} & { query: { "phone-number": string } };
}
| {
type?: "report/politically-exposed-person";
attributes: {
"account-id"?: string;
"reference-id"?: string;
"report-template-id"?: string;
} & {
query: {
"name-first"?: string;
"name-middle"?: string;
"name-last"?: string;
term?: string;
birthdate?: string;
"country-code"?: string;
};
};
}
| {
type?: "report/profile";
attributes?: {
"account-id"?: string;
"reference-id"?: string;
"report-template-id"?: string;
} & {
query?: {
"name-first"?: string;
"name-last"?: string;
birthdate?: string;
"social-security-number"?: string;
"address-street-1"?: string;
"address-street-2"?: string;
"address-city"?: string;
"address-subdivision"?: string;
"address-postal-code"?: string;
"country-code"?: string;
"phone-number"?: string;
};
};
}
| {
type?: "report/profile-non-authoritative";
attributes: {
"account-id"?: string;
"reference-id"?: string;
"report-template-id"?: string;
} & {
query: {
"name-first"?: string;
"name-last"?: string;
"phone-number"?: string;
"email-address"?: string;
"address-city"?: string;
"address-subdivision"?: string;
};
};
}
| {
type?: "report/social-media";
attributes: {
"account-id"?: string;
"reference-id"?: string;
"report-template-id"?: string;
} & {
query: {
"name-first"?: string;
"name-last"?: string;
birthdate?: string;
"phone-number"?: string;
"email-address"?: string;
"address-city"?: string;
"address-subdivision"?: string;
"address-postal-code"?: string;
"address-country-code"?: string;
};
};
}
| {
type?: "report/synthetic";
attributes: {
"account-id"?: string;
"reference-id"?: string;
"report-template-id"?: string;
} & {
query: {
"name-first": string;
"name-last": string;
birthdate: string;
"social-security-number"?: string;
"identification-number"?: string;
"address-street-1": string;
"address-street-2"?: string;
"address-city": string;
"address-subdivision": string;
"address-postal-code": string;
"address-country-code": string;
"phone-number"?: string;
"email-address"?: string;
};
};
}
| {
type?: "report/watchlist";
attributes: {
"account-id"?: string;
"reference-id"?: string;
"report-template-id"?: string;
} & {
query: {
"name-first"?: string;
"name-middle"?: string;
"name-last"?: string;
term?: string;
birthdate?: string;
"address-country-code"?: string;
};
};
};
meta?: {
"auto-create-account"?: false | true;
"auto-create-account-type-id"?: string;
"auto-create-account-reference-id"?: string;
"processing-mode"?: string;
"request-flags"?: string[];
};
},
include?: string,
fields?: string,
Key_Inflection?: string,
Idempotency_Key?: string,
Persona_Version?: string,
) {
const url = new URL(`https://api.withpersona.com/api/v1/reports`);
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