Edits history of script submission #16473 for ' Create a Category (kustomer)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Kustomer = {
      apiKey: string;
    };
    /**
     * Create a Category
     * Creates a new category document.
     */
    export async function main(
      auth: Kustomer,
      body: {
        parent?: string;
        knowledgeBase?: string;
        langs?: {};
        externalId?: string;
        hash?: string;
        positions?: string[];
        icon?: string;
      },
    ) {
      const url = new URL(`https://api.kustomerapp.com/v1/kb/categories`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + 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 235 days ago