APIs & Integrations

direstardb
Membre

How to Update a HubDB table cell?

Résolue

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!

0 Votes
1 Solution acceptée
danaketh
Solution
Participant

How to Update a HubDB table cell?

Résolue

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);

Voir la solution dans l'envoi d'origine

2 Réponses
danaketh
Solution
Participant

How to Update a HubDB table cell?

Résolue

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);
direstardb
Membre

How to Update a HubDB table cell?

Résolue

Thanks for the help!

0 Votes