I actually didnt find it convenient to write the body manually and wanted a way to quickly format the data from csv which is easy to type in google sheets. So i explored another script in Rstudio that i think can greatly speed up how you manually enter data into bubble.
This makes it very easy for anyone to send you data. They could simply enter it into a google sheet and you can reformat it for bulk upload, avoiding many clicks if you are on a hobby plan and that bubbles csv upload is very slow for many items.
Here is the data test file i made, the script should run with this test file if you specify the correct directory in rstudio: test.csv - Google Drive
Here is my script in R:
#clean the working environment
rm(list=ls())
#set working directory, keep files organized
setwd("C:/Users/")
#
#install packages('readr'}
#install.packages('jsonlite')
#install.packages("stringr")
#install.packages("stringi")
#libraries
library(readr)
library(jsonlite)
library(stringr)
library(stringi)
#import data in csv format
data <- read_csv("test.csv")
#View(data)
#Convert the CSV to Json format and verify it worked by printing
inJSON <- toJSON(data)
print(inJSON)
#Finding the locations of the separators of each data entry.
#This will allow us to determine to know where to begin and end the substring
# generating two tables indicating each location of patterns along the whole string
start_table <- data.frame(str_locate_all(inJSON, "key1"))
#start_table
stop_table <- data.frame(str_locate_all(inJSON, ","))
#selecting row 1, col 2.
#stop_table[1,2]
#defining the function that will restructure the data for bubble bulk upload format
restrucJSON <- function(jsonformat){
#prepping the loop
count <- str_count(jsonformat, "key1") #count the number of times the loop is going to run, or the number of database entries
a <- 1 #there is only one row per entry
b <- 6 #there are 6 columns in this data, so we take every 6th position of the commas
#loop to print
for (i in c(1:count)) { #using the count to tell the loop how many times to run
x <- start_table[a,1]
y <- stop_table[b,1]
print(substr(jsonformat, x-2, y-1))
a <- a+1 #
b <- b+6 #start counting from the next 6th comma
}
}
#lets try out the function with the inJSON object
export <- restrucJSON(inJSON)
I tried it with bulk upload and it worked:
This is the message that i received from bubble in Rstudio:
as you can tell, it gives you a status on each data entry at the bottom of the console.
Here i am uploading as a .txt file in the same format as is used in the POST function above. However, i upload a file instead of typing the body:
body = upload_file(“/test.txt”),
There may be better ways to do this, but this way worked for me