Regarding Discourse APIs

Please let me know why I do not see email id in response when I use the User APIs to get user by username or get user by user_id operation. Also, is there any method to get user details by using email_id in the response of a GET request?

To get a user’s email address, I do it in two steps- 1. get the username somehow, 2. call /users/{username}.json

I am doing the same, but I am not getting email in the output.
Response I got:

 {
    "user_badges": [],
    "user": {
        "id": 99,
        "username": "Ashutosh",
        "name": "Ashutosh Verma",
        "avatar_template": "https://avatars.discourse-cdn.com/v4/letter/a/e480ec/{size}.png",
        "last_posted_at": null,
        "last_seen_at": null,
        "created_at": "2021-05-31T05:53:07.914Z",
        "ignored": false,
        "muted": false,
        "can_ignore_user": true,
        "can_mute_user": true,
        "can_send_private_messages": true,
        "can_send_private_message_to_user": true,
        "trust_level": 1,
        "moderator": false,
        "admin": false,
        "title": null,
        "badge_count": 0,
        "custom_fields": {},
        "time_read": 0,
        "recent_time_read": 0,
        "primary_group_id": null,
        "primary_group_name": null,
        "primary_group_flair_url": null,
        "primary_group_flair_bg_color": null,
        "primary_group_flair_color": null,
        "featured_topic": null,
        "bio_excerpt": null,
        "staged": false,
        "bio_cooked": null,
        "can_edit": true,
        "can_edit_username": true,
        "can_edit_email": true,
        "can_edit_name": true,
        "uploaded_avatar_id": null,
        "has_title_badges": false,
        "pending_count": 0,
        "profile_view_count": 0,
        "second_factor_enabled": false,
        "can_upload_profile_header": true,
        "can_upload_user_card_background": true,
        "post_count": 0,
        "can_be_deleted": true,
        "can_delete_all_posts": true,
        "locale": null,
        "muted_category_ids": [],
        "regular_category_ids": [],
        "watched_tags": [],
        "watching_first_post_tags": [],
        "tracked_tags": [],
        "muted_tags": [],
        "tracked_category_ids": [],
        "watched_category_ids": [],
        "watched_first_post_category_ids": [],
        "system_avatar_upload_id": null,
        "system_avatar_template": "https://avatars.discourse-cdn.com/v4/letter/a/e480ec/{size}.png",
        "muted_usernames": [],
        "ignored_usernames": [],
        "allowed_pm_usernames": [],
        "mailing_list_posts_per_day": 0,
        "can_change_bio": true,
        "can_change_location": true,
        "can_change_website": true,
        "user_api_keys": null,
        "user_auth_tokens": [],
        "user_notification_schedule": {
            "enabled": false,
            "day_0_start_time": 480,
            "day_0_end_time": 1020,
            "day_1_start_time": 480,
            "day_1_end_time": 1020,
            "day_2_start_time": 480,
            "day_2_end_time": 1020,
            "day_3_start_time": 480,
            "day_3_end_time": 1020,
            "day_4_start_time": 480,
            "day_4_end_time": 1020,
            "day_5_start_time": 480,
            "day_5_end_time": 1020,
            "day_6_start_time": 480,
            "day_6_end_time": 1020
        },
        "use_logo_small_as_avatar": false,
        "date_of_birth": null,
        "featured_user_badge_ids": [],
        "invited_by": null,
        "groups": [
            {
                "id": 10,
                "automatic": true,
                "name": "trust_level_0",
                "display_name": "trust_level_0",
                "user_count": 2,
                "mentionable_level": 0,
                "messageable_level": 0,
                "visibility_level": 1,
                "primary_group": false,
                "title": null,
                "grant_trust_level": null,
                "incoming_email": null,
                "has_messages": false,
                "flair_url": null,
                "flair_bg_color": null,
                "flair_color": null,
                "bio_raw": null,
                "bio_cooked": null,
                "bio_excerpt": null,
                "public_admission": false,
                "public_exit": false,
                "allow_membership_requests": false,
                "full_name": null,
                "default_notification_level": 3,
                "membership_request_template": null,
                "members_visibility_level": 0,
                "can_see_members": true,
                "can_admin_group": true,
                "publish_read_state": false
            },
            {
                "id": 11,
                "automatic": true,
                "name": "trust_level_1",
                "display_name": "trust_level_1",
                "user_count": 2,
                "mentionable_level": 0,
                "messageable_level": 0,
                "visibility_level": 1,
                "primary_group": false,
                "title": null,
                "grant_trust_level": null,
                "incoming_email": null,
                "has_messages": false,
                "flair_url": null,
                "flair_bg_color": null,
                "flair_color": null,
                "bio_raw": null,
                "bio_cooked": null,
                "bio_excerpt": null,
                "public_admission": false,
                "public_exit": false,
                "allow_membership_requests": false,
                "full_name": null,
                "default_notification_level": 3,
                "membership_request_template": null,
                "members_visibility_level": 0,
                "can_see_members": true,
                "can_admin_group": true,
                "publish_read_state": false
            }
        ],
        "group_users": [
            {
                "group_id": 10,
                "user_id": 99,
                "notification_level": 3
            },
            {
                "group_id": 11,
                "user_id": 99,
                "notification_level": 3
            }
        ],
        "user_option": {
            "user_id": 99,
            "mailing_list_mode": false,
            "mailing_list_mode_frequency": 1,
            "email_digests": true,
            "email_level": 1,
            "email_messages_level": 0,
            "external_links_in_new_tab": false,
            "color_scheme_id": null,
            "dark_scheme_id": null,
            "dynamic_favicon": false,
            "enable_quoting": true,
            "enable_defer": false,
            "digest_after_minutes": 1440,
            "automatically_unpin_topics": true,
            "auto_track_topics_after_msecs": 240000,
            "notification_level_when_replying": 2,
            "new_topic_duration_minutes": 2880,
            "email_previous_replies": 2,
            "email_in_reply_to": false,
            "like_notification_frequency": 1,
            "include_tl0_in_digests": false,
            "theme_ids": [
                1
            ],
            "theme_key_seq": 0,
            "allow_private_messages": true,
            "enable_allowed_pm_users": false,
            "homepage_id": null,
            "hide_profile_and_presence": false,
            "text_size": "normal",
            "text_size_seq": 0,
            "title_count_mode": "notifications",
            "timezone": null,
            "skip_new_user_tips": false
        }
    }
}

Please reply ASAP.

Apologies, that doesn’t work for me anymore either. But this does: /u/{username}/emails.json

1 Like

Are you making that request with an admin api key?

2 Likes

Yes, I have solved that problem. Moreover, please let me know are there any options of getting a user by user’s email_id? Where can I find the “external id” to get a user by external_id operation.