Automating Data Loads with cURL Follow
In this article:
- cURL overview
- Mandatory cURL parameters
- Optional cURL parameters
- cURL loads using PHP
- cURL loads for large files
- Additional resources
Hāpara allows the automation of data loads by uploading Class and Student data through standard HTTP requests. Doing so involves extracting data from your student information system, and pushing a CSV file to Hāpara via a URL request tool, such as cURL.
To implement this process, the following steps are required (we recommend reaching out to your IT or Tech support team to query this further):
- Create an automated data export from your student information system to a local directory.
- Create 2x CSV files formatted with specific headers to be read by Hāpara. One would contain course and teacher data, and the other student data. Templates can be created and downloaded via the Manual Configuration page.
- Create a CRON job (Unix), Scheduled Task (Windows), or similar, containing a URL request to send the CSV files to Hāpara.
Here is an example cURL command line to upload CSV files to Hāpara:
curl -F "passkey=<PASS_KEY>" -F "uploadFile=@<PATH_TO_YOUR_CSV_FILE>" https://td-setup.appspot.com/<DOMAIN_NAME>/csvupload
Mandatory cURL parameters
The mandatory parameters of this request are:
- passkey: A pass key used to authenticate against the domain for which the CSV file is uploaded. This pass key can be found at https://settings.teacherdashboard.com/#/d/studentdomain/loader/url-load. If the pass key is not correct, then the uploaded CSV file will not be processed.
- uploadFile: The CSV file object to be uploaded. The location of the file must be prefixed with @. This instructs cURL to construct an HTTP Request containing the file.
Optional cURL parameters
The optional parameters of this request are:
- loadAll: If this parameter is set to "True" (or any non-null value), then the load will process all records specified in the CSV file. If it is not specified, the load will only process records which it detects have changed from the previous load.
- multipleYears: If this parameter is set to "Y", then the load will process all classes specified in the CSV file regardless of year. If it is not specified, then the load will only process classes that are in the same year as existing classes.
email: If this parameter is set to an email address then all email notifications for this load will be sent to the specified email. If it is not specified then the load will send any emails to the Primary Contact.
cURL loads using PHP
For those using PHP, a suggested format of the PHP command is below:
$target_url = 'https://td-setup.appspot.com/
$post = array(
'passkey' => '<PASS KEY>',
'uploadFile' => '@<PATH_TO_YOUR_CSV_FILE>');
$ch = curl_init();
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
cURL loads for large files
If your CSV is larger than 5MB, then we recommend building your URL request in this format:
curl -F "passkey=<PASS_KEY>" https://td-setup.appspot.com/<DOMAIN_NAME>/createuploadurl | xargs curl -X POST --header "Transfer-Encoding: chunked" -F "file=@<PATH_TO_YOUR_CSV_FILE>"
Windows users can create a batch file to run the following:
Note: tmpFile is a path you're setting for a temporary file to be created by this process.
curl -F "passkey=<PASS_KEY>" https://td-setup.appspot.com/<DOMAIN_NAME>/createuploadurl > tmpFile
set /p myvar= < tmpFile
curl -X POST --header "Transfer-Encoding: chunked" -F "file=@<PATH_TO_YOUR_CSV_FILE>" %myvar%