Edits history of script submission #22097 for ' Update location (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Update location
     * Update location
     */
    export async function main(
      auth: Zoho,
      location_id: string,
      organization_id: string | undefined,
      body: {
        type?: string;
        email?: string;
        phone?: string;
        address?: {
          city?: string;
          state?: string;
          country?: string;
          attention?: string;
          state_code?: string;
          street_address1?: string;
          street_address2?: string;
        };
        location_name: string;
        tax_settings_id: string;
        parent_location_id?: string;
        associated_series_ids?: string[];
        auto_number_generation_id?: string;
        is_all_users_selected?: false | true;
        user_ids?: string;
      },
    ) {
      const url = new URL(
        `https://www.zohoapis.com/inventory/v1/locations/${location_id}`,
      );
      for (const [k, v] of [["organization_id", organization_id]]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "PUT",
        headers: {
          "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