Answers.Body: <p>Yes, the API is definitely the correct approach.  Writing via SQL may work for now, but isn't guaranteed to in the future.</p>
  
  <p>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.</p>
  
  <p>Don't forget about the API Explorer (<strong>Support menu » Developer » API Explorer</strong>) to help with determining how to implement your solution.</p>
  
  <p>Also consider the <a href="https://civicrm.org/blog/xavier/api_batch_tools" rel="nofollow noreferrer">CSV API Import</a> tool, which may provide a no-coding (or low-coding alternative.</p>
  
  <p>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.</p>
  
  <p>Step 4 needs the <code>OptionValue</code> API to create the role (set "Option Group ID" to <code>acl_role</code>).  Use the <code>Acl</code> and <code>AclRole</code> API to set the rest.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-18T06:48:02.967Z
Answers.Text: 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.
Answers.UserDisplayName: artfulrobot
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-18T18:02:16.687Z
Answers.Text: There is also the API Import extension which Fuzion did - https://github.com/eileenmcnaughton/nz.co.fuzion.csvimport
Answers.UserDisplayName: petednz - fuzion
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-18T18:03:13.040Z
Answers.Text: Note - i am not familiar with Xavier's extension so can't comment on the difference - perhaps that question should be a separate item ;-)
Answers.UserDisplayName: petednz - fuzion
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-18T18:16:11.450Z
Answers.Text: @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.
Answers.UserDisplayName: Jon G - Megaphone Tech
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-18T06:37:01.483Z
Answers.LastActivityDate: 2017-10-18T06:37:01.483Z
Answers.UserDisplayName: Jon G - Megaphone Tech
Body: <p>I have a need to create  programmatically (from a csv) a complete ACL structure.
  In detail for each csv line i need to create</p>
  
  <ol>
  <li>the CMS user (Joomla) with a specific role </li>
  <li>the connected contact</li>
  <li>the connected group</li>
  <li>all the 3 ACL record (ACL, Roles and User assignments)</li>
  </ol>
  
  <p>I'm using CiviCRM 4.7.24 and Joomla, I'm thiking to utilize API.</p>
  
  <p>Questions:</p>
  
  <ul>
  <li><p>is the API the right approach or it's better to write directtly into DB?</p></li>
  <li><p>which APIs to use for each of the archives above?</p></li>
  </ul>
  
  <p>Thank's</p>
  
Tags: <api><acl>
Title: Create programmatically a ACL logic
ThreadText: # Create programmatically a ACL logic
  
  (Asked by: username_0 on 2017-10-16)
  
  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
  
  **Tags:** api, acl
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-10-18. Score: 3 | Accepted answer
  
  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](https://civicrm.org/blog/xavier/api_batch_tools) 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.
  
  > **Comments:**
  > **username_2**: 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.  
  > **username_3**: There is also the API Import extension which Fuzion did - https://github.com/eileenmcnaughton/nz.co.fuzion.csvimport  
  > **username_3**: Note - i am not familiar with Xavier's extension so can't comment on the difference - perhaps that question should be a separate item ;-)  
  > **username_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 username_0 wants programmatic import, I suggested the CLI-based version.  
  
  ---
  
  