# Cakephp 3.7 REST Api issue "Missing CSRF token cookie"

**URL:** <https://discourse.cakephp.org/t/cakephp-3-7-rest-api-issue-missing-csrf-token-cookie/7824>\
**Category:** Need Help\
**Created:** [May 15, 2020, 8:59pm UTC](https://discourse.cakephp.org/t/cakephp-3-7-rest-api-issue-missing-csrf-token-cookie/7824 "2020-05-15T20:59:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![twhess](https://avatars.discourse-cdn.com/v4/letter/t/da6949/32.png) [@twhess](https://discourse.cakephp.org/u/twhess)\
**Post date:** [May 15, 2020, 8:59pm UTC](https://discourse.cakephp.org/t/cakephp-3-7-rest-api-issue-missing-csrf-token-cookie/7824/1 "2020-05-15T20:59:05Z")

</div>

I’m trying to set up API on Cakephp 3.7 so I can acces with REST Api call from another app but keep running into “Missing CSRF token cookie” error. I’ve tried everything I could find but still have not been able to get it to work. Anyone have any suggestions of something I might have overlooked. I’ve installed the plugin to manage CORS. I’ve tried to disable CORS but the error keeps coming from the middleware. Not sure what I’m doing wrong.

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [May 15, 2020, 10:07pm UTC](https://discourse.cakephp.org/t/cakephp-3-7-rest-api-issue-missing-csrf-token-cookie/7824/2 "2020-05-15T22:07:33Z")

</div>

CORS and CSRF are two completely different things. Is your API running over Ajax or regular requests?

---

<div class="post-metadata">

**Author:** ![twhess](https://avatars.discourse-cdn.com/v4/letter/t/da6949/32.png) [@twhess](https://discourse.cakephp.org/u/twhess)\
**Post date:** [May 16, 2020, 12:53am UTC](https://discourse.cakephp.org/t/cakephp-3-7-rest-api-issue-missing-csrf-token-cookie/7824/3 "2020-05-16T00:53:14Z")

</div>

That’s probably why I’m struggling. I thought they were related. I was using ajax and after struggling with that I started testing it with a curl call and got the same error. Thanks for the reply.

---

<div class="post-metadata">

**Author:** ![twhess](https://avatars.discourse-cdn.com/v4/letter/t/da6949/32.png) [@twhess](https://discourse.cakephp.org/u/twhess)\
**Post date:** [May 16, 2020, 1:05am UTC](https://discourse.cakephp.org/t/cakephp-3-7-rest-api-issue-missing-csrf-token-cookie/7824/4 "2020-05-16T01:05:56Z")

</div>

Actually I had disabled CSRF protection in the routes.php file and I was still getting the error.

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [May 16, 2020, 2:02am UTC](https://discourse.cakephp.org/t/cakephp-3-7-rest-api-issue-missing-csrf-token-cookie/7824/5 "2020-05-16T02:02:10Z")

</div>

Search your code for references to CSRF. You’ve either got the component or the middleware activated somewhere. People have this question all the time, and it’s always because they have it turned on in a place they didn’t think of.

---

<div class="post-metadata">

**Author:** ![twhess](https://avatars.discourse-cdn.com/v4/letter/t/da6949/32.png) [@twhess](https://discourse.cakephp.org/u/twhess)\
**Post date:** [May 16, 2020, 2:13am UTC](https://discourse.cakephp.org/t/cakephp-3-7-rest-api-issue-missing-csrf-token-cookie/7824/6 "2020-05-16T02:13:30Z")

</div>

Thanks, I’ll dig into the code a little deeper.

---

<div class="post-metadata">

**Author:** ![sherwinrobles](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/sherwinrobles/32/1251_2.png) [@sherwinrobles](https://discourse.cakephp.org/u/sherwinrobles)\
**Post date:** [May 14, 2024, 7:26am UTC](https://discourse.cakephp.org/t/cakephp-3-7-rest-api-issue-missing-csrf-token-cookie/7824/7 "2024-05-14T07:26:15Z")

</div>

I know this is 4 years ago. Just encountered it today, I though might help others with same issue:

I use this solution: [Security - 3.10](https://book.cakephp.org/3/en/controllers/components/security.html#disabling-security-component-for-specific-actions)

And still encountered the issue. What solved the problem is you need to clear the cache.

via terminal: bin/cake cache clear\_all
