HubDB API along with the Blog Posts API to batch create/publish 152 blog entries



Hi all. Im looking for some advice on using the HubDB API along with the Blog Posts API to create/publish a batch of 152 blog posts. I have a HubDB set up with all of the data. The same HubDB also is being used by a custom module to render an embargoed preview of the blog posts. Each row in the HubDB contains all of the content for a blog post. There are 152 rows of data in the DB, one for each post. I am able to publish a single post and receive a 201 status, but then receive a TypeError that breaks the function from completing more than one blog entry/row. I have included the error from Terminal at the end. Unfortunately I do not understand how to solve the error. I have been trying to debug and look up errors, but seem to be stuck in a negative feedback loop. Any advice appreciated. I am open to new approaches as well.

def get_single_row(table_id):
  """Get table by row
  GET /hubdb/api/v2/tables/:tableId/rows
  xurl = "/hubdb/api/v2/tables/" + str(table_id) + "/rows?portalId=" + str(PORTAL_ID)
  url = HS_API_URL + xurl
  response = urlopen(url).read()
  table_data = json.loads(response)
  # print(table_data)
  for key, value in table_data.items():
      blog_author_id = value[i]["values"]["2"]
      campaign = value[i]["values"]["3"]
      campaign_name = value[i]["values"]["4"]
      content_group_id = value[i]["values"]["5"]
      featured_image = value[i]["values"]["6"]
      post_body = value[i]["values"]["10"]
      slug = value[i]["values"]["14"]
      meta_description = value[i]["values"]["18"]
      year = value[i]["values"]["19"]
      quarter = value[i]["values"]["20"]
      state_name = value[i]["values"]["21"]
      market_name = value[i]["values"]["22"]

      POST = {
        "blog_author_id": blog_author_id,
        "campaign": campaign,
        "campaign_name": campaign_name,
        "content_group_id": content_group_id,
        "featured_image": featured_image,
        "topic_ids": [year, quarter, market_name, state_name],
        "meta_description": meta_description,
        "name": meta_description,
        "post_body": post_body,
        "publish_date": 1543520639,
        "publish_immediately": False,
        "slug": slug,
        "use_featured_image": True
      # print(POST)
      xurl = "/content/api/v2/blog-posts"
      url = HS_API_URL + xurl + APIKEY
      headers = { "content-type" : "application/json" }
      response =, headers=headers, data=json.dumps(POST))
      # print(response.status_code, response.content, response)



  Traceback (most recent call last):
  File "", line 71, in <module>
  File "", line 34, in get_single_row
    blog_author_id = value[i]["values"]["2"]
 TypeError: 'int' object is not subscriptable

My HubDB has 20 columns of data and 152 rows. But when I try to return the JSON object with key, value pairs I only receive 12. Any thoughts on how to access the full HubDB? I am loading my JSON then printing the key, value of items.

for key, value in table_data.items():


        '18':'1 Dec 2018 | Positive Job Market Expected in Final Quarter of 2018 for Alabama',
        '4':'MEOS NA',
        '10':"<embed src=';url=,%20WI%20MSA.pdf' width='500' height='675'>",


I posted some function definitions in Slack. @Matt_Coley replied with assistance, guiding me through several issues with my program. I have posted the updated (and working) code to github as a gist here.

I was incorrectly looping through the HubDB rows, causing a TypeError to occur. Incorrect code for example:

    for key, value in table_data.items():

The corrected code to loop through a row in the DB and use the each column in the row as a content item in the blog post. Working example:

    for row in table_data['objects']: