Edits history of script submission #16635 for ' Get an Email Hook by ID (kustomer)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Kustomer = {
      apiKey: string;
    };
    /**
     * Get an Email Hook by ID
     * Fetches an email hook based on the ID.
    
    An email hook allows you to pass data into Kustomer by sending HTML email. Creating an email hook will return an email address.
    
    Any email received at that address will be parsed to extract json data. For added security, the email data requires inclusion of
    a key.
    
    The key should be included in the script tag within the html body of the email message along with the script type, i.e. ``````
    
    This endpoint will return a maximum of 10 pages with 99 entries.
     */
    export async function main(auth: Kustomer, id: string) {
      const url = new URL(`https://api.kustomerapp.com/v1/hooks/email/${id}`);
    
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Bearer " + auth.apiKey,
        },
        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