Hot answers tagged

17

Hopefully a new release will be made for the API Key extension soon. Here are detailed instructions for creating one manually without needing to get access to your database through phpMyAdmin, mysql on the command line or some similar MySQL database administration tool. Usually it is a good idea to create a special separate contact for each service that ...


16

To return more than 25 results you need to add options.limit to your api call: $params = array( 'version' => 3, 'sequential' => 1, 'membership_type' => 1, 'options' => array( 'limit' => 100, ), ); $result = civicrm_api('Membership', 'get', $params); For the second part, we want to be able to retrieve say 5,000 records. We ...


16

Chaining will attempt to "guess" at the id of the chained entity. In your first example, the fetched participant record has an "event_id" and the api chaining controller passes that into the chained Event api call as the id. The guessing is pretty basic though. For everything else, you should specify params explicitly. You do so by using the magic "$value" ...


15

The answer davejenx is correct but no longer considered best practice. Instead use: CRM_Core_Session::singleton()->getLoggedInContactID();


12

You can pass the skip_undelete parameter to the API, ie. $result = civicrm_api3('Contact', 'delete', array( 'sequential' => 1, 'id' => 9999999999999999999, // replace with your contact's Id. 'skip_undelete' => 1, )); Obviously a lot of care has to be taken over specifying the id to delete...


11

When you are importing a large number of contacts, you could face timeout issues when using the user interface. Importing through CLI is an alternative. There is a file called import.php in /civicrm/civicrm/bin/csv/import.php. We will call this file from the command line. After you have exported your CSV file, here are the steps for the import: Put the ...


10

You should use the API as the data dictionary. The API explorer (available in every installation) provides a convenient interface to browse the data dictionary. The demo sites each have an API explorer and they are the authoritative public data dictionary for CiviCRM. For example http://dmaster.demo.civicrm.org/civicrm/api/explorer (login first with ...


10

I have never seen the checksum available in the API. I have successfully obtained it programmatically though with code similar to: $cs = CRM_Contact_BAO_Contact_Utils::generateChecksum($contact_id); (This snippet is adapted from core code in CRM/Utils/Token.php)


9

If you are on the contact summary screen, then the contact id is always $_GET['cid']. To give yourself peace-of-mind about using raw input, cast it to an integer. $contactId = (int) $_GET['cid'];


9

I'm pretty certain you can't get a checksum from the standard API. However, you should write (or commission) an extension to provide a checksum API. The API would basically be a wrapper around the code that DaveD suggested, and you can read documentation here on how to use Civix to generate an API in your extension.


8

As of CiviCRM 4.6, the api explorer is like 1-stop-shopping for browsing, building and testing api calls. You can start on the "Examples" tab to see how custom values are generally done: If you want more detailed explanation of how it works, try the "Code Docs" tab: And finally, the Explorer tab lets you browse available params and will write the php/...


8

This is doable using the API, and I've accomplished it using Pentaho Kettle. It has a CiviCRM Input and CiviCRM Output step, which use the REST API. You're right to be concerned about the SQL-based approach, since there's been discussion of deprecating that table in favor of a line item-based approach to connecting contributions and memberships. If you ...


8

Whether or not https is used would be dependent on the CMS, but this is certainly recommended. Other than making sure the Access AJAX Api permission is set up for a particular CMS user, you will also need to pass a user api key that is assigned to the CiviCRM contact record associated with that CMS user. Details at: http://wiki.civicrm.org/confluence/...


8

The REST API requires that you specify the site key and an API key. Details can be found here.


8

I would recommend you to use post instead of get to communicate with the rest api, both because it would allow you to avoid having the keys "in clear" in the get url (and therefore written in the log an so on), but also because you don't have to deal with url encoding of the parameters. btw, you don't have to put the param in the json most of the time, so ...


8

You will need to create extension to have Eventbrite sync with CiviEvents. Here is some guideline on how to approach this Create extension. Add page using civix In run() use CiviCRM api to create entries in civicrm table. Reference : Mandrill extension uses same approach i.e to create entries in various civicrm table upon webhook call. This might find ...


8

Open API Explorer - Support menu > Developer > API Explorer and use GroupContact API to add contacts to group. See an eg in the screenshot below - API formed for PHP is - $result = civicrm_api3('GroupContact', 'create', [ 'group_id' => <group_id>, 'contact_id' => <contact id>, ]);


7

Well here's an alternate way to try which returns the total result if you have no idea how much entries does the returned result will contain : $count = civicrm_api('Membership', 'getcount', $params); $params = array( 'version' => 3, 'sequential' => 1, 'membership_type' => 1, 'options' => array( 'limit' => $count, ), ); $...


7

PCPs don't have an API currently - but I just wrote one in about 15 minutes. I didn't write unit tests, so I can't submit it upstream - maybe this is something you can help with to make CiviCRM better? Paste the contents of this file into "Pcp.php" in your civicrm/api/v3 folder: http://pastebin.com/cvzqfq69 There's some odd line of hyphens at the bottom, ...


7

Edit: The techniques below get the logged-in user's contact id. However the questioner has clarified that this isn't what they meant by "the current contact id". I'll leave this answer in place in case it's useful to someone else who misunderstood the question. Here's a simple way: CRM_Core_Session::singleton()->getLoggedInContactID(); The above (for ...


7

Drush can read parameters from standard input in JSON format if you supply the argument --in=json. This is what we need for API chaining, because chaining uses nested parameters, and in contrast to a flat list of command line arguments (the default way to pass parameters to drush cvapi, JSON can handle nesting. So to retrieve the email addresses for contact ...


7

Host URL Depending on the context of your situation, this is probably referring to the domain name of the site where you use CiviCRM. So if you see https://example.org/civicrm when using CiviCRM, then the host URL is example.org Site key This is one value, used globally for your CiviCRM installation and stored in the civicrm.settings.php file on your ...


7

You can find the site key information you need in the System Administrator Guide: https://docs.civicrm.org/sysadmin/en/latest/setup/site-key/ The API key is in the database and needs to be set up for a contact that has access. You can install the API Key extension which will enable the API Key in the contact summary if you have admin rights: https://civicrm....


6

Yes, I just used the new API explorer in 4.6 and got a sample PHP call: $result = civicrm_api3('Contribution', 'get', array( 'sequential' => 1, 'contact_id' => array('IN' => array(58, 25)), ));


6

In having to do this with Salesforce and CiviCRM a number operations included the creation of a new contact being initiated on one end, which then had to be replicated on the other. In this case we wanted to prevent both sending unnecessary data and creating duplicate contacts. Whenever the data being synced didn't involve a chain of transactions that ...


6

Adding options.limit to 0 returns the total result for the api which I feel is the best way to get more than 25 contacts :) $params = array( 'version' => 3, 'sequential' => 1, 'membership_type' => 1, 'options' => array( 'limit' => 0, ), ); $result = civicrm_api('Membership', 'get', $params);


6

Simply set up an additional line item for a donation in a Price Set. This is how I do it... the Price Set definition: And then how the 'Optional Donation' is defined: And a preview of this in action: Feel free to give it a whirl on my website - and make a donation if you like it! :-) http://www.breinton.com/book/hipp-abbate


6

Yes, you do not need the params to be formatted as json, since they are all simple strings/numbers you can just place them in the url like subject=test&target_id=1529697 etc. If you want your results back in json format, add &json=1 otherwise leave it off to get xml back.


6

To get the Groups, you can use the GroupContact API $result = civicrm_api3('GroupContact', 'get', array( 'sequential' => 1, 'contact_id' => <contact_id>, )); To get all the smart groups to which the contact belongs, you can use this BAO function defined in GroupContactCache.php $smartGroup = CRM_Contact_BAO_GroupContactCache::contactGroup($...


6

you can send via SMTP, so without any extension. However, you will not handle events about bounces, so civicrm will not be able to update the contact to flag that the email is invalid. So you will keep sending emails to the same invalid email, how mandrill will handle that (eg blacklist these emails, invoicing them as sent... up to ban you) is based on how ...


Only top voted, non community-wiki answers of a minimum length are eligible