Mattermost, Inc.

[SOLVED] Cannot make API calls

I am working with the Mattermost web services and have followed along with the guide located here. I have no trouble obtaining a session token and then making a GET call to the example API URL (curl -i -H 'Authorization: Bearer hyr5dmb1mbb49c44qmx4whniso' http://localhost:8065/api/v3/users/me). However, when I try to make calls to any other APIs, I receive the following error:

{"id":"api.context.404.app_error","message":"Sorry, we could not find the page.", "detailed_error":"There doesn't appear to be an api call for the url='API_URL'. Typo? are yo missing a team_id or user_id as part of the url?"...

For example, I was trying to make a call to http://localhost:8065/api/v3/channels/CHANNEL_ID/posts/0/5 and received the above error. The same occurs when I try to make a call to api/v3/posts/POST_ID. For the CHANNEL_ID and POST_ID I am retrieving the specific IDs from the postgresql database.

What am I doing wrong? Am I supposed to include a team_id or user_id when I make calls?

Hi @thej

Have you tried http://localhost/api/v3/channels/CHANNEL_ID/posts/page/0/5 ??

Hi @elias,

I tried that and got the same error. For the channel ID, do I use the name of a channel in mattermost or the auto-generated ID of a channel found in the PSQL database? I tried both and had no luck with either. I think this may be a problem with setup, but I’m not sure where to look.

Here is a full error message:

{"id":"api.context.404.app_error","message":"Sorry, we could not find the page.","detailed_error":"There doesn't appear to be an api call for the url='/api/v3/channels/[CHANNEL_ID OBTAINED FROM PSQL DATABASE]/posts/page/0/5'.  Typo? are you missing a team_id or user_id as part of the url?","request_id":"","status_code":404,"is_oauth":false}

I’ll try this later on today and I’ll post back

Ok @thej

The thing is that you need to build the URL like this

http:///api/v3/teams//channels//posts/page/0/5 in your example.

Hope this solves your problem.

Let me know

1 Like

@elias This worked like a charm!!! Thank you very much. How did you figure out to include teams/ in the URL so I can employ the same process for future API calls? For reference, I’ve been consulting the source code at https://github.com/mattermost/platform/blob/master/model/client.go and at https://github.com/mattermost/platform/blob/master/api to come up with the URLs I’ve been making requests to.

Hi @thej

At the beginning of https://github.com/mattermost/platform/blob/master/api/api.go you have all the routes prefix you can use that as a starting point.

Can you please set the title of this thread as [SOLVED] Cannot make API calls ?

Thanks my friend, I’m glad it helped.

1 Like