Vanilla API
I am having trouble in enabling Vanilla API. I placed the code inside api folder inside Applications folder. It's visible from the dashboard but during the enabling it throws the following error.
( ! ) Fatal error: Call to undefined function paths() in vanilla\applications\api\settings\class.hooks.php on line 38
Call Stack
Time Memory Function Location
1 0.0018 393872 {main}( ) ..\index.php:0
2 0.1699 8849032 Gdn_Dispatcher->Dispatch( ) ..\index.php:53
3 0.1937 10761640 call_user_func_array
( ) ..\class.dispatcher.php:322
4 0.1938 10761928 SettingsController->TestAddon( ) ..\class.dispatcher.php:322
5 0.1939 10766024 Gdn_ApplicationManager->TestApplication( ) ..\class.settingscontroller.php:836
6 5.2350 10814752 APIHooks->setup( )
Any suggestions?
Comments
Ok now I am able to enable it after download 0.0.8 dev version
Vanilla API v0.0.10-dev requires the latest master branch of Vanilla to work. If you want to use the API for anything besides testing, v0.0.9-dev and below is not what you want to use.
Kasper Kronborg Isager (kasperisager) | Freelance Developer @Vanilla | Hit me up: Google Mail or Vanilla Mail | Find me on GitHub
Thanks Kasper for guiding me. I've downloaded v0.0.9 and enabled it. The problem now I find is that the Application Interface is showing endpoint as http://localhost/api/ which throws a 404 error. I have vanilla as an embedded forum in my main website.
i think you need to check out mod_rewrite and override config on your web server.
@brianc, Can you please let me know where to do this? You mean any change in .htaccess file?
@kasper, I have the latest vanilla (cloned from master) and vanilla api installed. Still not able to access the end point. What could be the reason?
@kasper,@brianc I found the endpoint as the following http://127.0.0.1/vvanilla/api/discussions/1. Through postman rest client I can now see the JSON output.
@georgegijo Perfect, glad to hear! If you aren't already using it, I made a Postman Collection for Vanilla API: https://www.getpostman.com/collections/88c667ea752bc4f0186e
Kasper Kronborg Isager (kasperisager) | Freelance Developer @Vanilla | Hit me up: Google Mail or Vanilla Mail | Find me on GitHub
@kasper, Thanks for the collection. Now I am trying get a token but getting an error. Can you please let me know what could be the problem?
curl_setopt($curl_handle,CURLOPT_URL,'http://localhost/vvanilla/api/discussions');
$frequest = "username='admin'&email='admin@admin.com'×tamp=".$dtimestamp;
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $frequest);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
{"Code":401,"Exception":"API.Error.User.Invalid"}
It looks like the user you're passing in doesn't exists – hence the error.
Kasper Kronborg Isager (kasperisager) | Freelance Developer @Vanilla | Hit me up: Google Mail or Vanilla Mail | Find me on GitHub
@kasper, I got that resolved when I changed 'admin' to admin (removing quotes) and email also the same way. But now I am getting a token error.
{"Code":401,"Exception":"API.Error.Token.Missing"}
I'm following the documentation mentioned in https://github.com/kasperisager/vanilla-api/wiki/Authentication. I am trying obtain token before sending the actual request.
You need to provide a token in the request, as per the documentation
Kasper Kronborg Isager (kasperisager) | Freelance Developer @Vanilla | Hit me up: Google Mail or Vanilla Mail | Find me on GitHub
@kasper, I am trying to figure out how a token can be generated. Is there any specific endpoint to generate a token?
Tokens are like "passwords" generated by both the client and the server and then compared. You will therefore have to generate a token per the documentation and include it in your request.
Kasper Kronborg Isager (kasperisager) | Freelance Developer @Vanilla | Hit me up: Google Mail or Vanilla Mail | Find me on GitHub
@kasper, Ok. Now I understood what I was missing. From the documentation I have the following code.
Now I am getting a PHP error **Warning: strtolower() expects parameter 1 to be string, array given **
Is there anything missing here?
implode('-', $Request);
has to be$Request = implode('-', $Request);
Kasper Kronborg Isager (kasperisager) | Freelance Developer @Vanilla | Hit me up: Google Mail or Vanilla Mail | Find me on GitHub
@kasper, Thank you for pointing me that. Now that error is gone. I created a token with the secret (I assume secret is the value mentioned in API.Settings.Secret.Label). Still getting an error {"Code":401,"Exception":"API.Error.Token.Invalid"}. as $Request['query'] = 'value'; I provided the endpoint http://localhost/vanilla/api/discussions. Is that right?
The secret is found in the dashboard "Application Interface" menu and is stored in your configuration file.
Kasper Kronborg Isager (kasperisager) | Freelance Developer @Vanilla | Hit me up: Google Mail or Vanilla Mail | Find me on GitHub
@kasper,Thanks for guiding me. I copied the secret. What is expected for the parameter $Request['query'] = 'value'; I provided the endpoint http://localhost/vanilla/api/discussions. Is that right?
$Request['query'] = 'value';
is just an example of how you can add more query params to the request if need be. As for the endpoint, that depends on your installation. If your Vanilla installation is located at http://localhost/vanilla/, your endpoint seems correct.You're most certainly welcome by the way, I'm glad I was able to help out!
Kasper Kronborg Isager (kasperisager) | Freelance Developer @Vanilla | Hit me up: Google Mail or Vanilla Mail | Find me on GitHub