Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Fix typos

...

Code Block
languagephp
titleRetrieving a user profile
<?php
// Retrieve a profile in XML:
$curl = curl_init('http://your-domain.com/profile2.xml?user=2');
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);
$response = curl_exec($curl);
print $response;

...

Code Block
languagephp
titleCreating a course
<?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
)
*/

...