Edits history of script submission #17527 for ' Transfer dns zone (netlify)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Netlify = {
      token: string;
    };
    /**
     * Transfer dns zone
     *
     */
    export async function main(
      auth: Netlify,
      zone_id: string,
      account_id: string | undefined,
      transfer_account_id: string | undefined,
      transfer_user_id: string | undefined,
    ) {
      const url = new URL(
        `https://api.netlify.com/api/v1/dns_zones/${zone_id}/transfer`,
      );
      for (const [k, v] of [
        ["account_id", account_id],
        ["transfer_account_id", transfer_account_id],
        ["transfer_user_id", transfer_user_id],
      ]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "PUT",
        headers: {
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago