Edits history of script submission #17980 for ' Get details of an activity (pipedrive)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Pipedrive = {
      apiToken: string;
    };
    /**
     * Get details of an activity
     * Returns the details of a specific activity.
     */
    export async function main(
      auth: Pipedrive,
      id: string,
      include_fields: "attendees" | undefined,
    ) {
      const url = new URL(`https://api.pipedrive.com/api/v2/activities/${id}`);
      for (const [k, v] of [["include_fields", include_fields]]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          "x-api-token": auth.apiToken,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago