Edits history of script submission #16443 for ' Bulk batch update conversations (kustomer)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Kustomer = {
      apiKey: string;
    };
    /**
     * Bulk batch update conversations
     * Updates a bulk batch of conversations.
    
    Use the `ids` query param to update multiple conversations in bulk with the same data.
    
    Any one of the following roles is required for this endpoint:
    
    |Legacy Role|Equivalent Permission Set Role|
    |-----|--------|
    |org.user.conversation.write|org.permission.conversation.update|
     */
    export async function main(
      auth: Kustomer,
      ids: string | undefined,
      body:
        | {
            id: string;
            externalId?: string;
            name?: string;
            direction?: "in" | "out";
            priority?: number;
            satisfaction?: number;
            status?: "open" | "snoozed" | "done";
            replyChannel?: string;
            subStatus?: string;
            snooze?: {
              time?: string;
              status: "scheduled" | "canceled" | "elapsed";
            };
            tags?: string[];
            suggestedTags?: { tag: string; confidence: number }[];
            sentiment?: { polarity: 0 | 1 | -1; confidence: number };
            assignedUsers?: string[];
            assignedTeams?: string[];
            custom?: {};
            deleted?: false | true;
            ended?: false | true;
            endedAt?: string;
            endedReason?: string;
            endedBy?: string;
            endedByType?: "user" | "customer";
            locked?: false | true;
            rev?: number;
            defaultLang?: string;
            queue?: {} | {};
          }
        | { id: string; customer?: string }[],
    ) {
      const url = new URL(`https://api.kustomerapp.com/v1/conversations/bulk`);
      for (const [k, v] of [["ids", ids]]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "PUT",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.apiKey,
        },
        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