Edits history of script submission #21860 for ' Publish API Add Records (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
      baseUrl: string;
    };
    /**
     * Publish API Add Records
     * This API adds one or more records to a form in your Zoho Creator application. Subject to validations, each JSON object in the input file will be added as a record. A maximum of 200 records can be created per request.
     */
    export async function main(
      auth: Zoho,
      account_owner_name: string,
      app_link_name: string,
      form_link_name: string,
      privatelink: string | undefined,
      body: {
        result?: {
          fields?: string[];
          message?: false | true;
          tasks?: false | true;
        };
        data?: {}[];
      },
    ) {
      const url = new URL(
        `${auth.baseUrl}/creator/v2.1/publish/${account_owner_name}/${app_link_name}/form/${form_link_name}`,
      );
      for (const [k, v] of [["privatelink", privatelink]]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      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