How to Update a HubDB table cell?


#1

Hi, I was wondering if anyone had any code to share to illustrate how to use the HubSpot API to update a cell in a HubDB table. If you could please include all of the code, not just the API call, that would be great.

I’m not too fussy about the code, but I’m more familiar with PHP.

Thank you!


#2

Here’s an example which should help you start. IDs for table, row and cell are taken from the API documentation example at https://developers.hubspot.com/docs/methods/hubdb/update_cell

<?php

// Options
$apiKey = '<YOUR_API_KEY>';
$tableId = 300081;
$rowId = 4685456343;
$cellId = 4;

// Put the URL together
$requestUrl = sprintf(
    'https://api.hubapi.com/hubdb/api/v1/tables/%s/rows/%s/cells/%s?hapikey=%s',
    $tableId,
    $rowId,
    $cellId,
    $apiKey
);

// Prepare our data for the cell
$data = [
    'value' => 'some value'
];

// Proceed with the API call
$ch = curl_init($requestUrl);
$dataJson = json_encode($data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataJson);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: application/json',
]);
$response = curl_exec($ch);

if (!$response) {
    trigger_error(curl_error($ch));
}

curl_close($ch);

#3

Thanks for the help!