Edits history of script submission #22251 for ' Get FaPiao Object ID (Matteroom) (matteroom)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    // 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