Edits history of script submission #14054 for ' Create a select option (attio)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Attio = {
      token: string;
    };
    /**
     * Create a select option
     * Adds a select option to a select attribute on an object or a list.
    
    Required scopes: `object_configuration:read-write`.
     */
    export async function main(
      auth: Attio,
      target: "objects" | "lists",
      identifier: string,
      attribute: string,
      body: { data: { title: string } },
    ) {
      const url = new URL(
        `https://api.attio.com/v2/${target}/${identifier}/attributes/${attribute}/options`,
      );
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        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