Edits history of script submission #21196 for ' Create a customer (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Create a customer
     * A new customer can a be created separately as well as at the time of creation of a new subscription.
     */
    export async function main(
      auth: Zoho,
      X_com_zoho_subscriptions_organizationid: string,
      body: {
        display_name: string;
        salutation?: string;
        first_name?: string;
        last_name?: string;
        email: string;
        tags?: { tag_id?: number; tag_option_id?: number }[];
        company_name?: string;
        phone?: string;
        mobile?: string;
        department?: string;
        designation?: string;
        website?: string;
        billing_address?: {
          attention?: string;
          street?: string;
          city?: string;
          state?: string;
          zip?: string;
          country?: string;
          state_code?: string;
          fax?: string;
        };
        shipping_address?: {
          attention?: string;
          street?: string;
          city?: string;
          state?: string;
          zip?: string;
          country?: string;
          state_code?: string;
          fax?: string;
        };
        payment_terms?: number;
        payment_terms_label?: string;
        currency_code?: string;
        ach_supported?: false | true;
        twitter?: string;
        facebook?: string;
        skype?: string;
        notes?: string;
        is_portal_enabled?: false | true;
        gst_no?: string;
        gst_treatment?: string;
        place_of_contact?: string;
        vat_treatment?: string;
        tax_reg_no?: string;
        tds_tax_id?: string;
        tax_treatment?: string;
        tax_regime?: string;
        is_tds_registered?: false | true;
        vat_reg_no?: string;
        is_taxable?: string;
        tax_id?: string;
        tax_authority_id: {};
        tax_authority_name: string;
        tax_exemption_id?: string;
        tax_exemption_code?: string;
        default_templates?: {
          invoice_template_id?: string;
          creditnote_template_id?: string;
        };
        custom_fields?: { label?: string; value?: string }[];
      },
    ) {
      const url = new URL(`https://www.zohoapis.com/billing/v1/customers`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "X-com-zoho-subscriptions-organizationid":
            X_com_zoho_subscriptions_organizationid,
          "Content-Type": "application/json",
          Authorization: "Zoho-oauthtoken " + auth.token,
        },
        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