Dear all,
i’m trying to add differents prices currency through API using PHP.
I tried to declare the $data like this
$data = array(
'name' => $row['Nom'],
'code' => $row['Code Produit'],
'prices' => [[
'currency' => 'EUR',
'price' => '99'
]] );
But i always got the result error : Prices must be given as array of objects.
Can someone got a working example ?
I need to add EUR,GBP and USD prices directly.
Thanks
Hem
January 27, 2022, 11:21am
2
Hey @Vanzetta
Welcome to the community
Are you using create product endpoint? Here’s a snippet that works for me
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://<account_name>.pipedrive.com/v1/products?api_token=<api_token>',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{
"name": "HotWheels",
"code": "HW100",
CURLOPT_POSTFIELDS =>'{
"name": "HotWheels",
"code": "HW100",
"prices": {
"EUR": {
"currency": "EUR",
"price": 10.50
},
"INR": {
"currency": "INR",
"price": 900
}
}
}',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Note:
The request payload has to be constructed with currency string as the key name
The snippet makes use of API Token to test the payload structure. However, always prefer OAuth instead of API Token (unless it’s for testing purposes).
1 Like
Hi @Hem , thanks for your code. it’s working now !
1 Like