civiCASE apis and running php from command line

Open terminal as super user [su]

php /var/www/drupal/sites/all/modules/contrib/civicrm/bin/cli.php -e /var/www/drupal/sites/all/modules/contrib/civicrm/bin/csv/export.php contact -e contact -a get –output  –contact_id=2

or, if already in the civicrm/bin directory:
cd /var/www/drupal/sites/all/modules/contrib/civicrm/bin/
php cli.php -e ../bin/csv/export.php contact -e contact -a get –output –contact_id=2

===================

following are notes that got me to this

===========

To run php code on a web site like civiCRM use the cURL program on linux.

First, civiCRM needs a site key.

  • Run the following in a command prompt
    php -r ‘echo md5(uniqid(rand(), true)) . “\n”;’
    highlight the result and right-click copy
  • Navigate to, as administrator,
    /var/www/drupal/sites/default
    open civicrm.settings.php
    search for CIVICRM_SITE_KEY
    Paste the result you copied into the appropriate place, as indicated by xxx’s below
    define( ‘CIVICRM_SITE_KEY’, ‘xxxxxxxxxxxxxxxxxxx’ );
    save the file
  • Save that site key somewhere safe for future use
  • Now you have a site key

Get cURL
sudo apt-get install curl

Test cURL by finding the definition of ‘bash’
curl dict://dict.org/d:bash

The key php file I need is for uploading csv text file data transferring from another system to civiCASE.

I found the basic import/export/delete php files in:
/var/www/drupal/sites/all/modules/contrib/civicrm/bin/csv

/**
* Import records from a csv file passed as an argument.
*
* Usage:
* php bin/csv/import.php -e <entity> –file /path/to/csv/file [ -s site.org ]
* e.g.: php bin/csv/import.php -e Contact –file /tmp/import.csv
*
**/

From http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API

The API explorer, which is available at http://[CIVICRM_URL]/civicrm/api/explorer (or http://[CIVICRM_URL]/?q=civicrm/api/explorer if you do not use clean URLs in Drupal). This gives you the possibility to actually try out the API in action.

http://localhost/?q=civicrm/api/explorer

The API parameter list, which shows all available entities which can be manipulated by the API and is available at http://[CIVICRM_URL]/civicrm/api/doc (or http://[CIVICRM_URL]/?q=civicrm/api/doc if you do not use clean URLs in Drupal)

http://localhost/?q=civicrm/api/doc

 

Api examples: https://github.com/civicrm/civicrm-core/tree/master/api/v3/examples
This included an example for creating a case with php.

Some handy examples:
http://www.thegeekstuff.com/2012/04/curl-examples/
An example from civiCRM
http://wiki.civicrm.org/confluence/display/CRMDOC40/Update+Greetings+and+Address+Data+for+Contacts
And the civiCRM command-line reference page
http://wiki.civicrm.org/confluence/display/CRMDOC40/Command-line+Script+Configuration

Comments are closed.