Hot answers tagged

18 votes

Get current contact id?

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

How do I set up an API key for a user?

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 ...
  • 6,671
16 votes
Accepted

How do I get more than 25 records from the API?

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( ...
16 votes
Accepted

What is the join logic when using API chaining with action = get?

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 ...
  • 16.3k
12 votes

How do I import contacts through the command line?

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/...
12 votes
Accepted

How to permanently delete contact with API?

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....
  • 3,688
10 votes
Accepted

Where is the CiviCRM ERD / data-dictionary?

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 ...
10 votes
Accepted

Get or generate a contact checksum via API?

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); ...
  • 2,455
9 votes
Accepted

Get current contact id?

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'];
  • 16.3k
9 votes

Get or generate a contact checksum via API?

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 ...
  • 7,367
8 votes

What is the correct way to work with custom data in the API?

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 ...
  • 16.3k
8 votes

What's the best way to import memberships and their associated contributions?

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 ...
8 votes
Accepted

How is the restful API secured?

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 ...
8 votes

How is the restful API secured?

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

How do I get more than 25 records from the API?

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);...
8 votes

REST API: Unable to decode supplied JSON

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 ...
  • 10.1k
8 votes
Accepted

CiviCRM integration with Eventbrite

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 ...
8 votes
Accepted

How do I add a contact to a group using the API?

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 = ...
8 votes

Where is the API key?

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 ...
7 votes

Incoporating PCPs in Wordpress

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 ...
7 votes

Get current contact id?

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 ...
  • 2,345
7 votes
Accepted

Can I chain API calls through drush?

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 ...
  • 1,012
7 votes

passing JSON objects to drush cvapi

Here is how to pass an array to drush echo '{"retrieval_parameters":{"jobId":97727336,"filePath":"Raw Recipient Data Export May 15 2017 22-07-43 PM 674.zip"}}' | drush cvapi Omnirecipients.get --in=...
  • 1,021
7 votes

I need to find the Host URL, Site key and API key

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, ...
  • 3,148
6 votes
Accepted

Can I use multiple values in an api Get call?

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, ...
  • 2,455
6 votes

Is there a CiviCRM hook or other method which can be used to push data updates to other systems?

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 ...
6 votes

How do I get more than 25 records from the API?

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, '...
6 votes
Accepted

Add Donations to Event Registration Form

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 ...
6 votes

REST API without JSON just key=value

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 ...
  • 16.3k
6 votes
Accepted

How to get all the groups for a contact

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 ...

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