I recently started a blog using a pre-configured Ubuntu 18.04 Ghost droplet at DigitalOcean. I have no web development knowledge at all but through lots of googling and trial & error, have managed to bumble my way into getting things mostly working.
One thing that’s been driving me crazy - every few minutes I get these messages in my syslog:
node[3291]: [2019-04-08 21:46:04] #033[31mERROR#033[39m
node[3291]: #033[31m
node[3291]: #033[31mThe {{#get}} helper requires your theme to have API access.#033[39m
node[3291]: #033[37m"Please enable the v2 API via your theme’s package.json file."#033[39m
node[3291]: #033[33m"See Ghost Handlebars Theme Structure - Developer Documentation "#033[39m
node[3291]: #033[1m#033[37mError ID:#033[39m#033[22m
node[3291]: #033[90m----------------------------------------#033[39m
node[3291]: #033[90mDisabledFeatureError: The {{#get}} helper requires your theme to have API access
node[3291]: at DisabledFeatureError.GhostError (/var/www/ghost/versions/2.19.1/core/server/lib/common/errors.js:10:26)
Things I have done:
Installed the free Editorial theme
From the Ghost admin page, created a new integration - https://myurl/ghost/api/v2/content/posts/?key=MyPublicKey appears to work
Confirmed that the theme’s package.json has:
“engines”: {
“ghost”: “>=2.0.0”,
“ghost-api”: “v2”
Edited the theme’s default.hbs to contain: “<script src=”{{asset “main/js/content-api.min.js”}}“>”
I’ve googled exhaustively and read through documentation but can’t figure this out. I feel like I need to set the API key somewhere but I can’t seem to find where to set it at.
Hey @thaifoon The error you are seeing is definitely a result of wrong (v1) or empty ghost-api configuration is the active theme. What you could try is activating the different theme and then reactivating the one you need again (this will repopulate api-version if you changed it by hand) or you could restart the ghost process, so it rereads theme version again. Let me know if this worked
@naz - I just tried your suggestion of activating a different theme (the default Casper theme) then reactivating the one I want. Unfortunately I am still getting the V2 API access error.
I also tried adding the below as a script to the code injection section:
var contentApiKey = “myapikey”;
var content_api_key = ‘myapikey’;
var site_url = “https://mywebsite.com”;
I’m basically trying anything I can manage to find via google then restarting ghost to see if it works but am pretty much out of ideas here. Help?
@thaifoon just tried reproducing the steps you have provided and there’s what worked for me.
Started from fresh ghost installation and created an integration.
Downloaded and activated Editorial theme and did not modify anything there (it’s using API v2 by default), didn’t see
Added the same minified content-api SDK script from here on default.hbs template in the end of {{!-- Theme Scripts --}} section (line 62 in latest Editorial release)
Added following script on default.hbs template after the script above the following example from here and the final result looks like:
The output of the script was as expected - fetched posts titles and primary author names. Let me know if this works for you.
A separate issue is with error messages you are receiving (The {{#get}} helper requires your theme to have API access). Can you track down the point at which they appear? Are you loading a specific page or maybe making an API call? It did not happen in my case when I used an unmodified editorial template, so wandering what could be causing it
Thank you for that - adding your code to default.hbs did help some! I clicked around my site with the browser console open and noticed that the ‘#get helper’ error only appears on my index/home page now. The console now also shows post titles which is new and presumably good. Syslog also shows GET requests to /ghost/api/v2/content/posts/?key=myapikey&limit=5&include=tags%2Cauthors which I think is a good sign.
If I view source code of my home page in the browser, I do see two instances of "console.error("The {{#get}} helper requires your theme to have API access. Please enable the v2 API via your theme’s package.json file. See Ghost Handlebars Theme Structure - Developer Documentation “)”. The first time is after the section loading social media icons. The second is after the footer in the navigation section.
Strangely enough, that error does show up when I view source on a post’s page but not in the browser console.
I did modify the Editorial theme in an attempt to clean it up a bit and customize it to my liking so it’s very probable I did something wrong. If you can offer a clue where to start that’d be great. If not, I’ll continue my trial & error bumbling. You’ve helped quite a bit already and it’s much appreciated.
It’s hard to tell what kind of code is causing these enable the v2 API errors without seeing them To find which part of the code is causing these errors exactly would try removing the modifications you’ve done to the original theme (as original doesn’t cause errors) and then would add these modifications step by step while checking for errors.
Would love to know what caused this error in the end, maybe would save a headache somebody else trying similar thing
I don’t understand why commenting out the sections still caused me to see the script errors when I viewed source in the browser but totally deleting the ‘featured post’ section from index.hbs fixed the error messages spamming my syslog. Not sure what modifications I made would have caused API errors there but I’m just happy things are working better for now.