APIs & Integrations

適用対象外

Getting error code 405 sent back from curl when trying to update Deal value

Hi, I'm trying to update a Deal value from my remote server to the hubspot server. When I run the script from my remote server to update the hubspot deal, curl returns the following error message back:

Error: call to URL https://api.hubapi.com/deals/v1/deal/?hapikey= failed with status 405, response , curl_error , curl_errno 0

The part of script that handles curl is below:

$url = "https://api.hubapi.com/deals/v1/deal/?hapikey=";

$content = '{"properties": [{"name": "amount","value": "70000"}]}';

$curl = @curl_init();
@curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
@curl_setopt($curl, CURLOPT_HTTPHEADER,
array("Content-type: application/json"));
@curl_setopt($curl, CURLOPT_URL, $url);
@curl_setopt($curl, CURLOPT_POST, true);

@curl_setopt($curl, CURLOPT_POSTFIELDS, $content);

$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

if ( $status != 201 ) {
die("Error: call to URL $url failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));
}

curl_close($curl);

$response = json_decode($json_response, true);

Any help would be appreciated.

Thanks

0 いいね!
3件の返信
Derek_Gervais
元HubSpot社員
元HubSpot社員

Getting error code 405 sent back from curl when trying to update Deal value

Hi @cmartin19,

That endpoint accepts PUT requests to update deals, not POST requests. Can you try making a PUT request?

0 いいね!
適用対象外

Getting error code 405 sent back from curl when trying to update Deal value

Thanks but that didn't seem to fix the problem as I'm getting the same error. I put in fake deal id and hubspot api key which the forum must have removed after I posted.

0 いいね!
danaketh
参加者

Getting error code 405 sent back from curl when trying to update Deal value

In your example, you're missing the dealId parameter in URL.

$dealId = 19320611;
$hapikey = '<THIS IS MY HUBSPOT API KEY>';

$urlPattern = "https://api.hubapi.com/deals/v1/deal/%s?hapikey=%s";
$url = sprintf($urlPattern, $dealId, $hapikey);

That could be the problem. Unless you have just removed the information for the purpose of publishing the code here.

0 いいね!