(beginner seeking guidance) HubDB api help with php app



Here’s the context
I am having some difficulty getting started with my first webapp that uses the hubDB api. Here’s my vision for what I want to build. It’s a page view counter. What I’m picturing is some javascript that every time a blog post loads, sends a hidden form with the title of the blog post to this php file (what code I have so far is below). The php script will then pull all the rows from a prexisting hubDB table, check to see if one with the blog post title already exists: if so, increment the counter value cell, if not, make a new row and populate it. The code I have so far seems to be successfully grabbing the hubDB table data. What I’m having trouble with is authenticating with the hubspot API to create a new row in the table. The code I have right now is very rudimentary and in an early testing stage. Once I figure out how to update/add table rows I’ll add in all the other functionalityl
Here is my code:

$table_json = file_get_contents('https://api.hubapi.com/hubdb/api/v1/tables/[tableID]/rows?
$table_json = utf8_encode($table_json);
$decoded_table_json = json_decode($table_json, true);

foreach ($decoded_table_json['objects'] as $row) {
echo $row['id'];
$values = $row;
echo " | ";
foreach ($values as $value) {
	echo $value['1'];
} echo "</br>";

$url = "https://api.hubapi.com/hubdb/api/v1/tables/[tableID]/rows/[rowID]?hapikey=[hapiKey]";
$ch = @curl_init($url);
@curl_setopt($ch, CURLOPT_URL, $url);
@curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
@curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
@curl_setopt($ch, CURLOPT_POSTFIELDS,'{ "values": {"4": "updated" }}}');
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response  = @curl_exec($ch);
echo $response;

this is what it echoes to the page:

5258874009 | eetest1title
5258642372 | eetest2title
5259257953 | eetest3title
5259258554 | eetest4title
{“status”:“error”,“message”:“This hapikey [hapiKey] does not have proper permissions! (requires all of [hubdb-access])”,“correlationId”:“36f25faf-c9c5-4369-826a-194f7eef0b5b”,“requestId”:“3317b0b9cee3f88e095eb3698290fd8d”}

If it seems like I’m a beginner or like I’m not quite sure what I’m doing, it’s because I am and I don’t. Any judgment free help would be great as I’m somewhat in over my head! This is my first time working with an API.

Thank you!