0

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?

  • 1
    Can you check if api(api/v3Contact/Myendpoint.php) file has been created in your extension folder? – Pradeep Nayak May 18 '18 at 13:27
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.

| improve this answer | |
  • Great. I am used to the command civix generate:api --schedule Daily Entity Action Without any slashes. – Jaap Jansma - CiviCooP May 18 '18 at 15:45
0

@Alan

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

| improve this answer | |
  • 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 .. – Alan Fuller May 18 '18 at 13:59
  • 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 – Ramesh - ARTECH Consultancy May 18 '18 at 14:02
  • With civix you can create an api and in one go a scheduled job with it. So no need to do SQL etc... – Jaap Jansma - CiviCooP May 18 '18 at 15:44
  • @Ramesh You used a really old link - I've updated it with the current one. Doc links now should be to docs.civicrm.org – Aidan May 18 '18 at 19:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.