# Cannot auth API Token - invalid\_grant

**URL:** <https://forum.mautic.org/t/cannot-auth-api-token-invalid-grant/34451>\
**Category:** Product Support\
**Created:** [December 14, 2024, 10:50pm UTC](https://forum.mautic.org/t/cannot-auth-api-token-invalid-grant/34451 "2024-12-14T22:50:49Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![anavivian](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/anavivian/32/13328_2.png) [@anavivian](https://forum.mautic.org/u/anavivian)\
**Post date:** [December 14, 2024, 10:50pm UTC](https://forum.mautic.org/t/cannot-auth-api-token-invalid-grant/34451/1 "2024-12-14T22:50:49Z")

</div>

**Your software**  
My Mautic version is: 5.2  
My PHP version is: 8.2  
My Database type and version is: idk

**Your problem**  
My problem is:  
I was trying to integrate with a service, then they told me my api token was invalid. Then tried this command:

curl -X GET “[https://my.mautic.address/api/users/me](https://my.mautic.address/api/users/me)” -H “Authorization: Bearer 7\_3iajoynzwhkw000k8sccscocs4sc4w8kwow4k4wcw8ss4sswg4”

Result:  
{“errors”:[{“message”:“The access token provided is invalid.”,“code”:401,“type”:“invalid\_grant”}]}

Cleaned cache, tried to increase token expire date, create several tokens…

Is this installation necessary to my version? [GitHub - mautic/api-library: Mautic API Library](https://github.com/mautic/api-library)

Tried to install it, but got a problem with my server memory, could not install so far. Then tried to add only the lib folder on the base of my mautic, and nothing changed.

Any ideas?

These errors are showing in the log:  
No errors on the log 😔

Steps I have tried to fix the problem:

---

<div class="post-metadata">

**Author:** ![marcus42](https://avatars.discourse-cdn.com/v4/letter/m/ac91a4/32.png) [@marcus42](https://forum.mautic.org/u/marcus42)\
**Post date:** [December 15, 2024, 9:57am UTC](https://forum.mautic.org/t/cannot-auth-api-token-invalid-grant/34451/2 "2024-12-15T09:57:52Z")

</div>

Are you sure about your cURL?

This is one of my cURL:

```auto
# Mautic URL
MAUTIC="my.mautic.address"

# Mautic administrator
USER="admin"

# Mautic Token
PASSWORD="7_3iajoynzwhkw000k8sccscocs4sc4w8kwow4k4wcw8ss4sswg4"

curl -X GET -u $USER:$PASSWORD https://$MAUTIC/api/users/self

```

Hope it will help you.

---

<div class="post-metadata">

**Author:** ![anavivian](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/anavivian/32/13328_2.png) [@anavivian](https://forum.mautic.org/u/anavivian)\
**Post date:** [December 15, 2024, 11:30am UTC](https://forum.mautic.org/t/cannot-auth-api-token-invalid-grant/34451/3 "2024-12-15T11:30:12Z")

</div>

> [@marcus42](#):
>
> `curl -X GET -u $USER:$PASSWORD https://$MAUTIC/api/users/self`

Thank you for the reply.

Tried like that, but forgot to mention that I need to use Oauth2 for integrating with the service. And your Curl command is HTTP basic auth.

---

<div class="post-metadata">

**Author:** ![anavivian](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/anavivian/32/13328_2.png) [@anavivian](https://forum.mautic.org/u/anavivian)\
**Post date:** [December 15, 2024, 2:49pm UTC](https://forum.mautic.org/t/cannot-auth-api-token-invalid-grant/34451/4 "2024-12-15T14:49:38Z")

</div>

What i want to know is… why fresh created tokens are invalid?  
Is there a way to check validity via database? Or is there a way to log information about tokens errors on my log files?

I’ve installed my mautic via softaculous, all working fine, except for this…

---

<div class="post-metadata">

**Author:** ![marcus42](https://avatars.discourse-cdn.com/v4/letter/m/ac91a4/32.png) [@marcus42](https://forum.mautic.org/u/marcus42)\
**Post date:** [December 15, 2024, 10:16pm UTC](https://forum.mautic.org/t/cannot-auth-api-token-invalid-grant/34451/5 "2024-12-15T22:16:58Z")

</div>

Maybe this will help?

> **[How to Use the Mautic Rest API](https://www.mautic.org/blog/developer/how-to-use-the-mautic-rest-api)**
>
> Looking for example REST API and Mautic API documentation? This article gives a great high-level review of how to integrate Mautic API with third parties.

---

<div class="post-metadata">

**Author:** ![anavivian](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/anavivian/32/13328_2.png) [@anavivian](https://forum.mautic.org/u/anavivian)\
**Post date:** [December 16, 2024, 7:54pm UTC](https://forum.mautic.org/t/cannot-auth-api-token-invalid-grant/34451/6 "2024-12-16T19:54:11Z")

</div>

Ty for the reply.  
Idk why I could integrate for a while with the other system. Token was authorized, could send users to specific segments. Then after a day token stopped working, even setting it to several days.

What is the maximum value i can set on those fields?  
Access token lifetime (in minutes)  
Refresh token lifetime (in days)

---

<div class="post-metadata">

**Author:** ![anavivian](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/anavivian/32/13328_2.png) [@anavivian](https://forum.mautic.org/u/anavivian)\
**Post date:** [December 16, 2024, 7:54pm UTC](https://forum.mautic.org/t/cannot-auth-api-token-invalid-grant/34451/7 "2024-12-16T19:54:59Z")

</div>

Oh, btw, i saw this topic before. But its from 2015, and my mautic version is 5.2, are those steps useful for 5.2 version?

---

<div class="post-metadata">

**Author:** ![anavivian](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/anavivian/32/13328_2.png) [@anavivian](https://forum.mautic.org/u/anavivian)\
**Post date:** [December 16, 2024, 8:57pm UTC](https://forum.mautic.org/t/cannot-auth-api-token-invalid-grant/34451/8 "2024-12-16T20:57:27Z")

</div>

Well, installed all mautic and api-modules on my pc, then moved vendor folder + composer.lock composer.json to my server. Then deleted all previous integrations on the service I was looking to integrate. Its working… Hope it keeps working for a while now
