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

I’m trying to get the number of notifications via /notifications.json on https://mysite.com

I’ve enabled CORS in the app.yml file (also allowed http://mysite.com 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('https://forum.mysite.com/notifications.json');
$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 https://forum.mysite.com/notifications.json via the browser it works.

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

2 Likes

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.

4 Likes

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.

3 Likes