Jump to content

Guides

Sending your first request

URL

If you have URL rewriting enabled on your community (if you're not sure, look at the URL to a topic or other page on your community: if it contains index.php?/ you do not have URL rewriting enabled), you will send your requests to:

http://www.example.com/api/

For example, to access the GET /core/hello endpoint, you will send a HTTP GET request to http://www.example.com/api/core/hello.

If you do not have URL rewriting enabled, you will send you requests to:

http://www.example.com/api/index.php?/

For example, to access the GET /core/hello endpoint, you will send a HTTP GET request to http://www.example.com/api/index.php?/core/hello.

Warning

If you do not have URL rewriting enabled, the URL already has a ? in it. Therefore, to send additional parameters, you will append a & rather than a ?. For example http://www.example.com/api/index.php?/core/hello&foo=bar

Authorization

If supported by your server, the recommend method for authorization is via HTTP Basic Auth. Send the API key you created earlier as the username, and no password.

If your server does not support this because PHP is running as a CGI binary, you will see a message in the AdminCP to indicate this. To authenticate, you should send an additional "key" parameter (in the query string for a GET request or along with the other parameters for a POST or PUT request) with the API key you created earlier. For example:

http://www.example.com/api/core/hello?key={apiKeyHere}

Parameters

For GET requests, provide all parameters in the query string. For POST and PUT requests, all parameters should be sent Form URL-Encoded.

Response

The Response is always JSON-encoded.

Example Code

Here is an example request to the /core/hello endpoint:

<?php
	
	$communityUrl = 'http://localhost:8888/ips4/';
	$apiKey = 'c7a349a1629f02cd2855a58d77646f6d';
		
	$curl = curl_init( $communityUrl . 'api/core/hello' );
	curl_setopt_array( $curl, array(
		CURLOPT_RETURNTRANSFER	=> TRUE,
		CURLOPT_HTTPAUTH	=> CURLAUTH_BASIC,
		CURLOPT_USERPWD		=> "{$apiKey}:"
	) );
	$response = curl_exec( $curl );
	
	echo $response;

If all goes successfully, this script will output:

{
    "communityName": "IPS Community Suite",
    "communityUrl": "http:\/\/localhost:8888\/ips4\/",
    "ipsVersion": "4.1.6"
}

 


  Report Guide


×