4 * YOURLS : sample file showing how to use the API
5 * This shows how to tap into your YOURLS install API from *ANOTHER* server
6 * not from a file hosted on the same server. It's just a bit dumb to make a
7 * remote HTTP request to the server the request originates from.
13 // EDIT THIS: your auth parameters
17 // EDIT THIS: the query parameters
18 $url = 'http://planetozh.com/blog/'; // URL to shrink
19 $keyword = 'ozh'; // optional keyword
20 $format = 'json'; // output format: 'json', 'xml' or 'simple'
22 // EDIT THIS: the URL of the API file
23 $api_url = 'http://yoursite/yourls-api.php';
25 // Init the CURL session
27 curl_setopt($ch, CURLOPT_URL, $api_url);
28 curl_setopt($ch, CURLOPT_HEADER, 0); // No header in the result
29 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return, do not echo result
30 curl_setopt($ch, CURLOPT_POST, 1); // This is a POST request
31 curl_setopt($ch, CURLOPT_POSTFIELDS, array( // Data to POST
33 'keyword' => $keyword,
34 'title' => $keyword, // If omitted, Yourls will lookup TITLE with an HTTP request
36 'action' => 'shorturl',
37 'username' => $username,
38 'password' => $password
41 // Fetch and return content
42 $data = curl_exec($ch);
45 // Do something with the result. Here, we just echo it.