Edits history of script submission #21237 for ' Create bulk write job (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Create bulk write job
     *
     */
    export async function main(
      auth: Zoho,
      body: {
        character_encoding?: string;
        operation?: "upsert" | "insert" | "update";
        callback?: { url?: string; method?: "post" };
        resource?: {
          status?: "COMPLETED" | "ADDED" | "FAILED" | "IN PROGRESS" | "SKIPPED";
          type?: "data";
          module?: {
            api_name: string;
            id: string;
            module_name?: string;
            module?: string;
          };
          code?: string;
          file_id?: string;
          file_names?: string[];
          ignore_empty?: false | true;
          find_by?: string;
          field_mappings?: {
            api_name?: string;
            index?: number;
            format?: string;
            find_by?: string;
            default_value?: { name?: string; module?: string; value?: {} };
            module?: string;
            parent_column_index?: number;
          }[];
          file?: {
            status?: "COMPLETED" | "ADDED" | "FAILED" | "IN PROGRESS" | "SKIPPED";
            name?: string;
            added_count?: number;
            skipped_count?: number;
            updated_count?: number;
            total_count?: number;
          };
        }[];
        ignore_empty?: false | true;
      },
    ) {
      const url = new URL(`https://zohoapis.com/crm/bulk/v8/write`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Zoho-oauthtoken " + auth.token,
        },
        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 235 days ago