Hot answers tagged

20 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 ...
Joe Murray's user avatar
  • 6,731
18 votes

Get current contact id?

The answer davejenx is correct but no longer considered best practice. Instead use: CRM_Core_Session::singleton()->getLoggedInContactID();
Jon G - Megaphone Tech's user avatar
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 ...
Coleman's user avatar
  • 16.9k
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/...
Borislav Zlatanov's user avatar
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....
artfulrobot's user avatar
  • 3,870
11 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); ...
DaveD's user avatar
  • 2,465
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 ...
Andie Hunt's user avatar
  • 7,422
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);...
jitendra - fuzion's user avatar
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 ...
Xavier's user avatar
  • 10.2k
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 ...
Pradeep Nayak - Circle Int.'s user avatar
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 = ...
jitendra - fuzion's user avatar
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 ...
ErikH - CiviCooP's user avatar
7 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 ...
Lionel Smith-Gordon's user avatar
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 ...
Noah Miller's user avatar
  • 1,057
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=...
user4278's user avatar
  • 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, ...
Sean's user avatar
  • 3,158
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, '...
jitendra - fuzion's user avatar
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 ...
Coleman's user avatar
  • 16.9k
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 ...
jitendra - fuzion's user avatar
6 votes

Mandrill on CiviCRM - SMTP or API?

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 ...
Xavier's user avatar
  • 10.2k
6 votes
Accepted

Limit is ignored in civicrm_api3('Membership', 'get')

You need to use options.limit to make this work. options.limit : The maximum number of records to return. You can make this unlimited by setting the value to 0. Usage $result = civicrm_api3('...
jitendra - fuzion's user avatar
6 votes
Accepted

CiviCRM Ajax API - Searching by Tag

you are almost there: instead of using the tag name, use the tag id (eg 5 for Volunteers) CRM.api3('Contact', 'get', { "debug": 1, "sequential": 1, "return": ["tag"], "tag": "5" }).done(...
Xavier's user avatar
  • 10.2k
6 votes
Accepted

Civix reports "Failed to locate civicrm.settings.php"

The generate:api subcommand (and a few others) require access to a working copy of CiviCRM. To locate this, it uses a process reminiscent of drush or wp-cli. For example, if the command-line is ...
Tim Otten's user avatar
  • 5,619
6 votes
Accepted

Silent error when accessing php API has not logged in user

The recommended way to include the necessary files to run the php API is to call civicrm_initialize() before the API call.
Bryan D.'s user avatar
  • 126
6 votes
Accepted

REST API 'between' parameters

I just figured it out: &received_date[BETWEEN][]=2017-12-01&received_date[BETWEEN][]=2017-12-02
Troy's user avatar
  • 241
6 votes
Accepted

Upload a contact image via the API

Contact Image URL is directly stored in civicrm_contact table, so I think if you have the URL which can display an image, you should be directly able to use the contact create API as below - $result =...
jitendra - fuzion's user avatar
5 votes
Accepted

Update contact via REST and JSON request body

Please, do not put the api_key nor key into the get parameter, to they don't end up in logs and other places, they are better as a post param. As for your question, you can have json="{'id':2..."} as ...
Xavier's user avatar
  • 10.2k
5 votes

Get or generate a contact checksum via API?

I needed this exact functionality, so I wrote the extension that provides it, com.megaphonetech.checksums. I used Coleman's comment above as my spec :)
Jon G - Megaphone Tech's user avatar
5 votes

How to delete a contact through the command line (CLI)

If you're on Drupal and have drush installed you can do drush cvapi Contact.delete id=17 skip_undelete=1
DaveFF's user avatar
  • 1,517
5 votes

Find Contacts with no Relationships

One way of achieving your goal would be via a temporary group: Using advanced search, search for all contacts who do have a relationship (simply open the "Relationships" tab, enter nothing, and ...
Coleman's user avatar
  • 16.9k

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