Discourse_api URL not found error

Hi everyone,

I’m attempting to use the discourse_api gem:

client = DiscourseApi::Client.new("https://<mysite>.com")
client.api_key = "<my global key>"
client.api_username = "system"

…as the basic setup, then

client.latest_topics

returns data correctly but…

client.get_dashboard_stats

returns a URL “not_found” error. I’m assuming something fails when a route requires a key, since client.latest_topics works.

I’ve doublechecked that the key is correct, even made a new one and tried that. It has the global access option checked as well. The URL is also correct. Anything else I should check? :slight_smile:

Cheers!

2 Likes

This is very likely an api key authentication issue.

If you open up a new incognito browser window to your site you are not logged into and browse to that route https://yoursite/admin/dashboard.json will return

{"errors":["The requested URL or resource could not be found."],"error_type":"not_found"}

But if you are logged into your site and browse to the same url you should see the json result.

One other thing to check is if api key to “all users” or “single user”? If it is set to single user make sure it matches with the user you are making the api request for.

That being said it looks like the two dashboard endpoints in the api gem need updating. the get_dashboard_stats still works, but doesn’t return as much info as it used to and looks like get_dashboard_stats_totals will need updating.

4 Likes

I agree that it is likely something do to with the keys, but I’ve tried with the “All users” and “Single user” settings (using an admin username) and still I get the not found error you posted.

The key is correct, the URL is correct and I’ve tried all the different settings as well as other endpoints listed in the api examples. All return “The requested URL or resource could not be found”. I can’t think of much else to do :smiley: :sweat_smile: I’m guessing the user scopes do not apply here for global keys?

1 Like

Can you run this command

gem list discourse_api

to see what version of the discourse_api gem you are using?

3 Likes

0.10.0 - so that’s probably the reason, it is attempting to use URL parameters instead of HTTP Headers :slight_smile: Thanks!

3 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.