Answers.Body: <p>Based on Erik's help, this is how I've dealt with my need:</p>
  
  <ul>
  <li><p>When a new membership is manually checked and validated (for some legal issue), the team in charge of this task adds the member to a previously created dynamic group (sub group to membership called "validated membership")</p></li>
  <li><p>using CiviRules, the new "validated" member automatically receives an email with a personnalized body AND a .pdf as attachment generated from a template.</p></li>
  </ul>
  
  <h1>this is the civirule:</h1>
  
  <blockquote>
    <ul>
    <li>Linked Condition(s): Contact (not) in Group(s) In one of selected groups ("validated membership") </li>
    <li>Linked Action(s): Send PDF to e-mail address (printer or mailbox) "" with template "XXX" , template for e-mail body "YYY"</li>
    <li>No Delay</li>
    </ul>
  </blockquote>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-25T12:56:50.600Z
Answers.LastActivityDate: 2019-06-25T12:56:50.600Z
Answers.UserDisplayName: Guillaume Sorel
Answers.Body: <p>Do I gather correctly you want to do this in many cases? The easiest option would then be to use the CiviRules extension to send the PDF so you do not have to code.</p>
  
  <p>You could then set up something like <em>if a membership of a certain type is added, send the PDF</em>. That would make more sense to me then trying to add it to a template? I do not think that route will take you anywhere.</p>
  
  <p>You can find more information about the CiviRules extension here: <a href="https://docs.civicrm.org/civirules/en/latest/" rel="nofollow noreferrer">https://docs.civicrm.org/civirules/en/latest/</a></p>
  
  <p>If CiviRules can not help you you would probably have to write an extension but you need to explain more about what is required exactly at what time for me to be able to help you with that.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-25T12:13:03.517Z
Answers.Text: yes I want to do this in many case. I will have a look at CiviRules. This thing is that I want this document to be generated automatically but manually sent as a file (not as the body of an email) when the team in charge of memberships validates the sign-up. And this is not related to time. I set the journey of a constituent but the only variables are join in date / start date / end date. I've created "to be confirmed" status that lasts 1 month after effective start date of membership (i.e when the payment is done, mainly online) in order to let the team have enough time to check the document.
Answers.UserDisplayName: Guillaume Sorel
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-25T12:45:17.340Z
Answers.Text: CiviRules did the job! This is exactly what I was looking for. Thanks so much Erik!
Answers.UserDisplayName: Guillaume Sorel
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-25T17:52:15.557Z
Answers.Text: Good to hear @Guillaume!
Answers.UserDisplayName: ErikH - CiviCooP
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-06-24T08:55:48.080Z
Answers.LastActivityDate: 2019-06-24T08:55:48.080Z
Answers.UserDisplayName: ErikH - CiviCooP
Body: <p>(This post is following a previous question I asked and is related to ErikH's answer: <a href="https://civicrm.stackexchange.com/a/31142/6991">https://civicrm.stackexchange.com/a/31142/6991</a>)</p>
  
  <p>Context: I want to send per email an attached amended certificate (document ID #73). I tried the API explorer v3 and for one test user (id #54) it worked fine. Why an attached .pdf? Because it's an insurance certificate and it's important for each one of the 4000 members to have it personalized, that they can't modify it because of a legal issue and that they can print it easily. Once the membership is manually approved (it will always stay this way, again for legal issues), I want the team of volunteers to have the simple option to send it.</p>
  
  <p>I have 2 questions that are related to each other. I read the documentation but as far as I am not so familiar to code, I don't know exactly what to do.</p>
  
  <p>Question #1: is it possible to include some code in an existing template with general purpose within Civicrm? and which code? (and of course how?...)</p>
  
  <p>PHP?</p>
  
  <pre><code>    $result = civicrm_api3('Pdf', 'create', [
    'contact_id' =&gt; 54,
    'template_id' =&gt; 73,
  ]);
  </code></pre>
  
  <p>or JavaScript</p>
  
  <pre><code>    CRM.api3('Pdf', 'create', {
    "contact_id": 54,
    "template_id": 73
  }).then(function(result) {
    // do something with result
  }, function(error) {
    // oops
  });
  </code></pre>
  
  <p>Question #2: for this action, the API needs a contact ID and it's obvious it makes no sense to set it this way. Is there awy to use some fuzion fields instead like the civitoken {user.id}? I tried this way and the API explorer returns an error message. Is it possible or not?
  Thanks for any help.</p>
  
Tags: <api><pdf>
Title: How to use PDF API in production?
ThreadText: # How to use PDF API in production?
  
  (Asked by: username_0 on 2019-06-24)
  
  (This post is following a previous question I asked and is related to ErikH's answer: https://civicrm.stackexchange.com/a/31142/6991)
  Context: I want to send per email an attached amended certificate (document ID #73). I tried the API explorer v3 and for one test user (id #54) it worked fine. Why an attached .pdf? Because it's an insurance certificate and it's important for each one of the 4000 members to have it personalized, that they can't modify it because of a legal issue and that they can print it easily. Once the membership is manually approved (it will always stay this way, again for legal issues), I want the team of volunteers to have the simple option to send it.
  I have 2 questions that are related to each other. I read the documentation but as far as I am not so familiar to code, I don't know exactly what to do.
  Question #1: is it possible to include some code in an existing template with general purpose within Civicrm? and which code? (and of course how?...)
  PHP?
      $result = civicrm_api3('Pdf', 'create', [
    'contact_id' => 54,
    'template_id' => 73,
  ]);
  
  or JavaScript
      CRM.api3('Pdf', 'create', {
    "contact_id": 54,
    "template_id": 73
  }).then(function(result) {
    // do something with result
  }, function(error) {
    // oops
  });
  
  Question #2: for this action, the API needs a contact ID and it's obvious it makes no sense to set it this way. Is there awy to use some fuzion fields instead like the civitoken {user.id}? I tried this way and the API explorer returns an error message. Is it possible or not?
  Thanks for any help.
  
  **Tags:** api, pdf
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2019-06-24. Score: 4 | Accepted answer
  
  Do I gather correctly you want to do this in many cases? The easiest option would then be to use the CiviRules extension to send the PDF so you do not have to code.
  
  You could then set up something like *if a membership of a certain type is added, send the PDF*. That would make more sense to me then trying to add it to a template? I do not think that route will take you anywhere.
  
  You can find more information about the CiviRules extension here: <https://docs.civicrm.org/civirules/en/latest/>
  
  If CiviRules can not help you you would probably have to write an extension but you need to explain more about what is required exactly at what time for me to be able to help you with that.
  
  > **Comments:**
  > **username_0**: yes I want to do this in many case. I will have a look at CiviRules. This thing is that I want this document to be generated automatically but manually sent as a file (not as the body of an email) when the team in charge of memberships validates the sign-up. And this is not related to time. I set the journey of a constituent but the only variables are join in date / start date / end date. I've created "to be confirmed" status that lasts 1 month after effective start date of membership (i.e when the payment is done, mainly online) in order to let the team have enough time to check the document.  
  > **username_0**: CiviRules did the job! This is exactly what I was looking for. Thanks so much Erik!  
  > **username_1**: Good to hear @Guillaume!  
  
  ---
  
  ### Answer by username_0 on 2019-06-25. Score: 3
  
  Based on Erik's help, this is how I've dealt with my need:
  
  * When a new membership is manually checked and validated (for some legal issue), the team in charge of this task adds the member to a previously created dynamic group (sub group to membership called "validated membership")
  * using CiviRules, the new "validated" member automatically receives an email with a personnalized body AND a .pdf as attachment generated from a template.
  
  # this is the civirule:
  
  > * Linked Condition(s): Contact (not) in Group(s) In one of selected groups ("validated membership")
  > * Linked Action(s): Send PDF to e-mail address (printer or mailbox) "" with template "XXX" , template for e-mail body "YYY"
  > * No Delay
  
  
  ---
  
  