Edits history of script submission #14055 for ' Create a status (attio)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Attio = {
      token: string;
    };
    /**
     * Create a status
     * Add a new status to a status attribute on either an object or a list.
    
    Required scopes: `object_configuration:read-write`.
     */
    export async function main(
      auth: Attio,
      target: "lists" | "objects",
      identifier: string,
      attribute: string,
      body: {
        data: {
          title: string;
          celebration_enabled?: false | true;
          target_time_in_status?: string;
        };
      },
    ) {
      const url = new URL(
        `https://api.attio.com/v2/${target}/${identifier}/attributes/${attribute}/statuses`,
      );
    
      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