Retriving teams from API returns empty

Hey guys, I hope you all are doing great.

I have been using the Mattermost API and found an issue with this endpoint https://{myurl}/api/v4/teams it always returns empty but there is a team on the account. It allows me to retrieve the team by providing the ID with the endpoint https://{myurl}/api/v4/teams/{teamid}. I wonder what might be happening.

Version:

Hi, @RicardoE105

Can I please confirm how you run the API on your end? One of the easiest way is via cURL on the terminal. For example:

curl --location --request GET "https://<url>/api/v4/teams" --header "Authorization: Bearer <personal_token>" --header "Content-Type: application/json" | python -m json.tool

Replace the following parameters with the appropriate values:

  • token: The personal access token generated for the user who is running the API call .
  • url: FQDN of your Mattermost instance.

A sample of running this command successfully will look like this:

Ahmad-Danials-MacBook-Pro:~ ahmaddanialmohammad$ curl --location --request GET "https://ahmaddanial.mattermost.com/api/v4/teams" --header "Authorization: Bearer oi68k5u56tyntm4oz8ex8f1zgh" --header "Content-Type: application/json" | python -m json.tool
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1455  100  1455    0     0   129k      0 --:--:-- --:--:-- --:--:--  129k
[
    {
        "allow_open_invite": true,
        "allowed_domains": "",
        "company_name": "",
        "create_at": 1587421102735,
        "delete_at": 0,
        "description": "",
        "display_name": "Supreme",
        "email": "ahmad.danial@mattermost.com",
        "group_constrained": null,
        "id": "tbakp8msi3g33b5reb8h6k8kjr",
        "invite_id": "q8eza1ghztr1zcn45rt8ugyxmy",
        "name": "supreme",
        "scheme_id": null,
        "type": "O",
        "update_at": 1587529390771
    },
    {
        "allow_open_invite": true,
        "allowed_domains": "",
        "company_name": "",
        "create_at": 1587421099506,
        "delete_at": 0,
        "description": "",
        "display_name": "Undefeated",
        "email": "ahmad.danial@mattermost.com",
        "group_constrained": null,
        "id": "sae41b3bmjd1iy8z87rr7i3zgc",
        "invite_id": "1rxu48thrtyp7bb5ezmynsce5a",
        "name": "undefeated",
        "scheme_id": null,
        "type": "O",
        "update_at": 1587421283876
    },
    {
        "allow_open_invite": true,
        "allowed_domains": "",
        "company_name": "",
        "create_at": 1587421105726,
        "delete_at": 0,
        "description": "",
        "display_name": "Stussy",
        "email": "ahmad.danial@mattermost.com",
        "group_constrained": null,
        "id": "tbihkd7cxfbauxsmgpif9gw86c",
        "invite_id": "kr1ph6pkofb8unopp9oeq43gmc",
        "name": "stussy",
        "scheme_id": null,
        "type": "O",
        "update_at": 1587421291764
    },
    {
        "allow_open_invite": false,
        "allowed_domains": "",
        "company_name": "",
        "create_at": 1587529557832,
        "delete_at": 0,
        "description": "",
        "display_name": "Yohji",
        "email": "ahmad.danial@mattermost.com",
        "group_constrained": true,
        "id": "qxjos985tib9deuufodmcmnceh",
        "invite_id": "7rrhwabxptbuby4kns3w3qkjkr",
        "name": "yohji",
        "scheme_id": null,
        "type": "O",
        "update_at": 1587530472365
    }
]

Can you please give it a try and let me know how it goes on your end? Thanks.

@RicardoE105, I believe the global teams endpoint just has different semantics that what you might expect. I believe it doesn’t list the teams you can see, but rather the teams you could see, even if you weren’t in any of them. There is a /api/v4/users/<user_id>/teams to get your own teams.

As another example using the endpoint shared by @jesse:

Ahmad-Danials-MacBook-Pro:~ ahmaddanialmohammad$ curl --location --request GET "http://ahmaddanial.mattermost.com/api/v4/users/q1pbfm9refyx3rsjm5b8hqaosw/teams" --header "Authorization: Bearer oi68k5u56tyntm4oz8ex8f1zgh" --header "Content-Type: application/json" | python -m json.tool
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1093  100  1093    0     0   213k      0 --:--:-- --:--:-- --:--:--  213k
[
        "allow_open_invite": true,
        "allowed_domains": "",
        "company_name": "",
        "create_at": 1587421102735,
        "delete_at": 0,
        "description": "",
        "display_name": "Supreme",
        "email": "ahmad.danial@mattermost.com",
        "group_constrained": null,
        "id": "tbakp8msi3g33b5reb8h6k8kjr",
        "invite_id": "q8eza1ghztr1zcn45rt8ugyxmy",
        "name": "supreme",
        "scheme_id": null,
        "type": "O",
        "update_at": 1587529390771
    },
    {
        "allow_open_invite": true,
        "allowed_domains": "",
        "company_name": "",
        "create_at": 1587421099506,
        "delete_at": 0,
        "description": "",
        "display_name": "Undefeated",
        "email": "ahmad.danial@mattermost.com",
        "group_constrained": null,
        "id": "sae41b3bmjd1iy8z87rr7i3zgc",
        "invite_id": "1rxu48thrtyp7bb5ezmynsce5a",
        "name": "undefeated",
        "scheme_id": null,
        "type": "O",
        "update_at": 1587421283876
    }
]

Thanks @ahmaddanial @jesse this was really helpful.

2 Likes