APIs & Integrations

direstardb
Membro

How to Update a HubDB table cell?

resolver

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 Avaliação positiva
1 Solução aceita
danaketh
Solução
Participante

How to Update a HubDB table cell?

resolver

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

Exibir solução no post original

2 Respostas 2
danaketh
Solução
Participante

How to Update a HubDB table cell?

resolver

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
Membro

How to Update a HubDB table cell?

resolver

Thanks for the help!

0 Avaliação positiva