2

I'm looking to take periodic PDF snapshots of a SearchDisplay's output for archiving purposes.

I see Demerit's option as a possible solution, 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.

1 Answer 1

6

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

Pradeep

8
  • 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.
    – Justin657
    Nov 7, 2023 at 20:30
  • 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.
    – Justin657
    Nov 7, 2023 at 20:37
  • 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.
    – Demerit
    Nov 8, 2023 at 1:35
  • 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.
    – Justin657
    Nov 8, 2023 at 16:41
  • Here's the call: cv api4 --user=test_cms_admin SearchDisplay.download display=Test_Table_1 savedSearch=Test format=pdf > reporttest.pdf
    – Justin657
    Nov 8, 2023 at 16:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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