405 errors on PATCH, 401 on DELETE

Hello all,

I’m trying to update a hubdb via API v3. When using POST, all data flows as expected and the database is populated with the proper data in the proper columns.

However, I don’t want to duplicate the information every time I run the script, and it should run at least every day.

I’ve tried doing PATCH, PUT and DELETE methods on my code, each with varying errors - correlation errors, 405 errors, 401 errors. I cannot, for the life of me, figure out what’s going on here and perhaps someone came across this issue and has a fix for it?

Here’s where my code stands at the minute:

$payload = json_encode([ ‘values’ => [ ‘name’ => $currency, // Use the column name ‘moeda’ ‘valor_compra’ => (string)$entry[‘buyValue’], // Use the column name ‘valor_compra’ ‘valor_venda’ => (string)$entry[‘sellValue’], // Use the column name ‘valor_venda’ ‘data’ => (string)$entry[‘lastUpdateDate’], // Use the column name ‘lastUpdateDate’ ] ]); $ch = curl_init($updateUrl); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Authorization: Bearer '.$hubspot_api_key, ‘Content-Type: application/json’, ]); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, ‘PUT’); // Use PATCH to update the row curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); // Payload with null values curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); // Get the HTTP response code curl_close($ch); echo “PATCH Response: $response, HTTP Code: $http_code\n”;

Bare in mind that when doing the almost exact same code in POST instead of PATCH, it goes through. Same $payload, same auth key and Bearer method. Any suggestions? Thanks in advance

Hi, @FSena :waving_hand: Thanks for your question. Do you get the same error responses when you make a PATCH or DELETE request using Postman?

Hey @Anton @alyssamwilie @Josh, do you have any additional HubDB API troubleshooting suggestions?

Thank you for taking a look! — Jaycee

Yep, pretty much.

Tried it with postman, and either got a 401 “Unauthorized” (PATCH and DELETE), or a 405 method not allowed with PUT.

So, I’ve figured it out and I’m going to post it here in case anyone stumbles upon the same issue and doesn’t know what would work or not.
Here’s what I’ve come up with:

THE PROBLEM
Hubspot hubdb doesn’t allow for modifications (i.e. PUT, PATCH or DELETE) on published databases. This is key information that should be on the documentation but, alas, one has to figure it out by himself.
THE SOLUTION

Therefore, the solution is pretty obvious. We send the data we need to change to a /draft version of the database, and in the end of our PATCH cycle, we send the order to /publish the database and push it to live.
Github project for anyone looking for the file → hs-connect-api/hs-connect.php at main · sena-design-studio/hs-connect-api · GitHub
Hope it helps some other person as it took me far too long to figure this one out :wink:

Thank you so much for taking the time to post the solution! — Jaycee