I have started to use R2 and I get an OAuth token and tried to simply pass it in to the REST calls and it seems to work for me. These are internal calls to REST APIs that we have written. I am surprised it worked so easily (just be adding the setrequestheader). I didn't think this was going to be supported until R3. Call me a happy camper :)
For the new RESTClient I simply add a request header with the token and it works
RESTClient rest
rest = create RESTClient
rest.setrequestheader("Authorization", "Bearer " + is_token )
ll_rc = rest.Retrieve( dw_1, "https://xxxxx/List?Product=ASSESS")
To pass a PDF with other data to a REST call, I have done the following:
string ls_file, jsondata
blob lblob_pdf
int li_rc
Long ll_rc, ll_stat
httpclient http
ls_file = "C:\test.pdf"
JSONParser json
json = create JSONParser
ll_rc = f_file_to_blob(ls_file , ref lblob_pdf) //Converts file to blob
jsondata = '{"Access":"A", "Archive":"N","Product":"ASSESS"}' // data I need to pass to REST API
http = create httpclient
string ls_BOUNDARY
ls_BOUNDARY = "$$$Boundary$$$" // use or build a string that is not part of the other content!
// build the content
blob lblob_data
lblob_data = blob ("--" + ls_BOUNDARY + "~r~n" + &
'Content-Disposition: form-data; name="dockey"' + &
"~r~nContent-Type: " + "application/json;charset=UTF-8" + &
"~r~n~r~n" + jsondata + "~r~n", EncodingUTF8!)
lblob_data = lblob_data + blob ("--" + ls_BOUNDARY + "~r~n" + &
'Content-Disposition: form-data; name="docfile"; filename="' + 'Test' + '"' + &
"~r~nContent-Type: " + "application/octet-stream" + "~r~n~r~n", EncodingUTF8!) + &
lblob_pdf + blob ("~r~n--" + ls_BOUNDARY + "--~r~n", EncodingUTF8!)
http.setrequestheader( "Content-Type", "multipart/form-data; boundary=" + ls_BOUNDARY)
http.setrequestheader("Authorization", "Bearer " + is_write_token )
li_rc = http.sendrequest( 'POST', 'https://api.systest.worksafebc.com/v1/Correspondence_int/Upload', lblob_data)
ll_stat = http.GetResponseStatusCode()
MessageBox("Stat", String(ll_stat ))