2

I have a need to create programmatically (from a csv) a complete ACL structure. In detail for each csv line i need to create

  1. the CMS user (Joomla) with a specific role
  2. the connected contact
  3. the connected group
  4. all the 3 ACL record (ACL, Roles and User assignments)

I'm using CiviCRM 4.7.24 and Joomla, I'm thiking to utilize API.

Questions:

  • is the API the right approach or it's better to write directtly into DB?

  • which APIs to use for each of the archives above?

Thank's

3

Yes, the API is definitely the correct approach. Writing via SQL may work for now, but isn't guaranteed to in the future.

For the first item (creating the Joomla) user, I can't offer help, since that's not CiviCRM. There are plenty of pages that indicate how to create a Joomla user programmatically.

Don't forget about the API Explorer (Support menu » Developer » API Explorer) to help with determining how to implement your solution.

Also consider the CSV API Import tool, which may provide a no-coding (or low-coding alternative.

Create the contact (step 2) with the "Contact" API. Connect it to the group (step 3) with the "GroupContact" API. Use the "Group" API if the groups don't currently exist.

Step 4 needs the OptionValue API to create the role (set "Option Group ID" to acl_role). Use the Acl and AclRole API to set the rest.

  • This answer looks right and I think you might need some separate code to create the joomla roles, or that it might be sensible to have that code separate, especially if your CiviCRM API calls are in your extension's install hook. – artfulrobot Oct 18 '17 at 6:48
  • There is also the API Import extension which Fuzion did - github.com/eileenmcnaughton/nz.co.fuzion.csvimport – petednz - fuzion Oct 18 '17 at 18:02
  • Note - i am not familiar with Xavier's extension so can't comment on the difference - perhaps that question should be a separate item ;-) – petednz - fuzion Oct 18 '17 at 18:03
  • 1
    @petednz-fuzion Xavier's work isn't an extension, it's built into core. The difference is that Xavier's is CLI-based, and Fuzion's is GUI-based. Because marcello wants programmatic import, I suggested the CLI-based version. – Jon G - Megaphone Tech Oct 18 '17 at 18:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.