Answers.Body: <p>Turns out the controller action was running, but since I was just using <code>return</code>, Craft was looking for a template to show once the functions were complete, and failing when it didn't find one. Using <code>die();</code> after the function runs is working fine.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-10-29T23:34:24.873Z
Answers.LastActivityDate: 2019-10-29T23:34:24.873Z
Answers.UserDisplayName: Chad Crowell
Body: <p>I built a plugin for Craft 3 and need to run one of its actions via CRON. I know I can set this up as a console command, and will do that, but before I get there, I'd like to solve this issue.</p>
  
  <p>I noticed my CRON was failing, and when I attempted to run the URL myself, at <code>http://campaigns.gcx.loc/actions/gcxCampaignTools/stats/syncCampaignsRemote</code>, I got this error:</p>
  
  <pre><code>yii\base\InvalidRouteException: Unable to resolve the request "gcxCampaignTools/stats/syncCampaignsLocal". in /Users/Chad/Sites/gcx-campaigns/vendor/yiisoft/yii2/base/Module.php:537
  Stack trace:
  #0 /Users/Chad/Sites/gcx-campaigns/vendor/craftcms/cms/src/web/Application.php(299): yii\base\Module-&gt;runAction('gcxCampaignTool...', Array)
  #1 /Users/Chad/Sites/gcx-campaigns/vendor/craftcms/cms/src/web/Application.php(566): craft\web\Application-&gt;runAction('gcxCampaignTool...', Array)
  #2 /Users/Chad/Sites/gcx-campaigns/vendor/craftcms/cms/src/web/Application.php(278): craft\web\Application-&gt;_processActionRequest(Object(craft\web\Request))
  #3 /Users/Chad/Sites/gcx-campaigns/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application-&gt;handleRequest(Object(craft\web\Request))
  #4 /Users/Chad/Sites/gcx-campaigns/public_html/index.php(21): yii\base\Application-&gt;run()
  #5 {main}
  
  Next yii\web\NotFoundHttpException: Page not found. in /Users/Chad/Sites/gcx-campaigns/vendor/craftcms/cms/src/web/Application.php:570
  Stack trace:
  #0 /Users/Chad/Sites/gcx-campaigns/vendor/craftcms/cms/src/web/Application.php(278): craft\web\Application-&gt;_processActionRequest(Object(craft\web\Request))
  #1 /Users/Chad/Sites/gcx-campaigns/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application-&gt;handleRequest(Object(craft\web\Request))
  #2 /Users/Chad/Sites/gcx-campaigns/public_html/index.php(21): yii\base\Application-&gt;run()
  #3 {main}
  </code></pre>
  
  <p>The action works from a front end link with the following code when I am logged in (user must be logged in to use the entire app, so login is required to run the action as well):</p>
  
  <p><code>&lt;a href="/actions/gcx-campaign-tools/stats/sync-campaigns-local"&gt;Sync Campaigns&lt;/a&gt;</code></p>
  
  <p>Because it worked when logged in, I thought I may need to allow anonymous in the controller, but that was already in place. I tried both <code>protected $allowAnonymous = true;</code> and <code>protected $allowAnonymous = ['actionSyncCampaignsRemote'];</code> with the same results.</p>
  
  <p>Here is a screenshot of my plugin file structure and controller actions: <a href="https://d.pr/i/2ByGtW" rel="nofollow noreferrer">screenshot</a></p>
  
  <p>As you can see there I did put <code>URL: /actions/gcx-campaign-tools/stats/sync-campaigns-remote</code> in the code comments when I built this. Loading that URL produces the same error.</p>
  
  <p>What am I missing here?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-09-25T07:41:09.863Z
Comments.Text: Can you try
  `protected $allowAnonymous = ['sync-campaigns-remote']; `
Comments.UserDisplayName: Seb
Tags: <controller><cron>
Title: Action route not available from URL. What do I have wrong?
ThreadText: # Action route not available from URL. What do I have wrong?
  
  (Asked by: username_0 on 2019-09-24)
  
  I built a plugin for Craft 3 and need to run one of its actions via CRON. I know I can set this up as a console command, and will do that, but before I get there, I'd like to solve this issue.
  
  I noticed my CRON was failing, and when I attempted to run the URL myself, at `http://campaigns.gcx.loc/actions/gcxCampaignTools/stats/syncCampaignsRemote`, I got this error:
  
  ```
  yii\base\InvalidRouteException: Unable to resolve the request "gcxCampaignTools/stats/syncCampaignsLocal". in /Users/username_0/Sites/gcx-campaigns/vendor/yiisoft/yii2/base/Module.php:537
  Stack trace:
  #0 /Users/username_0/Sites/gcx-campaigns/vendor/craftcms/cms/src/web/Application.php(299): yii\base\Module->runAction('gcxCampaignTool...', Array)
  #1 /Users/username_0/Sites/gcx-campaigns/vendor/craftcms/cms/src/web/Application.php(566): craft\web\Application->runAction('gcxCampaignTool...', Array)
  #2 /Users/username_0/Sites/gcx-campaigns/vendor/craftcms/cms/src/web/Application.php(278): craft\web\Application->_processActionRequest(Object(craft\web\Request))
  #3 /Users/username_0/Sites/gcx-campaigns/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application->handleRequest(Object(craft\web\Request))
  #4 /Users/username_0/Sites/gcx-campaigns/public_html/index.php(21): yii\base\Application->run()
  #5 {main}
  
  Next yii\web\NotFoundHttpException: Page not found. in /Users/username_0/Sites/gcx-campaigns/vendor/craftcms/cms/src/web/Application.php:570
  Stack trace:
  #0 /Users/username_0/Sites/gcx-campaigns/vendor/craftcms/cms/src/web/Application.php(278): craft\web\Application->_processActionRequest(Object(craft\web\Request))
  #1 /Users/username_0/Sites/gcx-campaigns/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application->handleRequest(Object(craft\web\Request))
  #2 /Users/username_0/Sites/gcx-campaigns/public_html/index.php(21): yii\base\Application->run()
  #3 {main}
  
  ```
  
  The action works from a front end link with the following code when I am logged in (user must be logged in to use the entire app, so login is required to run the action as well):
  
  `<a href="/actions/gcx-campaign-tools/stats/sync-campaigns-local">Sync Campaigns</a>`
  
  Because it worked when logged in, I thought I may need to allow anonymous in the controller, but that was already in place. I tried both `protected $allowAnonymous = true;` and `protected $allowAnonymous = ['actionSyncCampaignsRemote'];` with the same results.
  
  Here is a screenshot of my plugin file structure and controller actions: [screenshot](https://d.pr/i/2ByGtW)
  
  As you can see there I did put `URL: /actions/gcx-campaign-tools/stats/sync-campaigns-remote` in the code comments when I built this. Loading that URL produces the same error.
  
  What am I missing here?
  
  **Tags:** controller, cron
  
  > **Comments:**
  > **username_1**: Can you try `protected $allowAnonymous = ['sync-campaigns-remote']; `  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2019-10-29. Score: 2
  
  Turns out the controller action was running, but since I was just using `return`, Craft was looking for a template to show once the functions were complete, and failing when it didn't find one. Using `die();` after the function runs is working fine.
  
  
  ---
  
  