XF 2.1 API Auth problems

Sam Pearson

Member
Hello,

I'm a rookie with API's and have successfully been able to get a list of threads using this code;

PHP:
$headers = array(
    'Content-type: application/x-www-form-urlencoded',
    'XF-Api-Key: API_KEY',
    'XF-Api-User: USER_ID'
);

$url = 'https://BOARD_URL/api/threads';

$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, $url);
$json = curl_exec($ch);

echo $json;

But I'm trying to authenticate a user. This is the code I've been trying but I keep getting a 403. What am I doing wrong?

PHP:
$headers = array(
    'Content-type: multipart/form-data',
    'XF-Api-Key: API_KEY',
    'XF-Api-User: USER_ID',
);

$url = 'https://BOARD_URL/api/auth?login=USERNAME&password=PASSWORD';

$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
$json = curl_exec($ch);

echo $json;

Any help would be greatly appreciated! :)
 
Never worked with the API, but I guess you should use POST in order to pass the parameters, not GET.

Also take care:
Tests a login and password for validity. Only available to super user keys.
 
Top Bottom