Edits history of script submission #16657 for ' Get custom attribute metadata (kustomer)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Kustomer = {
      apiKey: string;
    };
    /**
     * Get custom attribute metadata
     * Retrieves the [metadata properties](https://developer.kustomer.com/kustomer-apps-platform/docs/klasses#metadataproperties) for the custom attributes of a specific resource (for example, Company, Conversation, Customer, Message, and KObject (custom Object)).
    
    Any one of the following roles is required for this endpoint:
    
    |Legacy Role|Equivalent Permission Set Role|
    |-----|--------|
    |org.user.metadata.read|org.permission.metadata.read|
    |org.admin.metadata.read||
    
     */
    export async function main(auth: Kustomer, resource: string) {
      const url = new URL(`https://api.kustomerapp.com/v1/metadata/${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