Help

Re: Posting JSON string into text feild or .txt file into Attachments feild

Solved
Jump to Solution
1366 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Tom_Howarth
5 - Automation Enthusiast
5 - Automation Enthusiast

Hello!

Currently for a school project (Software Development and Design) I am making a game in unity complete with an online highscores leaderboard through Airtable. The leaderboard side of the project is now done but I wanted to add a replay system to the game.

Much like demo files from the old doom games my replay solution is a JSON array that contains the positions and rotations of the key game objects over the lifetime of the game. The file that is generated is only about 1mb in size and such shouldnt take very long to upload if sent with the rest of my run information (such as the players username and their time)

The issue I have run into is that im getting an INVALID_REQUEST_BODY error every time i try to put the entire JSON string into a Long Text feild on airtable. I beleive this may be due to the fact that it is a JSON string inside the rest of the JSON request that is sent to irtable. Is there a way to isolate the string so that airtable doesnt try and parse this data?

Alternatively is there a way to upload the .txt file directly into an Attachments feild. I did some research and it looks like the API will only take a url for a file that is already hosted somewhere on the internet so I didnt think this method was an option.

Any help would be greatly appreciated

  • Tom Howarth
1 Solution

Accepted Solutions
ScottWorld
18 - Pluto
18 - Pluto

If you’re uploading the text of a JSON request via the API, the text of that JSON request likely has lots of quotation marks in it.

You will need to escape all the quotation marks by putting a backslash before each quote, in order to prevent the API from thinking that you are literally trying to quote parameters or values within the body of your API call itself.

Alternatively, your idea of uploading the entire .txt file into an attachment field is a good idea, too. You could just temporarily upload the .txt file into the cloud to Google Drive or some other public location that gives you a URL, and then send that URL onto Airtable.

Not sure what programming language you’re using to trigger the Airtable API, but if you’re in need of a no-code/low-code way of doing any of this, I typically do all of this through Integromat. Integromat could even substitute all of your quotation marks with a backslash before them.

See Solution in Thread

7 Replies 7
ScottWorld
18 - Pluto
18 - Pluto

If you’re uploading the text of a JSON request via the API, the text of that JSON request likely has lots of quotation marks in it.

You will need to escape all the quotation marks by putting a backslash before each quote, in order to prevent the API from thinking that you are literally trying to quote parameters or values within the body of your API call itself.

Alternatively, your idea of uploading the entire .txt file into an attachment field is a good idea, too. You could just temporarily upload the .txt file into the cloud to Google Drive or some other public location that gives you a URL, and then send that URL onto Airtable.

Not sure what programming language you’re using to trigger the Airtable API, but if you’re in need of a no-code/low-code way of doing any of this, I typically do all of this through Integromat. Integromat could even substitute all of your quotation marks with a backslash before them.

It is possible that 1mb is still too big for a long text field. I don’t remember the exact maximum length off the top of my head, but I recommend you try sending a string that is less than 100K characters (which is significantly less than 1mb) and see if that goes through.

As for uploading a text file to an attachment field, you are correct that you need to have the file hosted at a publicly available url in order to create an attachment in Airtable with the API.

Good call on this! I wonder if Airtable has posted information somewhere on the size limit for a long text field? I don’t see it on their support article for long text fields. I will ask them about this.

The Long Text Field has a max size of 100K

Thank you, @openside, for this valuable information! :grinning_face_with_big_eyes:

Tom_Howarth
5 - Automation Enthusiast
5 - Automation Enthusiast

Yes I initially tried the solution of writing the code to place a \ before every " but still received the INVALID_REQUEST_BODY error. It is possible that there is still something wrong with the quotation marks but if the size limit is only 100kb then my 1000-2000kb files will never fit.

I’ll look into using the google drive API to upload and generate links to my Replay.txt files but it would be very convenient if the airtable API could handle this functionality on its own

Thanks for confirming. That’s what I thought but didn’t remember where it was documented.

It won’t fit in a single long text field. It might be easier to split it across multiple long text fields (either 20+ fields in the same table, or in a varying number of linked records) than to involve another api. Of course since this is for a course, you might want use the file method anyway for the learning experience.