0

Update vendor credit

by
Published Oct 17, 2025

Update an existing vendor credit.

Script zoho Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Zoho = {
3
  token: string;
4
};
5
/**
6
 * Update vendor credit
7
 * Update an existing vendor credit.
8
 */
9
export async function main(
10
  auth: Zoho,
11
  vendor_credit_id: string,
12
  organization_id: string | undefined,
13
  body: {
14
    vendor_id: string;
15
    vat_treatment?: string;
16
    vendor_credit_number?: string;
17
    gst_treatment?: string;
18
    tax_treatment?: string;
19
    gst_no?: string;
20
    source_of_supply?: string;
21
    destination_of_supply?: string;
22
    place_of_supply?: string;
23
    pricebook_id?: string;
24
    reference_number?: string;
25
    is_update_customer?: false | true;
26
    date?: string;
27
    exchange_rate?: number;
28
    is_inclusive_tax?: false | true;
29
    location_id?: string;
30
    line_items?: {
31
      item_id?: string;
32
      line_item_id?: string;
33
      account_id?: string;
34
      name?: string;
35
      hsn_or_sac?: string;
36
      reverse_charge_tax_id?: string;
37
      location_id?: string;
38
      description?: string;
39
      item_order?: number;
40
      quantity?: number;
41
      unit?: string;
42
      rate?: number;
43
      tax_id?: string;
44
      tds_tax_id?: string;
45
      tax_treatment_code?: string;
46
      tags?: { tag_id?: number; tag_option_id?: number }[];
47
      item_custom_fields?: {
48
        custom_field_id?: number;
49
        label?: string;
50
        value?: string;
51
        index?: number;
52
      }[];
53
      serial_numbers?: string[];
54
      project_id?: string;
55
      project_name?: string;
56
    }[];
57
    notes?: string;
58
    documents?: { document_id?: number; file_name?: string }[];
59
    custom_fields?: {
60
      custom_field_id?: number;
61
      label?: string;
62
      value?: string;
63
      index?: number;
64
    }[];
65
  },
66
) {
67
  const url = new URL(
68
    `https://www.zohoapis.com/inventory/v1/vendorcredits/${vendor_credit_id}`,
69
  );
70
  for (const [k, v] of [["organization_id", organization_id]]) {
71
    if (v !== undefined && v !== "" && k !== undefined) {
72
      url.searchParams.append(k, v);
73
    }
74
  }
75
  const response = await fetch(url, {
76
    method: "PUT",
77
    headers: {
78
      "Content-Type": "application/json",
79
      Authorization: "Zoho-oauthtoken " + auth.token,
80
    },
81
    body: JSON.stringify(body),
82
  });
83
  if (!response.ok) {
84
    const text = await response.text();
85
    throw new Error(`${response.status} ${text}`);
86
  }
87
  return await response.json();
88
}
89