Answers.Body: <p>you need to specify <code>--user</code> parameter in the cv API call otherwise the fetch will be treated as anonymous user and will return blank results if the results don't have access to an anonymous user. Providing <code>--user</code> will give you result if the cms user specified has access to the data.</p>
  <p>eg
  <code>--user=cmsusername</code></p>
  <p>HTH</p>
  <p>Pradeep</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-11-07T20:30:09.493Z
Answers.Text: Thanks, that worked. Now I can generate the csv and json array outputs with all the query results. However the PDF output gets cut off on the first line of results. It prints the table header and then only part of the first line of data. As if the PDF generation process gets stuck somehow. It doesn't run long or time out. Plus for my testing I've limited it to 10 lines of query results. Weird. No errors in the Civi debug logs either.
Answers.UserDisplayName: Justin657
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-11-07T20:37:52.287Z
Answers.Text: Also just to clarify, when I manually download the results as a PDF via the SearchDisplay Action menu, the generated PDF file is good, showing all the results.
Answers.UserDisplayName: Justin657
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-11-08T01:35:22.650Z
Answers.Text: It works ok for me so maybe is something specific about your search display or it chokes on some unusual data. Try it with a super simple search and display.
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-11-08T16:41:20.707Z
Answers.Text: Still gets cut off even with a simple query displaying only the Contact ID and Display Name for Individuals, again about 10 records in the results. This time it chokes on display of the table header. PDF is ok when I manually download it from Actions menu.
Answers.UserDisplayName: Justin657
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-11-08T16:45:05.940Z
Answers.Text: Here's the call: cv api4 --user=test_cms_admin SearchDisplay.download display=Test_Table_1 savedSearch=Test format=pdf > reporttest.pdf
Answers.UserDisplayName: Justin657
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-11-08T17:53:12.563Z
Answers.Text: Maybe it's a version difference. I admit I didn't test with 5.65 (using 5.69).
Answers.UserDisplayName: Demerit
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-11-08T18:01:57.133Z
Answers.Text: No worries, I'll bring this up to 5.67 and see where we go from there.
Answers.UserDisplayName: Justin657
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-11-09T20:11:58.503Z
Answers.Text: Well, upgrading to 5.67 has not fixed the issue. Still investigating...
Answers.UserDisplayName: Justin657
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-11-07T17:54:37.897Z
Answers.LastActivityDate: 2023-11-07T17:54:37.897Z
Answers.UserDisplayName: Pradeep Nayak
Body: <p>I'm looking to take periodic PDF snapshots of a SearchDisplay's output for archiving purposes.</p>
  <p>I see <a href="https://civicrm.stackexchange.com/a/45512/15346">Demerit's option as a possible solution</a>, but in my tests so far the <code>cv api4 SearchDisplay.download</code> call only generates a blank output file.</p>
  <p>My code is similar to this sample code:</p>
  <pre><code>cv api4 SearchDisplay.download savedSearch=saved_search_name display=search_display_name format=csv &gt; report.csv
  </code></pre>
  <p>When I run the same command in the API Explorer v4 with output to <code>array</code>, I see the correct values.</p>
  <p>But when I run the same code via a bash script, the output file is empty. It does generate the output file, but it's blank. I get the same empty file when I run the script with other output formats like <code>csv</code> and <code>pdf</code>.</p>
  <p>It's probably something simple. I'm just stuck. Any ideas?</p>
  <p>Thanks.</p>
  <p>Civi 5.65.0 + Drupal 10.</p>
  
Tags: <searchkit><pdf>
Title: How to download SearchDisplay results as a PDF via API4
ThreadText: # How to download SearchDisplay results as a PDF via API4
  
  (Asked by: username_0 on 2023-11-07)
  
  I'm looking to take periodic PDF snapshots of a SearchDisplay's output for archiving purposes.
  
  I see [username_2's option as a possible solution](https://civicrm.stackexchange.com/a/45512/15346), but in my tests so far the `cv api4 SearchDisplay.download` call only generates a blank output file.
  
  My code is similar to this sample code:
  
  ```
  cv api4 SearchDisplay.download savedSearch=saved_search_name display=search_display_name format=csv > report.csv
  
  ```
  
  When I run the same command in the API Explorer v4 with output to `array`, I see the correct values.
  
  But when I run the same code via a bash script, the output file is empty. It does generate the output file, but it's blank. I get the same empty file when I run the script with other output formats like `csv` and `pdf`.
  
  It's probably something simple. I'm just stuck. Any ideas?
  
  Thanks.
  
  Civi 5.65.0 + Drupal 10.
  
  **Tags:** searchkit, pdf
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2023-11-07. Score: 4 | Accepted answer
  
  you need to specify `--user` parameter in the cv API call otherwise the fetch will be treated as anonymous user and will return blank results if the results don't have access to an anonymous user. Providing `--user` will give you result if the cms user specified has access to the data.
  
  eg
  `--user=cmsusername`
  
  HTH
  
  username_1
  
  > **Comments:**
  > **username_0**: Thanks, that worked. Now I can generate the csv and json array outputs with all the query results. However the PDF output gets cut off on the first line of results. It prints the table header and then only part of the first line of data. As if the PDF generation process gets stuck somehow. It doesn't run long or time out. Plus for my testing I've limited it to 10 lines of query results. Weird. No errors in the Civi debug logs either.  
  > **username_0**: Also just to clarify, when I manually download the results as a PDF via the SearchDisplay Action menu, the generated PDF file is good, showing all the results.  
  > **username_2**: It works ok for me so maybe is something specific about your search display or it chokes on some unusual data. Try it with a super simple search and display.  
  > **username_0**: Still gets cut off even with a simple query displaying only the Contact ID and Display Name for Individuals, again about 10 records in the results. This time it chokes on display of the table header. PDF is ok when I manually download it from Actions menu.  
  > **username_0**: Here's the call: cv api4 --user=test_cms_admin SearchDisplay.download display=Test_Table_1 savedSearch=Test format=pdf > reporttest.pdf  
  > **username_2**: Maybe it's a version difference. I admit I didn't test with 5.65 (using 5.69).  
  > **username_0**: No worries, I'll bring this up to 5.67 and see where we go from there.  
  > **username_0**: Well, upgrading to 5.67 has not fixed the issue. Still investigating...  
  
  ---
  
  