Project

General

Profile

Submitting data from a third-party study » History » Revision 2

Revision 1 (Tom Clegg, 04/07/2016 07:13 PM) → Revision 2/4 (Tom Clegg, 04/07/2016 07:17 PM)

h1. Submitting data from a third-party study 

 As a third-party study (aka third-party collection event), you can add data to a participant's public profile using an HTTP POST request. 

 <pre> 
 POST https://tapestry.example.org/third_party/add_dataset 
 </pre> 

 There are three mandatory form fields: 
 * @api_key@ is a unique identifier assigned to your study by Tapestry. It is shown on the "view/edit collection event" page. 
 * @participant_id@ is a unique identifier for the participant whose data is being contributed. It is sent to your third-party web site as @participant_id@ when the participant first signs up for your study. 
 * @data_sources_tsv@ is TSV data, where each line looks like 
 * <pre> 
 md5_hex <TAB> file_size_decimal <TAB> url [<CR>] <LF> 
 </pre> 

 Tapestry will download the data files from the URLs provided in the TSV data. The files will be added to the participant's profile only if _all_ files are downloaded successfully and the content matches the provided MD5 and file size. 

 Example: 
 * <pre> 
 ( 
 tmpfile=$(mktemp) 
 printf 'c5b5b2fa19bd66ff23211d9f844e0131\t36868\thttps://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js\n' >"$tmpfile" 
 curl -f -X POST \ 
   --form api_key=9/d5b032dbea658e5289d311a1cdd4a7cba86fae0d \ 
   --form participant_code=85551af2bbc451e66344f27a2cf471994aed64f5 \ 
   --form data_sources_tsv=\<"$tmpfile" \ 
   https://my.pgp-hms.org/third_party/add_dataset 
 ret=$? 
 echo 
 rm "$tmpfile" 
 [[ $ret = 0 ]] 
 ) && echo "success!" 
 </pre> 

 Example output: 
 * <pre> 
 HTTP/1.1 200 OK 

 {"success":true} 
 </pre> 

 If any of the form values are invalid or improperly formatted, the HTTP response will have status 4xx and a JSON body with error details. Example: 
 * <pre> 
 HTTP/1.1 400 Bad Request 

 {"errors":["invalid api_key parameter"]} 
 </pre>