APIs & Integrations

nickdeckerdevs
Contributor | Diamond Partner
Contributor | Diamond Partner

HubDB update/replace table CSV upload help needed [php]

Can someone help me translate this into how a php curl would be? I’m unable to figure it out and just get 401 errors. I believe I’m doing it all wrong.

curl -v \
-F "file=@2017-05-01-FL.csv;type=text/csv" \
-F "config={
    \"file\":\"$curl_file\",
    \"resetTable\":true,
    \"skipRows\":1,
    \"format\":\"csv\",
    \"columnMappings\":[
        {\"source\":1,\"target\":1},
        {\"source\":2,\"target\":2},
        {\"source\":3,\"target\":3},
        {\"source\":4,\"target\":4},
        {\"source\":5,\"target\":5},
        {\"source\":6,\"target\":6},
        {\"source\":7,\"target\":7},
        {\"source\":8,\"target\":8},
        {\"source\":9,\"target\":9},
        {\"source\":10,\"target\":10},
        {\"source\":11,\"target\":11},
        {\"source\":12,\"target\":12},
        {\"source\":13,\"target\":13}
    ]
};type=application/json" \
https://api.hubapi.com/hubdb/api/v1/tables/658449/import?hapikey=xxxxx-xx-x-x-x

Here is a a portion of the code I have below. The bottom function works to update the name of the table. That uses oauth2 just fine – I just have a problem forming this multipart post. I just can’t wrap my head around it:

PHP code - hubdb update api

0 Upvotes
3 Replies 3
nickdeckerdevs
Contributor | Diamond Partner
Contributor | Diamond Partner

HubDB update/replace table CSV upload help needed [php]

If I change the header to:
curl_setopt($curl, CURLOPT_HTTPHEADER, [“Authorization: Bearer $accessToken”, “Content-type:multipart/form-data”]);
I get a 500 response
{“status”:“error”,“message”:“internal error”,“correlationId”:“cbd9226e-6c49-44f0-b70a-0ab0c9eda4cf”,“requestId”:“b8fe469f49431e95d690ec04efdf9c9d”}

I get this 500 response or a 415 response. I can’t seem to figure out anything else

0 Upvotes
Dadams
HubSpot Employee
HubSpot Employee

HubDB update/replace table CSV upload help needed [php]

Hi @nickdeckerdevs

We just updated the documentation with a PHP example:

Import a CSV file

POST /hubdb/api/v1/tables/:tableId/import - import a CSV file into a HubDB table

The example uses a hapikey to keep the it simple, but you should be able to use an access token using the code you have in your last post before line 21 in the example:

@curl_setopt($ch, CURLOPT_HTTPHEADER, ["Authorization: Bearer $accessToken", "Content-type:multipart/form-data"]);
0 Upvotes
nickdeckerdevs
Contributor | Diamond Partner
Contributor | Diamond Partner

HubDB update/replace table CSV upload help needed [php]

Thanks David, you are amazing!

Figured I would share my end result; https://gist.github.com/NickDeckerDevs/95711b65488a4ec0d9f309e2abbf70f9

I’m using OAUTH so that the client can use this and not have to worry about api keys. That was a whole other fun thing.

0 Upvotes