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,741
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
  • 18.6k
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'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

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,168
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,684
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

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
Accepted

Uploading files through the API

Yes, it did happen and it's called the "attachment" api. You can look up the docs for it in the api explorer:
Coleman's user avatar
  • 18.6k
5 votes

Is it possible to integrate a custom Drupal donate form with CiviCRM?

So this is definitely possible. I'm assuming that you asking the question, you have some Drupal FAPI experience. If you have CiviCRM installed already check out the API explorer, and check out the ...
jackrabbithanna's user avatar
5 votes

How to control API4 permissions for CRUD operations?

Events The API kernel broadcasts an authorise event. Core permission check listener The main API permission check subscriber will respond to the event by: $apiRequest = $event->getApiRequest(); ...
ErichBSchulz's user avatar
  • 1,571
5 votes
Accepted

How to add email while trying to create a Household contact using civicrm api v3?

You will have to use the Email API with the contact_id of the just created contact. You can do this in a chained API call if you want to.
ErikH - CiviCooP's user avatar
5 votes
Accepted

How to sort in descending order the results of CiviCRM API

sort option takes the parameter followed by sort_order in civicrm api. For eg - the following works fine -
jitendra - fuzion's user avatar
5 votes

CiviCRM API Implementation

Welcome to CiviCRM SE! The first place to look for this information is in the relevant section of the developers guide at https://docs.civicrm.org/dev/en/latest/api/
Mick Kahn's user avatar
  • 3,227
4 votes

How can I 'or' 2 conditions using the api?

With API4 you can do it like this: $contacts = \Civi\Api4\Contact::get() ->addClause('OR', ['birth_date', '<=', '1960-01-01'], ['birth_date', 'IS NULL'] ) ->execute(); ...
artfulrobot's user avatar
  • 3,930
4 votes

API: How do I delete a custom value?

Currently, you can't do this. If you try, you will get the notice: API (CustomValue, delete) does not exist (join the API team and implement it!) This is true for CiviCRM version 4.7.7, which is ...
moopet's user avatar
  • 145
4 votes

How do I use the joins feature of the new API

The JIRA Issue for this feature https://issues.civicrm.org/jira/browse/CRM-17795 reads This adds support for joins in api.get operations to fetch information from more than one table. It ...
Allen Hutchison's user avatar
4 votes

API for update an address

@Zeno when you have create option you don't have to look for replace please use create key word to create new or to update the record if record exist $result = civicrm_api3('Address', 'create', ...
Ramesh - ARTECH Consultancy's user avatar
4 votes
Accepted

How to use the REST API with curl

I just created a working example for curl and tested it on linux. Do also URL encode the curly braces. I used the this website to do that. So {"contact_id":"358383"} becomes %7B%22contact_id%22%3A%...
Kainuk - CiviCooP's user avatar
4 votes
Accepted

How to set a default value for a custom field

Used to work, before CiviCRM v5.18 Here's how I've opted to do it. Please do submit alternative answers if there's a better way. Use the civicrm_post hook like this: Note that you need to replace N ...
artfulrobot's user avatar
  • 3,930
4 votes
Accepted

How do I get CiviCRM Mailing to submit via the API

Remove the force_rollback block. What is the result of the civicrm_api3 call?
Xavier's user avatar
  • 10.2k
4 votes
Accepted

The apiv3 does not return joined fields

Membership doesn't have a contact details(apart from id) in its API call. To get the address and display name, I think you need to call a chain API - $result = civicrm_api3('Membership', 'get', array(...
jitendra - fuzion's user avatar
4 votes
Accepted

CiviCRM REST API Call

As kainuk mentioned, you don't have the right syntax for the json field, i needs to be json= instead of json: http://www.mysite.com/wp-content/plugins/civicrm/civicrm/extern/rest.php?entity=Contact&...
Xavier's user avatar
  • 10.2k

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