Answers.Body: <p>OK I found out what I did wrong</p>
  
  <p>the help message gives</p>
  
  <pre><code>Usage:                                                                                                                                                       
    generate:api [options] [--] \EntityName&gt;&gt; \ActionName&gt;&gt;                                                                                                    
  
  Arguments:                                                                                                                                                   
  &lt;EntityName&gt;               The entity against which the action runs (eg 
  "Contact", "MyEntity")                                                             
  ...
  </code></pre>
  
  <p>Being new to this I followed the instructions and typed</p>
  
  <pre><code>civix generate:api    \Contact \myendpoint
  </code></pre>
  
  <p>Which works without complaint, and puts the end point in the explore  ... but doesn't work.</p>
  
  <p>interestingly </p>
  
  <pre><code>civix generate:api    Contact \myendpoint
  </code></pre>
  
  <p>does work - it is the backslash before Contact that breaks things.  </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-18T15:45:53.130Z
Answers.Text: Great. I am used to the command civix generate:api --schedule Daily Entity Action
  Without any slashes.
Answers.UserDisplayName: Jaap Jansma - CiviCooP
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-18T14:14:30.713Z
Answers.LastActivityDate: 2018-05-18T14:14:30.713Z
Answers.UserDisplayName: Alan Fuller
Answers.Body: <p>@Alan </p>
  
  <p>you are right - to setup a schedule job you need to create an API and then you need to add that API in your JOBS folder - </p>
  
  <p>But you are trying both together - this is the correct syntax </p>
  
  <pre><code>civix generate:api NewEntity NewAction
  </code></pre>
  
  <p>First create your extension folder - then cd extensionfolder</p>
  
  <p>Then run the above code to generate an API </p>
  
  <p>Then you need to create an entry in civicrm_job table - this can be done through SQL or in the front end </p>
  
  <p>Refer: <a href="https://docs.civicrm.org/dev/en/latest/extensions/civix/#generate-api" rel="nofollow noreferrer">https://docs.civicrm.org/dev/en/latest/extensions/civix/#generate-api</a></p>
  
  <p>I guess this helps !!!!</p>
  
  <p>Thanks</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-18T13:59:50.620Z
Answers.Text: I started from scratch - I was trying to build the API in a existing extension with reports and queries in it.   For some reason ( that I can't get to the bottom of ) is in the reports extension it didn't work ( generated some different files ), but starting as a brand new extension was fine ..
Answers.UserDisplayName: Alan Fuller
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-18T14:02:27.457Z
Answers.Text: I guess your old extension wasn't build using Civix then - try to move the API folder from your newly created extension it should work
Answers.UserDisplayName: Ramesh - ARTECH Consultancy
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-18T15:44:47.303Z
Answers.Text: With civix you can create an api and in one go a scheduled job with it. So no need to do SQL etc...
Answers.UserDisplayName: Jaap Jansma - CiviCooP
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-18T19:07:28.043Z
Answers.Text: @Ramesh You used a really old link - I've updated it with the current one.  Doc links now should be to docs.civicrm.org
Answers.UserDisplayName: Aidan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-18T13:46:00.937Z
Answers.LastActivityDate: 2018-05-18T19:06:04.053Z
Answers.LastEditDate: 2018-05-18T19:06:04.053Z
Answers.UserDisplayName: Ramesh - ARTECH Consultancy
Body: <p>As far as I can understand, the way to add a job is to set it up in your extension as an API.</p>
  
  <p>So I have created the default code using </p>
  
  <pre><code> civix generate:api --schedule=Daily Contact myendpoint
  </code></pre>
  
  <p>Enabled the extention and it appears in the API Explorer</p>
  
  <p>But when I run it</p>
  
  <pre><code>cv api Contact.myendpoint debug=1 
  </code></pre>
  
  <p>it fails</p>
  
  <p><code>{
      "error_code": "not-found",
      "entity": "Contact",
      "action": "myendpoint",
      "trace": "#0 /var/www/html/wp-content/plugins/civicrm/civicrm/Civi/API/Kernel.php(166): Civi\\API\\Kernel-&gt;resolve(Array)\n#1 /var/www/html/wp-content/plugins/civicrm/civicrm/Civi/API/Kernel.php(100): Civi\\API\\Kernel-&gt;runRequest(Array)\n#2 /var/www/html/wp-content/plugins/civicrm/civicrm/api/api.php(23): Civi\\API\\Kernel-&gt;runSafe('Contact', 'myendpoint', Array, NULL)\n#3 /var/www/html/wp-content/plugins/civicrm/civicrm/CRM/Utils/REST.php(311): civicrm_api('Contact', 'myendpoint', Array)\n#4 /var/www/html/wp-content/plugins/civicrm/civicrm/CRM/Utils/REST.php(548): CRM_Utils_REST::process(Array, Array)\n#5 /var/www/html/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php(275): CRM_Utils_REST::ajax()\n#6 /var/www/html/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php(84): CRM_Core_Invoke::runItem(Array)\n#7 /var/www/html/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php(52): CRM_Core_Invoke::_invoke(Array)\n#8 /var/www/html/wp-content/plugins/civicrm/civicrm.php(1246): CRM_Core_Invoke::invoke(Array)\n#9 /var/www/html/wp-includes/class-wp-hook.php(286): CiviCRM_For_WordPress-&gt;invoke('')\n#10 /var/www/html/wp-includes/class-wp-hook.php(310): WP_Hook-&gt;apply_filters('', Array)\n#11 /var/www/html/wp-includes/plugin.php(453): WP_Hook-&gt;do_action(Array)\n#12 /var/www/html/wp-admin/admin.php(224): do_action('toplevel_page_C...')\n#13 {main}",
      "is_error": 1,
      "error_message": "API (Contact, myendpoint) does not exist (join the API team and implement it!)"
  }</code></p>
  
  <p>So it looks like I'm missing a step somewhere - but can't find it in the docs .. any help?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-18T13:27:35.383Z
Comments.Text: Can you check if api(api/v3Contact/Myendpoint.php) file has been  created in your extension folder?
Comments.UserDisplayName: Pradeep Nayak
Tags: <api>
Title: Adding a job as API
ThreadText: # Adding a job as API
  
  (Asked by: username_0 on 2018-05-18)
  
  As far as I can understand, the way to add a job is to set it up in your extension as an API.
  
  So I have created the default code using
  
  ```
   civix generate:api --schedule=Daily Contact myendpoint
  
  ```
  
  Enabled the extention and it appears in the API Explorer
  
  But when I run it
  
  ```
  cv api Contact.myendpoint debug=1 
  
  ```
  
  it fails
  
  `{
  "error_code": "not-found",
  "entity": "Contact",
  "action": "myendpoint",
  "trace": "#0 /var/www/html/wp-content/plugins/civicrm/civicrm/Civi/API/Kernel.php(166): Civi\\API\\Kernel->resolve(Array)\n#1 /var/www/html/wp-content/plugins/civicrm/civicrm/Civi/API/Kernel.php(100): Civi\\API\\Kernel->runRequest(Array)\n#2 /var/www/html/wp-content/plugins/civicrm/civicrm/api/api.php(23): Civi\\API\\Kernel->runSafe('Contact', 'myendpoint', Array, NULL)\n#3 /var/www/html/wp-content/plugins/civicrm/civicrm/CRM/Utils/REST.php(311): civicrm_api('Contact', 'myendpoint', Array)\n#4 /var/www/html/wp-content/plugins/civicrm/civicrm/CRM/Utils/REST.php(548): CRM_Utils_REST::process(Array, Array)\n#5 /var/www/html/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php(275): CRM_Utils_REST::ajax()\n#6 /var/www/html/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php(84): CRM_Core_Invoke::runItem(Array)\n#7 /var/www/html/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php(52): CRM_Core_Invoke::_invoke(Array)\n#8 /var/www/html/wp-content/plugins/civicrm/civicrm.php(1246): CRM_Core_Invoke::invoke(Array)\n#9 /var/www/html/wp-includes/class-wp-hook.php(286): CiviCRM_For_WordPress->invoke('')\n#10 /var/www/html/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters('', Array)\n#11 /var/www/html/wp-includes/plugin.php(453): WP_Hook->do_action(Array)\n#12 /var/www/html/wp-admin/admin.php(224): do_action('toplevel_page_C...')\n#13 {main}",
  "is_error": 1,
  "error_message": "API (Contact, myendpoint) does not exist (join the API team and implement it!)"
  }`
  
  So it looks like I'm missing a step somewhere - but can't find it in the docs .. any help?
  
  **Tags:** api
  
  > **Comments:**
  > **username_1**: Can you check if api(api/v3Contact/Myendpoint.php) file has been  created in your extension folder?  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2018-05-18. Score: 1
  
  OK I found out what I did wrong
  
  the help message gives
  
  ```
  Usage:                                                                                                                                                       
    generate:api [options] [--] \EntityName>> \ActionName>>                                                                                                    
  
  Arguments:                                                                                                                                                   
  <EntityName>               The entity against which the action runs (eg 
  "Contact", "MyEntity")                                                             
  ...
  
  ```
  
  Being new to this I followed the instructions and typed
  
  ```
  civix generate:api    \Contact \myendpoint
  
  ```
  
  Which works without complaint, and puts the end point in the explore ... but doesn't work.
  
  interestingly
  
  ```
  civix generate:api    Contact \myendpoint
  
  ```
  
  does work - it is the backslash before Contact that breaks things.
  
  > **Comments:**
  > **username_2**: Great. I am used to the command civix generate:api --schedule Daily Entity Action Without any slashes.  
  
  ---
  
  ### Answer by username_3 on 2018-05-18. Score: 0
  
  @username_0
  
  you are right - to setup a schedule job you need to create an API and then you need to add that API in your JOBS folder -
  
  But you are trying both together - this is the correct syntax
  
  ```
  civix generate:api NewEntity NewAction
  
  ```
  
  First create your extension folder - then cd extensionfolder
  
  Then run the above code to generate an API
  
  Then you need to create an entry in civicrm\_job table - this can be done through SQL or in the front end
  
  Refer: <https://docs.civicrm.org/dev/en/latest/extensions/civix/#generate-api>
  
  I guess this helps !!!!
  
  Thanks
  
  > **Comments:**
  > **username_0**: I started from scratch - I was trying to build the API in a existing extension with reports and queries in it.   For some reason ( that I can't get to the bottom of ) is in the reports extension it didn't work ( generated some different files ), but starting as a brand new extension was fine ..  
  > **username_3**: I guess your old extension wasn't build using Civix then - try to move the API folder from your newly created extension it should work  
  > **username_2**: With civix you can create an api and in one go a scheduled job with it. So no need to do SQL etc...  
  > **username_4**: @username_3 You used a really old link - I've updated it with the current one.  Doc links now should be to docs.civicrm.org  
  
  ---
  
  