Can't get data from notifications.json (solved)

(magoz) #1

I’m trying to get the number of notifications via /notifications.json on

I’ve enabled CORS in the app.yml file (also allowed on Discourse > Settings > cors origins).
I’m already using other .json to retrieve other information and it works perfectly ( /latest.json, for example).

Here is my code in PHP, I’m just trying to get one of the objects, to see if I can access to any of the information.

$string_notifications = file_get_contents('');
$json_notifications = json_decode($string_notifications, true);
$notifications_total_number = $json_notifications['total_rows_notifications'];
echo $notifications_total_number;

But it doesn’t work. It doesn’t retrieve anything.
If I go to via the browser it works.

Any ideas why is not working? Am I missing something?

(Sam Saffron) #2

I am SUPER confused here, are you properly using the Discourse API and specifying API keys.

Try going to that page as anonymous in chrome, that is what you are doing.

(magoz) #3

Thanks for your help, I solved the issue.
As you pointed, there was a problem related to the API keys, I didn’t pass correctly the username value.

(Régis Hanol) #4

Saved Searches Plugin