SOLVED - HubDB API - CSV Import fails when updating with primaryKeyColumn

hubdb

#1

I have a script that's importing a csv into a HubDB table via the import csv api. If the table is empty, the data is imported without issue. However, if I run the script again, the import fails with:
{"status":"error","message":"internal error","correlationId":"f82f9f09-9418-49c8-8077-537e46658c1e","requestId":"0aa07a8 (truncated...)

If I remove the primaryKeyColumn property from my json config, then it will import over and over without issue. Obviously that's not what I want since it adds duplicate records to the table. Am I missing something when it comes to importing and checking for duplicates?

below is my script.

<?php

require 'vendor/autoload.php';

use GuzzleHttp\Client;

$client = new Client();


$res = $client->request('GET','https://platform.podium.com/api/v2/locations/20093/reviews?page%5Bsize%5D=999999', [
            'headers' => [
            'Authorization' => '[api key]',
            'Accept' => 'application/json',
            'Content-type' => 'application/json'
            ]
]);

$response_body = $res->getBody();
$output = json_decode($response_body);


$filename = "reviews".time().".csv";

$fp = fopen($filename, 'w');
$headers = array();
foreach($output->reviews[0] as $key=>$review){
    $headers[] = $key;
}
fputcsv($fp, $headers);
    
foreach($output->reviews as $review){
    fputcsv($fp,get_object_vars($review));
}

fclose($fp);


$json_config = 
            '{
            "resetTable":false,
            "skipRows":1,
            "format":"csv",
            "primaryKeyColumn":"review_id",
            "columnMappings":[
                {
                  "source": 1,
                  "target": 6
                },
                {
                  "source": 10,
                  "target": 1
                },
                {
                  "source": 7,
                  "target": 2
                },
                {
                  "source": 3,
                  "target": 3
                },
                {
                  "source": 6,
                  "target": 4
                },
                {
                  "source": 5,
                  "target": 5
                },
                {
                  "source": 10,
                  "target": 1
                }
              ]
            };
            type=application/json
            ';

  
$hub_res = $client->request('POST','https://api.hubapi.com/hubdb/api/v1/tables/[table id]/import?hapikey=[api key]',[
  
   'multipart' => [
     [
       'name' => 'config',
       'contents' => $json_config
         
     ],
     [
       'name' => 'file',
       'contents' => fopen($filename, 'r')
     ]
     
     
   ]
  ]);

$response_body = $hub_res->getBody();
$response_body = json_decode($response_body, true);

echo "<pre>";
var_dump($response_body);
echo "</pre>";


?>

#2

Turned out this was caused by a bug on the backend. HubSpot engineer fixed the bug and seems all is well now.