I have a clinical trials management site I work with where I need to copy this number from one field to another field for a couple hundred protocols (individual pages on the site):
I have figured out how to use an API call to get everything from this particular page:
library(jsonlite)
library(httr)
library(crul)
token<- "12345"
base <- "https://mywebsite.website.com"
endpoint <- "/website-api/rest/protocolManagementDetails/"
protocol <- "2506" ##This is the 'protocolID' of that particular page
call2<-paste(base,endpoint, protocol, sep="")
httpResponse <- GET(call2, add_headers(authorization = token))
results = fromJSON(content(httpResponse, "text"))
results
Which will return something like this:
And I know how to modify that result and push it in a new hospitalaccountno manually:
results$hospitalAccountNo<-"654321"
base <- "https://mywebsite.website.com"
endpoint <- "/website-api/rest/protocolManagementDetails/"
protocol <- "2506"
call2<-paste(base,endpoint, protocol, sep="")
httpResponse <- PUT(call2,
add_headers(authorization = token), body=results, encode = "json", verbose())
So if I were to go through one protocol at a time manually, that's easy! I'd plug the number for each protocol in, GET it, change the hospital account number, PUT it and call it a day. But I'd love to automate that process using the numbers from a dataframe like this:
df<-structure(list(PROTOCOL_ID = c(1, 22, 543, 421, 55, 6), PROTOCOL_NO = c("CTSU-E1234",
"BRUOG-j-1234", "tp-P-bob61", "PFIZER-T", "Jimbo",
"INCONGRUENCE"), LIBRARY = c("Non-Oncology", "Oncology", "Non-Oncology",
"Oncology", "Oncology", "Non-Oncology")), row.names = c(NA, 6L), class = "data.frame")
So to summarize:
I'd love to loop through the 'df' dataframe, swapping in that df$protocol_id for the 'protocol' part of the api calls.
So the loop would 'GET' protocol 1, get the number from the internalaccountno, paste it into the hospitalaccountno, then 'PUT' protocol 1, then 'GET' and 'PUT' 22, then 543.. and so on until it runs out of numbers. Does that make sense?