APIs & Integrations

kaoki
Contributor | Platinum Partner
Contributor | Platinum Partner

[HubDB API] how to add Foreign ID type columns to table

SOLVE

Hi, I`m using HubDB API .

https://developers.hubspot.com/docs/api/cms/hubdb

 

I tried to create table which has a Foreign ID type column, and I got following error.

 

 

 

 

HTTP 400

Foreign table id must be defined: {name='text_column', label=Text Column, type=FOREIGN_ID, id=1, deleted=false, options=[], foreignTableId0, width=null}

 

 

 

 

Here is an entire request log.

 

 

 

 

curl --request POST \
  --url 'https://api.hubapi.com/cms/v3/hubdb/tables?hapikey={{API_KEY}}' \
  --header 'content-type: application/json' \
  --data '{
  "name": "test_table",
  "label": "Test Table",
  "useForPages": true,
  "columns": [
    {
      "name": "text_column",
      "label": "Text Column",
      "id": "1",
      "type": "FOREIGN_ID"
    }
  ],
  "allowChildTables": true,
  "enableChildTablePages": false,
  "allowPublicApiAccess": false
}'

 

 

 

 

It seems that the error occurs because I don`t specify foreign table id.

I read the API documents but I didn`t found out how to specify it.

How do I specify foreign table id?

 

Thank you.

0 Upvotes
1 Accepted solution
kaoki
Solution
Contributor | Platinum Partner
Contributor | Platinum Partner

[HubDB API] how to add Foreign ID type columns to table

SOLVE

@stefen @dennisedson 

Thank you for the response.

But it didn`t work for me.

 

I found solution.

I just added "foreignTableId" property to column object, and it worked.

Here is request log

curl --request POST \
  --url 'https://api.hubapi.com/cms/v3/hubdb/tables?hapikey={{API_KEY}}' \
  --header 'content-type: application/json' \
  --data '{
  "name": "test_table",
  "label": "Test Table",
  "useForPages": true,
  "columns": [
    {
      "name": "text_column",
      "label": "Text Column",
      "id": "1",
      "type": "FOREIGN_ID",
      "foreignTableId": 5316197,
      "foreignColumnId": 1
    }
  ],
  "allowChildTables": true,
  "enableChildTablePages": false,
  "allowPublicApiAccess": false
}'

View solution in original post

3 Replies 3
kaoki
Solution
Contributor | Platinum Partner
Contributor | Platinum Partner

[HubDB API] how to add Foreign ID type columns to table

SOLVE

@stefen @dennisedson 

Thank you for the response.

But it didn`t work for me.

 

I found solution.

I just added "foreignTableId" property to column object, and it worked.

Here is request log

curl --request POST \
  --url 'https://api.hubapi.com/cms/v3/hubdb/tables?hapikey={{API_KEY}}' \
  --header 'content-type: application/json' \
  --data '{
  "name": "test_table",
  "label": "Test Table",
  "useForPages": true,
  "columns": [
    {
      "name": "text_column",
      "label": "Text Column",
      "id": "1",
      "type": "FOREIGN_ID",
      "foreignTableId": 5316197,
      "foreignColumnId": 1
    }
  ],
  "allowChildTables": true,
  "enableChildTablePages": false,
  "allowPublicApiAccess": false
}'
stefen
Key Advisor | Partner
Key Advisor | Partner

[HubDB API] how to add Foreign ID type columns to table

SOLVE

@kaoki @dennisedson the foreign id column should be an array with objects inside of it since you can have multiple IDs in that field. So, for example the log should look more like this:

 

curl --request POST \
  --url 'https://api.hubapi.com/cms/v3/hubdb/tables?hapikey={{API_KEY}}' \
  --header 'content-type: application/json' \
  --data '{
  "name": "test_table",
  "label": "Test Table",
  "useForPages": true,
  "columns": [
    {
      "name": "text_column" [
        {
          "id": "1",
          "type": "foreignid"
        },
        {
          "id": "2",
          "type": "foreignid"
        }
      ]
    }
  ],
  "allowChildTables": true,
  "enableChildTablePages": false,
  "allowPublicApiAccess": false
}'

 

 

Stefen Phelps, Community Champion, Kelp Web Developer
dennisedson
HubSpot Product Team
HubSpot Product Team

[HubDB API] how to add Foreign ID type columns to table

SOLVE

@stefen , think you could assist here?