Edits history of script submission #16586 for ' Get KViews by Resource (kustomer)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Kustomer = {
      apiKey: string;
    };
    /**
     * Get KViews by Resource
     * Retrieves all the KViews for a resource.
    
    Optionally, the context can be included to be more specific.
    
    If the context is included, it will be ordered according to when the KView was added or the order specified in the KView ordering endpoint.
     */
    export async function main(auth: Kustomer, resource: string) {
      const url = new URL(`https://api.kustomerapp.com/v1/kviews/${resource}`);
    
      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