Edits history of script submission #18010 for ' Update an activity (pipedrive)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Pipedrive = {
      apiToken: string;
    };
    /**
     * Update an activity
     * Updates the properties of an activity.
     */
    export async function main(
      auth: Pipedrive,
      id: string,
      body: {
        subject?: string;
        type?: string;
        owner_id?: number;
        deal_id?: number;
        lead_id?: string;
        person_id?: number;
        org_id?: number;
        project_id?: number;
        due_date?: string;
        due_time?: string;
        duration?: string;
        busy?: false | true;
        done?: false | true;
        location?: {
          value?: string;
          country?: string;
          admin_area_level_1?: string;
          admin_area_level_2?: string;
          locality?: string;
          sublocality?: string;
          route?: string;
          street_number?: string;
          postal_code?: string;
        };
        participants?: { person_id?: number; primary?: false | true }[];
        attendees?: {
          email?: string;
          name?: string;
          status?: string;
          is_organizer?: false | true;
          person_id?: number;
          user_id?: number;
        }[];
        public_description?: string;
        priority?: number;
        note?: string;
      },
    ) {
      const url = new URL(`https://api.pipedrive.com/api/v2/activities/${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