Edits history of script submission #12286 for ' Create Universal Content (klaviyo)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Klaviyo = {
      apiKey: string;
    };
    /**
     * Create Universal Content
     * Create universal content. Only text blocks, which can include text or HTML, are supported at this time.*Rate limits*:Burst: `10/s`Steady: `150/m`
    
     */
    export async function main(
      auth: Klaviyo,
      revision: string,
      body: {
        data: {
          type: "template-universal-content";
          attributes: {
            name: string;
            definition:
              | {
                  content_type: "block";
                  type: "html";
                  data: {
                    content: string;
                    display_options: {
                      show_on?: "all" | "desktop" | "mobile";
                      visible_check?: string;
                      content_repeat?: { repeat_for: string; item_alias: string };
                    };
                  };
                }
              | {
                  content_type: "block";
                  type: "text";
                  data: {
                    content: string;
                    display_options: {
                      show_on?: "all" | "desktop" | "mobile";
                      visible_check?: string;
                      content_repeat?: { repeat_for: string; item_alias: string };
                    };
                    styles: {
                      block_background_color?: string;
                      block_border_color?: string;
                      block_border_style?:
                        | "dashed"
                        | "dotted"
                        | "groove"
                        | "inset"
                        | "none"
                        | "outset"
                        | "ridge"
                        | "solid";
                      block_border_width?: number;
                      block_padding_bottom?: number;
                      block_padding_left?: number;
                      block_padding_right?: number;
                      block_padding_top?: number;
                      color?: string;
                      extra_css_class?: string;
                      font_family?: string;
                      font_size?: number;
                      font_style?: "italic" | "normal";
                      font_weight?: string;
                      inner_padding_bottom?: number;
                      inner_padding_left?: number;
                      inner_padding_right?: number;
                      inner_padding_top?: number;
                      mobile_stretch_content?: false | true;
                      background_color?: string;
                      letter_spacing?: number;
                      line_height?: number;
                      text_align?: "center" | "left" | "right";
                      text_decoration?: string;
                      text_table_layout?: "auto" | "fixed" | "inherit" | "initial";
                    };
                  };
                };
          };
        };
      },
    ) {
      const url = new URL(`https://a.klaviyo.com/api/template-universal-content`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          revision: revision,
          "Accept": "application/vnd.api+json",
          "Content-Type": "application/vnd.api+json",
          Authorization: "Klaviyo-API-Key " + auth.apiKey,
        },
        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 428 days ago