# Display PDF return by web service call in smart action

**URL:** <https://community.forestadmin.com/t/display-pdf-return-by-web-service-call-in-smart-action/6262>\
**Category:** Help me!\
**Created:** [May 6, 2023, 3:44pm UTC](https://community.forestadmin.com/t/display-pdf-return-by-web-service-call-in-smart-action/6262 "2023-05-06T15:44:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ptrognon](https://avatars.discourse-cdn.com/v4/letter/p/85f322/32.png) [@ptrognon](https://community.forestadmin.com/u/ptrognon)\
**Post date:** [May 6, 2023, 3:44pm UTC](https://community.forestadmin.com/t/display-pdf-return-by-web-service-call-in-smart-action/6262/1 "2023-05-06T15:44:22Z")

</div>

I have a smart action that calls a webservice that returns me a PDF type document, here is the code attached, how do I display the PDF that I retrieve in the bodyPDF variable?

```
        collection.addAction('Get Search Contract', {
            scope: 'Single',
            async execute(context, resultBuilder) {
                const record = await context.getRecord(['souscriptionExternalId']);

                try {
                    const bodyPDF = await AuthApiService.searchContract(record.souscriptionExternalId);
                    return resultBuilder.success(`Successfully read Search Contract for souscription ${record.souscriptionExternalId}`);
                } catch (error) {
                    return resultBuilder.error(`Failed to read Search Contract for souscription ${record.souscriptionExternalId}`);
                }
            },
        });

```

## Context

- Project name: PledgerMiddleV2
- Team name: Pledger
- Environment name: Recette
- Agent (forest package) name & version: 2 / typescript
- Database type: Postgres
- Recent changes made on your end if any: NA

---

<div class="post-metadata">

**Author:** ![anon39940173](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@anon39940173](https://community.forestadmin.com/u/anon39940173)\
**Post date:** [May 7, 2023, 7:17pm UTC](https://community.forestadmin.com/t/display-pdf-return-by-web-service-call-in-smart-action/6262/2 "2023-05-07T19:17:01Z")

</div>

Hi @ptrognon

Here is the related documentation: [https://docs.forestadmin.com/developer-guide-agents-nodejs/agent-customization/actions/result-builder#file-generation](https://docs.forestadmin.com/developer-guide-agents-nodejs/agent-customization/actions/result-builder#file-generation)

Your handler should look something like this:

```javascript
        collection.addAction('Get Search Contract', {
            scope: 'Single',
            generateFile: true, // <-- do not forget this
            async execute(context, resultBuilder) {
                const record = await context.getRecord(['souscriptionExternalId']);

                try {
                    const bodyPDF = await AuthApiService.searchContract(record.souscriptionExternalId);
                    return resultBuilder.file(bodyPDF, 'file.pdf', 'application/pdf');
                } catch (error) {
                    return resultBuilder.error(`Failed to read Search Contract for souscription ${record.souscriptionExternalId}`);
                }
            },
        });

```

---

<div class="post-metadata">

**Author:** ![ptrognon](https://avatars.discourse-cdn.com/v4/letter/p/85f322/32.png) [@ptrognon](https://community.forestadmin.com/u/ptrognon)\
**Post date:** [May 7, 2023, 7:45pm UTC](https://community.forestadmin.com/t/display-pdf-return-by-web-service-call-in-smart-action/6262/3 "2023-05-07T19:45:56Z")

</div>

Hello, yes i try resuildbuilder.file but it’s do nothing ?

what is the expected result with this call? it presents the pdf file in a popup? does it save it locally (I don’t see anything in the local download directory)?

---

<div class="post-metadata">

**Author:** ![anon39940173](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@anon39940173](https://community.forestadmin.com/u/anon39940173)\
**Post date:** [May 7, 2023, 8:20pm UTC](https://community.forestadmin.com/t/display-pdf-return-by-web-service-call-in-smart-action/6262/4 "2023-05-07T20:20:19Z")

</div>

It should trigger a download on the browser.  
bodyPdf should be either a string, a buffer or a stream.

Can you try replacing bodyPDF with a dummy payload?

```javascript
resultBuilder.file('dummy payload', 'file.txt', 'text/plain');

```
