...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
stdClass Object ( [self] => http://your-domain.com/course_enrollment?uid=200&nid=310300 // The current page the list value displaying information [first] => http://your-domain.com/course_enrollment?uid=200&nid=310300&page=0 [last] => http://your-domain.com/course_enrollment?uid=200&nid=310300&page=0 [list] => [] ) |
Continuing from section #1, as the call to http://your-domain.com/course_enrollment?uid=200&nid=300 has returned an empty list, we can can now send the creation request.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
$response = json_decode($json); $list = $response->list; if(empty($list)){ $data = array( 'nid' => 300, 'uid' => 200, 'enrollmenttype' => 'webservice_call', 'type' => 'webservice_call', 'status' => 1, ); // Send the enrollment creation request $curl = curl_init("http://your-domain.com/course_enrollment"); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-CSRF-Token: $token", "Content-Type: application/json")); curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($curl, CURLOPT_USERPWD, "restws_webservice:webservice_password"); //Your credentials go here curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data)); $response = curl_exec($curl); } |
...