{"id":45069,"date":"2020-02-18T15:10:50","date_gmt":"2020-02-18T14:10:50","guid":{"rendered":"https:\/\/churchtools.academy\/help\/non-knowledgebase\/uncategorized\/api-alt\/"},"modified":"2026-03-17T09:24:25","modified_gmt":"2026-03-17T08:24:25","password":"","slug":"api-alt","status":"publish","type":"docs","link":"https:\/\/churchtools.academy\/en\/help\/system-settings\/api-en\/api-alt\/","title":{"rendered":"API-Alt"},"content":{"rendered":"\n<aside class=\"wp-block-group ct-box ct-box-blue has-text-color has-background has-link-color wp-elements-74648fa9a9506de5179716347194bc98 is-vertical is-layout-flex wp-container-core-group-is-layout-002f1c27 wp-block-group-is-layout-flex\" style=\"border-radius:8px;border-left-color:#e7c000;border-left-width:0.5rem;color:#3f3400;background-color:#ffe5644d;margin-top:var(--wp--preset--spacing--60);margin-bottom:var(--wp--preset--spacing--60)\">\n<p style=\"margin-top:0.5rem;margin-right:0.5rem;margin-bottom:0rem;margin-left:0.5rem\"><strong>Important<\/strong><\/p>\n\n\n\n<p style=\"margin-top:0rem;margin-right:0.5rem;margin-bottom:0.5rem;margin-left:0.5rem\">This page describes the old AJAX API in ChurchTools. Information about the new RESTful API can be found on the <a href=\"https:\/\/churchtools.academy\/en\/help\/system-settings\/api-en\/overview-api\/\" data-type=\"link\" data-id=\"https:\/\/churchtools.academy\/help\/system-einstellungen\/api\/0-api\/\">API<\/a> page. <\/p>\n<\/aside>\n\n\n\n<h2 class=\"wp-block-heading\">How the API works<\/h2>\n\n\n\n<p>Since ChurchTools controls all communication via AJAX, every function can also be called via API.<\/p>\n\n\n\n<p>For example <a href=\"https:\/\/xxx.churchtools.de\/index.php?q=churchresource\/ajax\">https:\/\/xxx.church.tools\/index.php?q=churchresource\/ajax<\/a><\/p>\n\n\n\n<p>And then via POST:<em> func=getBookings<\/em> (returns all<em> bookings<\/em> ) or e.g. <em>func=getMasterData <\/em>returns all necessary master data.<\/p>\n\n\n\n<p>It is important that the call is sent via POST command and that the desired function is contained in the parameter &#8220;func=functioname&#8221;. There are different calls per module. This can be looked up under system\/modulename\/classes\/CTModulename.class.php.   <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Further examples of API calls<\/h2>\n\n\n\n<p>For example, Login via<\/p>\n\n\n\n<p><a href=\"https:\/\/xxx.churchtools.de\/?q=login\"><code>https:\/\/xxx.church.tools\/?q=login<\/code><\/a><\/p>\n\n\n\n<p>Then POST the parameters:<\/p>\n\n\n\n<p>email<\/p>\n\n\n\n<p>password<\/p>\n\n\n\n<p>directtool=yes<\/p>\n\n\n\n<p><strong>Query from all persons<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/xxx.churchtools.de\/?q=churchdb\/ajax&amp;func=getAllPersonData\"><code>https:\/\/xxx.church.tools\/?q=churchdb\/ajax&amp;func=getAllPersonData<\/code><\/a><\/p>\n\n\n\n<p><strong>Query a person<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/xxx.churchtools.de\/?q=churchdb\/ajax&amp;func=getPersonDetails&amp;id=736\"><code>https:\/\/xxx.church.tools\/?q=churchdb\/ajax&amp;func=getPersonDetails&amp;id=736<\/code><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Example of an API call in PHP<\/h2>\n\n\n\n<p><code>&lt;?php <\/code><br><code>\/** * Example API call to ChurchTools Installation for PHP. The cookies will be stored to current directory <\/code><br><code>* Author: Jens Martin Rauen <\/code><br><code>* Copyright: 2015 <\/code><br><code>**\/ <\/code><\/p>\n\n\n\n<p><code>\/**  <\/code><br><code>* Get saved Cookies from filesystem and returns an array  <\/code><br><code>* @return array of Cookies in string  <\/code><br><code>*\/ <\/code><br><code>function getCookies() {<\/code><br><code>   $aCookies = glob(\"*.txt\");<\/code><br><code>   $n = count($aCookies);<\/code><br><code>   if ($n !== 0) {<\/code><br><code>    $counter = 0;<\/code><\/p>\n\n\n\n<p><code>   while ($counter &lt; $n) {<\/code><br><code>     $sCombined .= file_get_contents($aCookies[\"$counter\"]) . ';';<\/code><br><code>     ++$counter;<\/code><br><code>    }<\/code><br><code>    return $sCombined;<\/code><br><code>   } else {<\/code><br><code>    return $n;<\/code><br><code>   }<\/code><br><code>} <\/code><\/p>\n\n\n\n<p><code>\/**<\/code> <br><code> * Save cookies from $aRH (http response header) to the filesystem <\/code><br><code> * @param $aRH <\/code><br><code> *\/ <\/code><br><code>function saveCookies($aRH) {<\/code><br><code>   $n = count($aRH); \/\/ Number of Pieces<\/code><br><code>   $counter = 0;<\/code><br><code>   while ($counter &lt;= $n) {<\/code><br><code>     if(preg_match('@Set-Cookie: (([^=]+)=[^;]+)@i', $aRH[\"$counter\"], $matches)) {<\/code><br><code>       $fp = fopen($matches[\"2\"].'.txt', 'w');<\/code><br><code>        fwrite($fp, $matches[\"1\"]);<\/code><br><code>       fclose($fp);<\/code><br><code>     }<\/code><br><code>     ++$counter;<\/code><br><code>   }<\/code> <br><code>} <\/code><\/p>\n\n\n\n<p><code>\/** <\/code><br> <code>* Send request to $url with $data <\/code><br><code> * @param [type] $url  [description] <\/code><br><code> * @param [type] $data [description] <\/code><br><code> *\/ <\/code><br><code>function sendRequest($url, $data) {<\/code><br><code>   $options1 = array(<\/code><br><code>     'http' =&gt; array(<\/code><br><code>       'header'  =&gt; \"Cookie: \".getCookies() . \"rnContent-type: application\/x-www-form-urlencodedrn\",<\/code><br><code>       'method'  =&gt; 'POST',<\/code><br><code>       'content' =&gt; http_build_query($data),<\/code><br><code>     ),<\/code><br><code>   );<\/code><br><code>   $context  = stream_context_create($options1);<\/code><br><code>   $result = file_get_contents($url, false, $context);<\/code><br><code>   print_r($result);<\/code><br><code>   saveCookies($http_response_header); <\/code><br><code>} <\/code><\/p>\n\n\n\n<p><code>\/\/ Login to mghh churchtools <\/code><br><code>$url = 'https:\/\/mghh.churchtools.de\/?q=login'; <\/code><br><code>$data = array('email' =&gt; 'sabine@mghh.churchtools.de', 'password' =&gt; '1234', <\/code><br><code>'directtool' =&gt; 'yes'); <\/code><br><code>sendRequest($url, $data); <\/code><\/p>\n\n\n\n<p><code>\/\/ Now get all Person data <\/code><br><code>$url = 'https:\/\/mghh.churchtools.de\/index.php?q=churchdb\/ajax'; <\/code><br><code>$data = array('func' =&gt; 'getAllPersonData'); <\/code><br><code>sendRequest($url, $data);<\/code><\/p>\n\n\n\n<aside class=\"wp-block-group ct-artikel-zum-weiterlesen has-background is-layout-constrained wp-container-core-group-is-layout-89fd719a wp-block-group-is-layout-constrained\" style=\"border-radius:8px;background-color:#f9fafb;margin-top:24px;margin-bottom:24px;padding-top:32px;padding-right:24px;padding-bottom:32px;padding-left:24px\">\n<h2 class=\"wp-block-heading has-medium-font-size\">Read more<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/churchtools.academy\/en\/help\/system-settings\/api\/overview-api\/\" data-type=\"docs\" data-id=\"7251\">Overview API<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/churchtools.academy\/de\/help\/system-einstellungen\/api\/0-api-authentifizierung\/\" data-type=\"docs\" data-id=\"7252\">API authentication<\/a><\/li>\n<\/ul>\n<\/aside>\n","protected":false},"excerpt":{"rendered":"<p>How the API works Since ChurchTools controls all communication via AJAX, every function can also be called via API. For example https:\/\/xxx.church.tools\/index.php?q=churchresource\/ajax And then via POST: func=getBookings (returns all bookings ) or e.g. func=getMasterData returns all necessary master data. It is important that the call is sent via POST command and that the desired function [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_acf_changed":false,"footnotes":""},"doc_category":[461],"doc_tag":[653],"knowledge_base":[425],"class_list":["post-45069","docs","type-docs","status-publish","hentry","doc_category-api-en","doc_tag-content-outdated-en","knowledge_base-system-settings"],"pp_statuses_selecting_workflow":false,"pp_workflow_action":"current","pp_status_selection":"publish","acf":[],"year_month":"2026-04","word_count":379,"total_views":"425","reactions":{"happy":"0","normal":"0","sad":"0"},"author_info":{"name":"Hans-Helge B\u00fcrger","author_nicename":"hhbuerger","author_url":"https:\/\/churchtools.academy\/en\/author\/hhbuerger\/"},"doc_category_info":[{"term_name":"API","term_url":"https:\/\/churchtools.academy\/en\/help\/system-settings\/api-en\/"}],"doc_tag_info":[{"term_name":"Content outdated","term_url":"https:\/\/churchtools.academy\/en\/docs-tag\/content-outdated-en\/"}],"knowledge_base_info":[{"term_name":"System Settings","term_url":"https:\/\/churchtools.academy\/en\/help\/system-settings\/","term_slug":"system-settings"}],"knowledge_base_slug":["system-settings"],"_links":{"self":[{"href":"https:\/\/churchtools.academy\/en\/wp-json\/wp\/v2\/docs\/45069","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/churchtools.academy\/en\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/churchtools.academy\/en\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/churchtools.academy\/en\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/churchtools.academy\/en\/wp-json\/wp\/v2\/comments?post=45069"}],"version-history":[{"count":6,"href":"https:\/\/churchtools.academy\/en\/wp-json\/wp\/v2\/docs\/45069\/revisions"}],"predecessor-version":[{"id":50069,"href":"https:\/\/churchtools.academy\/en\/wp-json\/wp\/v2\/docs\/45069\/revisions\/50069"}],"wp:attachment":[{"href":"https:\/\/churchtools.academy\/en\/wp-json\/wp\/v2\/media?parent=45069"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/churchtools.academy\/en\/wp-json\/wp\/v2\/doc_category?post=45069"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/churchtools.academy\/en\/wp-json\/wp\/v2\/doc_tag?post=45069"},{"taxonomy":"knowledge_base","embeddable":true,"href":"https:\/\/churchtools.academy\/en\/wp-json\/wp\/v2\/knowledge_base?post=45069"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}