// native
type Matteroom = {
base_url: string;
username: string;
password: string;
};
/**
* Search Fapiao
* Retrieves fapiao information from Matteroom
*/
export async function main(
auth: Matteroom,
start: number = 0,
size: number = 100,
status: number = 6,
) {
const url = new URL(`${auth.base_url}/api/v3/search/`);
// Basic Auth: username:password -> Base64
const token = btoa(`${auth.username}:${auth.password}`);
const headers: Record<string, string> = {
Authorization: `Basic ${token}`,
"Content-Type": "application/json",
};
const body = {
object_type: "fapiao",
start,
size,
order_by: "-created_on",
q: `status:(${status})`,
result_type: "2",
fl: "obj_id",
};
const response = await fetch(url.toString(), {
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 dev626 154 days ago