Edits history of script submission #16494 for ' Create customer (kustomer)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Kustomer = {
      apiKey: string;
    };
    /**
     * Create customer
     * Creates a new customer record.
     */
    export async function main(
      auth: Kustomer,
      body: {
        name?: string;
        company?: string;
        externalId?: string;
        username?: string;
        signedUpAt?: string;
        lastActivityAt?: string;
        lastCustomerActivityAt?: string;
        lastSeenAt?: string;
        avatarUrl?: string;
        externalIds?: { externalId: string; verified?: false | true }[];
        sharedExternalIds?: { externalId: string; verified?: false | true }[];
        emails?: {
          type?: "home" | "work" | "other";
          email: string;
          verified?: false | true;
        }[];
        sharedEmails?: {
          type?: "home" | "work" | "other";
          email: string;
          verified?: false | true;
        }[];
        phones?: {
          type?: "home" | "work" | "other" | "mobile" | "fax";
          phone: string;
          verified?: false | true;
        }[];
        sharedPhones?: {
          type?: "home" | "work" | "other" | "mobile" | "fax";
          phone: string;
          verified?: false | true;
        }[];
        whatsapps?: { type?: "mobile"; phone: string; verified?: false | true }[];
        facebookIds?: { pageId: string; userId: string; name?: string }[];
        instagramIds?: {
          pageId: string;
          threadId: string;
          username: string;
          instagramId?: string;
        }[];
        socials?: {
          type: "twitter" | "facebook" | "instagram" | "linkedin" | "pinterest";
          userid?: string;
          username: string;
          url?: string;
          verified?: false | true;
        }[];
        sharedSocials?: {
          type: "twitter" | "facebook" | "instagram" | "linkedin" | "pinterest";
          userid?: string;
          username: string;
          url?: string;
          verified?: false | true;
        }[];
        urls?: { type?: "other" | "website" | "blog"; url: string }[];
        locations?: {
          type?: "home" | "work" | "other";
          name?: string;
          address?: string;
          address2?: string;
          address3?: string;
          latitude?: number;
          longitude?: number;
          countryCode?: string;
          countryName?: string;
          regionCode?: string;
          regionName?: string;
          cityName?: string;
          zipCode?: string;
          areaCode?: string;
        }[];
        locale?: string;
        timeZone?: string;
        tags?: string[];
        sentiment?: { polarity: 0 | 1 | -1; confidence: number };
        custom?: {};
        birthdayAt?: string;
        gender?: "m" | "f";
        createdAt?: string;
        importedAt?: string;
        rev?: number;
        defaultLang?: string;
      },
    ) {
      const url = new URL(`https://api.kustomerapp.com/v1/customers`);
    
      const response = await fetch(url, {
        method: "POST",
        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