<?php
$curl = curl_init('http://your-domain.com/restws/session/token');
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "admin:webservicepw"); // Your web service user credentials goesgo here.
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
$token = curl_exec($curl);
// The token looks like "q71OBx05wtECfjA0KmXf6wiktewrywNhkMZv-OcfyOA%"
// Build a course to send, in JSON. The fields and allowed values are available on the full documentation site.
$course = array(
'title' => 'my new course',
'type' => 'course',
'field_course_summary' => array(
'value' => 'this is the summary<b>This is bold</b>',
'format' => 'full_html'
),
'author' => 1,
'status' => 1,
);
$json = json_encode($course);
$curl = curl_init('http://your-domain.com/node.json');
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "admin:webservicepw"); //Your credentials goesgo here
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUTPOST');
curl_setopt($curl, CURLOPT_POSTFIELDS, $json);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-CSRF-Token: $token", "Content-Type: application/json"));
$response = json_decode(curl_exec($curl));
// The response looks like (JSON decoded)
/*
stdClass Object
(
[uri] => http://743your-domain.localhostcom/node/33
[id] => 33
[resource] => node
[uuid] => 5121134e-dbfa-4011-939e-180290a02618
)
*/
|