I’m trying to adapt the code by @Bill.French used here to upload a single long text field’s contents as a markdown document to Dropbox.
The automation is:
Trigger: When a new record is created
(records are created with nearly all fields filled at once, using Zapier, so the inputConfig fields are never empty)
Action: Run script…
// set the table name
let table = "Piece Information";
let inputConfig = input.config();
let fileContents = inputConfig.showNotes;
let fileName = inputConfig.fileID + "_" + inputConfig.fileName;
let fileNameExt = inputConfig.fileID + "_" + inputConfig.fileName + ".md";
// set the endpoint and app token
let dropboxEndpoint = "https://content.dropboxapi.com/2/files/upload";
let appToken = "<my app token>";
// set up the post options
let postOptions = {
method: "post",
headers: {
"Authorization" : "Bearer " + appToken,
"Dropbox-API-Arg" : "{\\"path\\": \\"2021%20TC-RHDF%20Competition/ALL%20ENTRIES/"+fileNameExt+"\\",\\"mode\\": \\"add\\",\\"autorename\\": true,\\"mute\\": false,\\"strict_conflict\\": false}",
"Content-Type" : "application/octet-stream",
"Accept" : "application/json",
},
body: fileContents
}
const postResults = await fetch(dropboxEndpoint, postOptions);
const jsonPost = await postResults.json();
// display the dropbox upload result
output.markdown("Display Dropybox Response JSON Object");
output.inspect(jsonPost);
When I remove this section, I get no errors, but I don’t see a file uploaded in dropbox:
const postResults = await fetch(dropboxEndpoint, postOptions);
const jsonPost = await postResults.json();
// display the dropbox upload result
output.markdown("Display Droplbox Response JSON Object");
output.inspect(jsonPost);
When I keep that section, I see this error:
SyntaxError: Unexpected token E in JSON at position 0 at main on line 40
Line 40 corresponds to: const jsonPost = await postResults.json();
Any sense what’s going wrong here?
I’m new to JavaScript and know almost nothing about JSON. I also have Zapier, on the off chance anyone knows an easier way to do this using Zapier (but it seems like the only dropbox options there are to upload a file with a .txt extension, and I need it to be a markdown file).
The reason for all of this is that I have a dropbox folder set up using JustCast to create a podcast RSS feed. Each audio file in that folder creates a podcast episode. Each audio file in that folder has a corresponding record in Airtable, with a “Summary” rich text field. Any markdown file placed into that folder with a matching file name to the audio file automatically becomes the Show Notes for the podcast episode.
Thanks for your help!!