Updates product variation data.
1
//native
2
type Pipedrive = {
3
apiToken: string;
4
};
5
/**
6
* Update a product variation
7
* Updates product variation data.
8
*/
9
export async function main(
10
auth: Pipedrive,
11
id: string,
12
product_variation_id: string,
13
body: { name?: string; prices?: {}[] },
14
) {
15
const url = new URL(
16
`https://api.pipedrive.com/api/v2/products/${id}/variations/${product_variation_id}`,
17
);
18
19
const response = await fetch(url, {
20
method: "PATCH",
21
headers: {
22
"Content-Type": "application/json",
23
"x-api-token": auth.apiToken,
24
},
25
body: JSON.stringify(body),
26
});
27
if (!response.ok) {
28
const text = await response.text();
29
throw new Error(`${response.status} ${text}`);
30
}
31
return await response.json();
32
33