XF 2.2 api installed ?

jtorral

Member
Dumb question but "forumurl/api/users" is not existent in 2.2 there is no api dir.

Does the api need to be installed? The doc says its there already.

Not Found​

The requested URL was not found on this server.

This is all I have

Code:
[root@ded4021 www]# find ./ -name "*" | grep api
./internal_data/code_cache/phrase_groups/l0/api_scope.php
./internal_data/code_cache/phrase_groups/l0/api_error.php
./internal_data/code_cache/phrase_groups/l1/api_scope.php
./internal_data/code_cache/phrase_groups/l1/api_error.php
./internal_data/code_cache/templates/l0/s2/email/api_key_change.php
./internal_data/code_cache/templates/l0/s0/admin/api_key_view.php
./internal_data/code_cache/templates/l0/s0/admin/api_key_edit.php
./internal_data/code_cache/templates/l0/s0/admin/api_scope_edit.php
./internal_data/code_cache/templates/l0/s0/admin/api_scope_list.php
./internal_data/code_cache/templates/l0/s0/admin/api_key_list.php
./internal_data/code_cache/templates/l0/s0/admin/api_key_macros.php
./internal_data/code_cache/templates/l0/s0/admin/api_key_regenerate.php
./internal_data/code_cache/templates/l0/s0/email/api_key_change.php
./internal_data/code_cache/templates/l0/s1/email/api_key_change.php
./internal_data/code_cache/templates/l1/s2/email/api_key_change.php
./internal_data/code_cache/templates/l1/s0/admin/api_key_view.php
./internal_data/code_cache/templates/l1/s0/admin/api_key_edit.php
./internal_data/code_cache/templates/l1/s0/admin/api_scope_edit.php
./internal_data/code_cache/templates/l1/s0/admin/api_scope_list.php
./internal_data/code_cache/templates/l1/s0/admin/api_key_list.php
./internal_data/code_cache/templates/l1/s0/admin/api_key_macros.php
./internal_data/code_cache/templates/l1/s0/admin/api_key_regenerate.php
./internal_data/code_cache/templates/l1/s0/email/api_key_change.php
./internal_data/code_cache/templates/l1/s1/email/api_key_change.php
./src/addons/XF/_data/api_scopes.xml
./src/addons/XFI/_data/api_scopes.xml
./src/vendor/braintree/braintree_php/lib/ssl/api_braintreegateway_com.ca.crt
./src/vendor/symfony/css-selector/Parser/Tokenizer/TokenizerEscaping.php
 
You need to send cURL requests to make API calls.

For example: curl --header "XF-Api-Key: <key here>" --request GET "http://localhost/xf/api/users/1/"

What are you trying to do?
 
Code:
$url = "${parentwebsite}/api/users/1";
//$url = "${website}/testapi";

$ch = curl_init();

curl_setopt_array($ch, [
  CURLOPT_URL => $url,
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_TIMEOUT => 0,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => [ "XF-Api-Key: $xfApi" ]
]);

$res = curl_exec($ch);

if ( !($res = curl_exec($ch)) ) {
   $err = curl_error($ch) ;
   echo $err;
   curl_close($ch);
   exit;
}
 
This should be the response when navigating to an API URL in the browser.

1673899943375.png

I just tested it on your site and it works the same.

You aren't using Friendly URLs so you need to use site.com/index.php?api/users .
That's the same for all routes other than the index.
 
looking at your example helped me resolve it. Thanks!

All documented code references the url to be: url/api/users....

when in fact i had to change my url to be url/index.php?api/users
 
Top Bottom