Edits history of script submission #14097 for ' Update a record (append multiselect values) (attio)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Attio = {
      token: string;
    };
    /**
     * Update a record (append multiselect values)
     * Use this endpoint to update people, companies, and other records by `record_id`. If the update payload includes multiselect attributes, the values supplied will be created and prepended to the list of values that already exist (if any). Use the `PUT` endpoint to overwrite or remove multiselect attribute values.
    
    Required scopes: `record_permission:read-write`, `object_configuration:read`.
     */
    export async function main(
      auth: Attio,
      object: string,
      record_id: string,
      body: { data: { values: {} } },
    ) {
      const url = new URL(
        `https://api.attio.com/v2/objects/${object}/records/${record_id}`,
      );
    
      const response = await fetch(url, {
        method: "PATCH",
        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