Invalid Session error when trying to post a message

Summary
When running the following API,
http:///api/v4/posts,
I am getting the following error, even though I logged in only a couple seconds earlier.
Invalid or expired session, please login again

Steps to reproduce
I am hosting a docker container for Mattermost server with an nginx reverse proxy server.
I hit the API
http:///api/v4/posts,
and i get this error
Invalid or expired session, please login again

Even though there is MMAUTHTOKEN present in the cookies in the application tab in devtools, and I have given withCredentials:true in the code.

The message should be posted but because of this I am getting a 401 Error message. What am I doing wrong?

Hi vishnu! Welcome to the Mattermost forums.

It sounds like a session or authentication issue. You might find these docs helpful:

:small_blue_diamond: Configuration settings
:small_blue_diamond: API Authentication

Let me know if you need more guidance! :blush: