{"id":1029,"date":"2014-12-18T16:48:41","date_gmt":"2014-12-19T00:48:41","guid":{"rendered":"http:\/\/systemsolver.com\/StatlerBlog\/?p=1029"},"modified":"2014-12-18T16:48:41","modified_gmt":"2014-12-19T00:48:41","slug":"civicase-running-php-from-command-line-with-curl","status":"publish","type":"post","link":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/2014\/12\/18\/civicase-running-php-from-command-line-with-curl\/","title":{"rendered":"civiCASE apis and running php from command line"},"content":{"rendered":"<p>Open terminal as super user [su]<\/p>\n<p>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 &#8211;output\u00a0 &#8211;contact_id=2<\/p>\n<p>or, if already in the civicrm\/bin directory:<br \/>\ncd \/var\/www\/drupal\/sites\/all\/modules\/contrib\/civicrm\/bin\/<br \/>\nphp cli.php -e ..\/bin\/csv\/export.php contact -e contact -a get &#8211;output &#8211;contact_id=2<\/p>\n<p>===================<\/p>\n<p>following are notes that got me to this<\/p>\n<p>===========<\/p>\n<p>To run php code on a web site like civiCRM use the cURL program on linux.<\/p>\n<p>First, civiCRM needs a site key.<\/p>\n<ul>\n<li>Run the following in a command prompt<br \/>\nphp -r &#8216;echo md5(uniqid(rand(), true)) . &#8220;\\n&#8221;;&#8217;<br \/>\nhighlight the result and right-click copy<\/li>\n<li>Navigate to, as administrator,<br \/>\n\/var\/www\/drupal\/sites\/default<br \/>\nopen civicrm.settings.php<br \/>\nsearch for <code class=\"java string\">CIVICRM_SITE_KEY<\/code><br \/>\nPaste the result you copied into the appropriate place, as indicated by xxx&#8217;s below<br \/>\ndefine( &#8216;CIVICRM_SITE_KEY&#8217;, &#8216;xxxxxxxxxxxxxxxxxxx&#8217; );<br \/>\nsave the file<\/li>\n<li>Save that site key somewhere safe for future use<\/li>\n<li>Now you have a site key<\/li>\n<\/ul>\n<p>Get cURL<br \/>\nsudo apt-get install curl<\/p>\n<p>Test cURL by finding the definition of &#8216;bash&#8217;<br \/>\ncurl dict:\/\/dict.org\/d:bash<\/p>\n<p>The key php file I need is for uploading csv text file data transferring from another system to civiCASE.<\/p>\n<p>I found the basic import\/export\/delete php files in:<br \/>\n\/var\/www\/drupal\/sites\/all\/modules\/contrib\/civicrm\/bin\/csv<\/p>\n<p style=\"padding-left: 30px;\">\/**<br \/>\n* Import records from a csv file passed as an argument.<br \/>\n*<br \/>\n* Usage:<br \/>\n* php bin\/csv\/import.php -e &lt;entity&gt; &#8211;file \/path\/to\/csv\/file [ -s site.org ]<br \/>\n* e.g.: php bin\/csv\/import.php -e Contact &#8211;file \/tmp\/import.csv<br \/>\n*<br \/>\n**\/<\/p>\n<p>From <a href=\"http:\/\/wiki.civicrm.org\/confluence\/display\/CRMDOC\/Using+the+API\">http:\/\/wiki.civicrm.org\/confluence\/display\/CRMDOC\/Using+the+API<\/a><\/p>\n<p style=\"padding-left: 30px;\">The <strong>API explorer<\/strong>, which is available at\u00a0<a rel=\"nofollow\">http:\/\/[CIVICRM_URL]\/civicrm\/api\/explorer<\/a> (or <a rel=\"nofollow\">http:\/\/[CIVICRM_URL]\/?q=civicrm\/api\/explorer<\/a> if you do not use clean URLs in Drupal). This gives you the possibility to actually try out the API in action.<\/p>\n<p><a href=\"http:\/\/localhost\/?q=civicrm\/api\/explorer\">http:\/\/localhost\/?q=civicrm\/api\/explorer<\/a><\/p>\n<p style=\"padding-left: 30px;\">The<strong> API parameter list<\/strong>, which shows all available entities which can be manipulated by the API and is available at\u00a0<a rel=\"nofollow\">http:\/\/[CIVICRM_URL]\/civicrm\/api\/doc<\/a> (or <a rel=\"nofollow\">http:\/\/[CIVICRM_URL]\/?q=civicrm\/api\/doc<\/a> if you do not use clean URLs in Drupal)<\/p>\n<p><a href=\"http:\/\/localhost\/?q=civicrm\/api\/doc\">http:\/\/localhost\/?q=civicrm\/api\/doc<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Api examples: <a href=\"https:\/\/github.com\/civicrm\/civicrm-core\/tree\/master\/api\/v3\/examples\">https:\/\/github.com\/civicrm\/civicrm-core\/tree\/master\/api\/v3\/examples<\/a><br \/>\nThis included an example for creating a case with php.<\/p>\n<p>Some handy examples:<br \/>\n<a href=\"http:\/\/www.thegeekstuff.com\/2012\/04\/curl-examples\/\">http:\/\/www.thegeekstuff.com\/2012\/04\/curl-examples\/<br \/>\n<\/a>An example from civiCRM<br \/>\n<a href=\"http:\/\/wiki.civicrm.org\/confluence\/display\/CRMDOC40\/Update+Greetings+and+Address+Data+for+Contacts\">http:\/\/wiki.civicrm.org\/confluence\/display\/CRMDOC40\/Update+Greetings+and+Address+Data+for+Contacts<\/a><br \/>\nAnd the civiCRM command-line reference page<br \/>\n<a href=\"http:\/\/wiki.civicrm.org\/confluence\/display\/CRMDOC40\/Command-line+Script+Configuration\">http:\/\/wiki.civicrm.org\/confluence\/display\/CRMDOC40\/Command-line+Script+Configuration<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &#8211;output\u00a0 &#8211;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 &#8211;output &#8211;contact_id=2 =================== following are notes that got me to this =========== To run php code on a web site [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,4,6],"tags":[],"class_list":["post-1029","post","type-post","status-publish","format-standard","hentry","category-civicrm","category-general","category-linux"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/posts\/1029","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/comments?post=1029"}],"version-history":[{"count":0,"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/posts\/1029\/revisions"}],"wp:attachment":[{"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/media?parent=1029"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/categories?post=1029"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/systemsolver.goodhealthyday.com\/StatlerBlog\/wp-json\/wp\/v2\/tags?post=1029"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}