APIs & Integrations

PaulAlmond91
参加者

Updating Deal using API returns 400 error (Bad Request)

解決

Hi,

 

I'm trying to make a simple PUT Request to update a Deal property using php. I'm making the following call:

$apikey = $config->hapikey;
    $url = 'https://api.hubapi.com/deals/v1/deal/864835248?hapikey=' . $apikey;
    $data = ["properties" => [
            [
                "property" => "company_name_hidden", 
                "value" => "test"
            ]
        ]
    ];
    $options = array(
		'http' => array(
		'method'  => 'PUT',
		'content' => json_encode($data),
		'header'=>  "Content-Type: application/json\r\n" .
					"Accept: application/json\r\n"
		)
	);
	$context  = stream_context_create($options);
	$result = file_get_contents($url, false, $context);
	$hubcomp = json_decode($result, true);
    
    return $hubcomp;
    
}

I am receiving a 400 bad request but I've double checked the formatting and cannot identify the cause.


Can anyone point out where this is causing the error?

 

Thanks

0 いいね!
1件の承認済みベストアンサー
himanshurauthan
解決策
ソートリーダー | Elite Partner
ソートリーダー | Elite Partner

Updating Deal using API returns 400 error (Bad Request)

解決

Hello @PaulAlmond91 

 

Can you please try as per this method?

 

$properties[] = array( "name" => "company_name_hidden", "value" => "test" );

$dealDetails = array( "properties" => $properties );

 

I think there is a issue in the array $data that you have formed ( used wrong keys )

 

Thanks

Digital Marketing & Inbound Expert In Growth Hacking Technology

元の投稿で解決策を見る

4件の返信
himanshurauthan
解決策
ソートリーダー | Elite Partner
ソートリーダー | Elite Partner

Updating Deal using API returns 400 error (Bad Request)

解決

Hello @PaulAlmond91 

 

Can you please try as per this method?

 

$properties[] = array( "name" => "company_name_hidden", "value" => "test" );

$dealDetails = array( "properties" => $properties );

 

I think there is a issue in the array $data that you have formed ( used wrong keys )

 

Thanks

Digital Marketing & Inbound Expert In Growth Hacking Technology
Matija2209
参加者

Updating Deal using API returns 400 error (Bad Request)

解決

Here is what I have now but it results in error 405 (Method not allowed). Do you have any ideas?

import requests
import json

url = "https://api.hubapi.com/deals/v1/deal/1291584395?hapikey=XXXX"
headers = {}
headers['Content-Type'] = 'application/json'

data=json.dumps({
  "properties": [
    {
      "value": "TEST",
      "name": "dealname"
    },
    {
      "value": "123",
      "name": "amount"
    }
  ]
})

r = requests.post(data=data, url=url, headers=headers)
0 いいね!
Matija2209
参加者

Updating Deal using API returns 400 error (Bad Request)

解決

Do you have this for Python?

0 いいね!
PaulAlmond91
参加者

Updating Deal using API returns 400 error (Bad Request)

解決

Hi @himanshurauthan 

 

Thanks for replying.

I didn't need to reformat as I realised once you posted your example what I had done wrong.

I changed "property" to "name" and this now worked correctly.

 

Monday morning brain to blame!!

 

Thanks Again