Edits history of script submission #18006 for ' Update a person (pipedrive)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Pipedrive = {
      apiToken: string;
    };
    /**
     * Update a person
     * Updates the properties of a person.
     */
    export async function main(
      auth: Pipedrive,
      id: string,
      body: {
        name?: string;
        owner_id?: number;
        org_id?: number;
        add_time?: string;
        update_time?: string;
        emails?: { value?: string; primary?: false | true; label?: false | true }[];
        phones?: { value?: string; primary?: false | true; label?: false | true }[];
        visible_to?: number;
        label_ids?: number[];
      },
    ) {
      const url = new URL(`https://api.pipedrive.com/api/v2/persons/${id}`);
    
      const response = await fetch(url, {
        method: "PATCH",
        headers: {
          "Content-Type": "application/json",
          "x-api-token": auth.apiToken,
        },
        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