How to use the API to create a table in a WorkDoc?

Hello. If I go to Document blocks it mentions you can insert a table by specifying column_count and row_count attributes. I have used this to successfully create a table. However, it does not tell you how to add data (or blocks) to that table. I tried adding a cells attribute as suggested by reading a table block but this didn’t work. Can you help please?

Hello there @danielball,

You can create a table with a mutation like this one:

mutation{ create_doc_block(doc_id: 926730, type: table, content: "{\"column_count\":2,\"row_count\":2 }"){ content id } }

Now the response value will contain an array with all the cell IDs

You can then use a mutation like this one to add data to a cell:

mutation{ create_doc_block(parent_block_id: "71ca3f1f-e6c0-42g8-8b6d-e5e0bbe74fb5", doc_id: 926730,type: normal_text, content: "{\"alignment\":\"left\",\"direction\":\"ltr\",\"deltaFormat\":[{\"insert\":\"New data in the cell\"}]}"){ id } }

I hope that helps!

Cheers,
Matias

1 Like

Hello @Matias.Monday,

Thank you for your help with this. Your method works but I have come across a problem. If I try to create a table with more than 5 rows or 5 columns I get the following error messages:

There was an error in response from monday.com graphql API:  [{"message":"bad request","locations":[{"line":1,"column":63}],"path":["create_doc_block"],"extensions":{"code":"DocMutationException","status_code":400,"error_data":[{"error_type":"Invalid property value","error_msg":"column_count column count must be less than 5"}]}}]
There was an error in response from monday.com graphql API:  [{"message":"bad request","locations":[{"line":1,"column":63}],"path":["create_doc_block"],"extensions":{"code":"DocMutationException","status_code":400,"error_data":[{"error_type":"Invalid property value","error_msg":"column_count column count must be less than 5"},{"error_type":"Invalid property value","error_msg":"row_count row count must be less than 5"}]}}]

Is there a workaround to the restrictions of 5 rows and 5 column limits? You can create bigger tables manually in WorkDocs but I want to create them programmatically. Can you use update_doc_block to increate the number of rows and columns?

Hello there @danielball,

As of today that is the limit and there is no workaround for it.

Let me know if you have any other questions!

Cheers,
Matias

Hi @Matias.Monday. Not having the ability to create tables bigger than 5x5 is a road block to delivering an app idea I’m working on. Is it on the road-map to lift this restriction? Can I ask why this restriction is in place? Is there anything I can do to make lifting this restriction a priority?

Whilst I’m asking for things, it would be really good to have the ability to add multi-block cell contents in a single API call as it runs quite slowly having to call the API to populate each cell.

Just a thought. Can you add a 5x5, then add more rows and columns?

Thought of that. I’m pretty sure I tried calling update-document-block with a higher column_count and row_count value. I can’t remember what the response was, but I think it was along the lines of “you can’t change those values on an existing table block”, which contradicts the API-reference if it’s true. If I get chance I will try and do a controlled experiment and post the exact response. From what I can tell, you are basically stuck with a 5x5 table if you create it using the API.