# Upload file to Fibery in Action button

**URL:** <https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664>\
**Category:** API & Programming\
**Created:** [May 28, 2021, 11:10am UTC](https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664 "2021-05-28T11:10:31Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sylvain\_Vuilliot](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/sylvain_vuilliot/32/1771_2.png) [@Sylvain\_Vuilliot](https://community.fibery.io/u/Sylvain_Vuilliot)\
**Post date:** [May 28, 2021, 11:10am UTC](https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664/1 "2021-05-28T11:10:31Z")

</div>

I’m on the way to create an action button script for generating a pdf of my invoice entity.  
So the steps are :

- get invoice lines related to the currentEntity \> ok
- post an http request to pdfMonkey with the data \> ok
- get back the download url \> ok
- create a file entity in fibery from this url \> TODO
- attach the file to the invoice \> TODO

I saw in the API guide how to upload a file but I don’t know how to use it in an action button script.

Once done, I could provide the script, since I think, it could be helpful for many.

Thanks for your help

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [May 28, 2021, 11:49am UTC](https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664/2 "2021-05-28T11:49:10Z")

</div>

If you know how to do it with the API, then you can do it with an action button using a script.  
See here for how to execute any API command from an action button:

> [@Command methods for button, and/or token availability in context](https://community.fibery.io/t/command-methods-for-button-and-or-token-availability-in-context/1035/3):
>
> Nice! I can’t find executeSingleCommand anywhere in the API docs, but I assume the IntelliSense in the button editor will help and/or that it takes the entire payload that would normally go in to body? The other stuff isn’t a huge deal for me, so no worries about that. slight_smile EDIT: Indeed it shows up in the IntelliSense, and it takes the body payload—except you omit the wrapping array and leave it with 1 command (as the method name suggests). For other people’s reference, here’s an ex…

---

<div class="post-metadata">

**Author:** ![Sylvain\_Vuilliot](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/sylvain_vuilliot/32/1771_2.png) [@Sylvain\_Vuilliot](https://community.fibery.io/u/Sylvain_Vuilliot)\
**Post date:** [May 28, 2021, 1:41pm UTC](https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664/3 "2021-05-28T13:41:12Z")

</div>

Thanks for your help, but it seems file upload is not a “command” since it requires use of /api/file endpoint instead of api/command  
Do you know if this can be done with the fibery service from script context without relying on external http call to the API ?

---

<div class="post-metadata">

**Author:** ![Sylvain\_Vuilliot](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/sylvain_vuilliot/32/1771_2.png) [@Sylvain\_Vuilliot](https://community.fibery.io/u/Sylvain_Vuilliot)\
**Post date:** [May 31, 2021, 9:12am UTC](https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664/4 "2021-05-31T09:12:32Z")

</div>

I also tried using the “http” service provided in the script context, but I’m don’t know if we can create a binary read stream from url and how to post it as a multipart form…

Is that even possible via the integromat integration ?

It would be helpful to have some doc on what is allowed in the script context regarding services available and their API, external dependencies, permanent or temporary storage, duration limits, …

Thanks for your help, as the pdf generation with pdfMonkey is really interesting

---

<div class="post-metadata">

**Author:** ![Oleg](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/oleg/32/1887_2.png) [@Oleg](https://community.fibery.io/u/Oleg)\
**Post date:** [May 31, 2021, 3:18pm UTC](https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664/5 "2021-05-31T15:18:30Z")

</div>

Hi, Sylvain

Thanks for sharing your problem. I am a developer from the fibery integrations team. I like the idea to create files from URLs and we will definitely implement it in the nearest future.

But I think there is a possibility to close your case right now using built-in possibilities of fibery action buttons and without using pdfMonkey.

Please find below step-by-step instructions on how to implement something you need using Fibery buttons only.

My app in Fibery contains Invoice type with a collection of Line type items.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/fibery/original/2X/4/4cf59e2be7389171ee43a712d6884e7cdcfd91bf.png)

1. Add **Generate Invoice** action button for Invoice type.
2. In action button popup add action **Attach PDF using template**
3. Now we need to provide a template for generating the document. Please find details on how to deal with templates here: [Markdown Templates | Fibery Help Center](https://help.fibery.io/en/articles/5170015-markdown-templates)  
 ![image](https://us1.discourse-cdn.com/flex020/uploads/fibery/original/2X/0/0ac54b0eaf065e967d119956b26b175574ed02d3.png)
4. Then we click the button on invoice to generate attachment.

The result can be found below. Please let me know if you find this solution acceptable or we will think about another way.

![gif-template](https://us1.discourse-cdn.com/flex020/uploads/fibery/original/2X/7/7845c59bb033a233d02aaa82ce6affd32fb53cef.gif)

---

<div class="post-metadata">

**Author:** ![Sylvain\_Vuilliot](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/sylvain_vuilliot/32/1771_2.png) [@Sylvain\_Vuilliot](https://community.fibery.io/u/Sylvain_Vuilliot)\
**Post date:** [June 1, 2021, 4:40am UTC](https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664/6 "2021-06-01T04:40:50Z")

</div>

Hi Oleg,

thanks for your reply. I know about the markdown template and I think it is a very good solution for simple cases but what I need is a more advanced document generation like this one  
 ![Capture d’écran du 2021-06-01 06-21-02](https://us1.discourse-cdn.com/flex020/uploads/fibery/original/2X/7/7e2894a189c7dd39a8921507e28edf8252d48ebc.png)

That’s why I suggested a more advanced language for pdf templating in this post  
[https://community.fibery.io/t/changelog-april-22-automated-actions-new-toolbar-in-all-views-duplicate-document-and-a-pen/1569/26?u=sylvain\_vuilliot](https://community.fibery.io/t/changelog-april-22-automated-actions-new-toolbar-in-all-views-duplicate-document-and-a-pen/1569/26)

Another option for templating would be to use docx templates, as they are really user friendly, with a library like this one [https://github.com/alonrbar/easy-template-x](https://github.com/alonrbar/easy-template-x)

In the end, I think integrating with an external document generator like pdfMonkey should be easy to do. So could you please answer my question about uploading a file to fibery in an action script ?

Thank you in advance

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [June 1, 2021, 8:52am UTC](https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664/7 "2021-06-01T08:52:56Z")

</div>

It doesn’t seem to be possible to use markdown in the File Name when attaching a PDF using a template.  
Are there plans to make it possible?

---

<div class="post-metadata">

**Author:** ![Oleg](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/oleg/32/1887_2.png) [@Oleg](https://community.fibery.io/u/Oleg)\
**Post date:** [June 1, 2021, 9:37am UTC](https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664/8 "2021-06-01T09:37:03Z")

</div>

Hi, Chr1sG

It is possible. You may use script \<% NAME(“File Name String”) %\>  
Please see below the screen how it looks like

 ![image](https://us1.discourse-cdn.com/flex020/uploads/fibery/original/2X/0/0579e302b9b2e3136e328b5393e24e9e712ba3d2.png)

---

<div class="post-metadata">

**Author:** ![Oleg](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/oleg/32/1887_2.png) [@Oleg](https://community.fibery.io/u/Oleg)\
**Post date:** [June 1, 2021, 9:38am UTC](https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664/9 "2021-06-01T09:38:45Z")

</div>

Hi, Sylvain

Please give me some time. Need to investigate how it can be done.

Thanks,  
Oleg

---

<div class="post-metadata">

**Author:** ![Oleg](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/oleg/32/1887_2.png) [@Oleg](https://community.fibery.io/u/Oleg)\
**Post date:** [June 3, 2021, 10:22am UTC](https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664/10 "2021-06-03T10:22:39Z")

</div>

Hi again, Sylvain

We discussed your case and decided to extend API with possibility of creating files from script actions. Will let you know when it will be released to production server.

Thanks,  
Oleg

---

<div class="post-metadata">

**Author:** ![Sylvain\_Vuilliot](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/sylvain_vuilliot/32/1771_2.png) [@Sylvain\_Vuilliot](https://community.fibery.io/u/Sylvain_Vuilliot)\
**Post date:** [June 3, 2021, 10:56am UTC](https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664/11 "2021-06-03T10:56:23Z")

</div>

ok, thank you Oleg for taking time on this.  
I think it will be useful for advanced users to be able to manage files from script actions.

But for less techy users, did you discussed about an easier way to create documents from template ? The markdown template is a good idea but I think quite limited regarding subcollections and formatting.  
I don’t request anything urgently on this since I was able to proceed with pdfMonkey, but I had to spend something like 5 or 6 hours from end to end : learning and playing with fibery API, learning pdfMonkey API, writing script action (the most tricky part was to collect the data deeply : invoice, client, invoice lines, invoice line description rich text).  
So I guess, lot of users would like to have an easier way, and I would like you thoughts on this.

Regards

---

<div class="post-metadata">

**Author:** ![Oleg](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/oleg/32/1887_2.png) [@Oleg](https://community.fibery.io/u/Oleg)\
**Post date:** [June 3, 2021, 11:14am UTC](https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664/12 "2021-06-03T11:14:48Z")

</div>

Sylvain,

You are totally right about complexity of using Fibery API and automations. Now we have dedicated integrations team in Fibery to make the integrations/automations more usable. But you know, it takes time. We will do our best to fix things and we are going to give a much more easy way in future.

Thanks,  
Oleg

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [June 13, 2021, 7:39pm UTC](https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664/13 "2021-06-13T19:39:21Z")

</div>

Is it possible to use markdown (e.g. while generating a PDF) to get the contents of rich text fields?  
Or do I have to resort to JS? ☹

---

<div class="post-metadata">

**Author:** ![Oleg](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/oleg/32/1887_2.png) [@Oleg](https://community.fibery.io/u/Oleg)\
**Post date:** [June 14, 2021, 10:41am UTC](https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664/14 "2021-06-14T10:41:07Z")

</div>

Hi, @Chr1sG

There is just text area for editing templates now. But we are going to add more powerful editor for markdown in future for PDF or Document templates in future.

Thanks,  
Oleg

---

<div class="post-metadata">

**Author:** ![Oleg](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/oleg/32/1887_2.png) [@Oleg](https://community.fibery.io/u/Oleg)\
**Post date:** [June 14, 2021, 11:23am UTC](https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664/15 "2021-06-14T11:23:00Z")

</div>

@Chr1sG

In case if it was a question about how to retrieve document using script

```auto
const fibery = context.getService('fibery');
const markdownContent = await fibery.getDocumentContent(`secret`, `md`);

```

Thanks,  
Oleg

---

<div class="post-metadata">

**Author:** ![Oleg](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/oleg/32/1887_2.png) [@Oleg](https://community.fibery.io/u/Oleg)\
**Post date:** [June 14, 2021, 11:33am UTC](https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664/16 "2021-06-14T11:33:28Z")

</div>

Hi, @Sylvain_Vuilliot

Please find the example on how add file to entity from URL below

```auto
const fibery = context.getService('fibery');

for (const entity of args.currentEntities) {
    await fibery.addFileFromUrl(`https://fibery-public-assets.s3.amazonaws.com/apps/integrations/gitlab.png`, `gitlab.png`, entity.type, entity.id, null);
}

```

There are 5 arguments

1. HTTP(s) url
2. File name
3. Entity type
4. Entity id
5. Authentication headers which should be provided if url is not public and secured. Provide null or {} if auth is not needed

Thanks,  
Oleg

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [June 14, 2021, 11:46am UTC](https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664/17 "2021-06-14T11:46:03Z")

</div>

I just meant that, at the moment, the [guide for how to create markdown templates](https://help.fibery.io/en/articles/5170015-markdown-templates) seems to only demonstrate how to refer to simple text fields.  
I was wondering how to use markdown to refer to rich text (or other field types for that matter).

---

<div class="post-metadata">

**Author:** ![Oleg](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/oleg/32/1887_2.png) [@Oleg](https://community.fibery.io/u/Oleg)\
**Post date:** [June 14, 2021, 12:01pm UTC](https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664/18 "2021-06-14T12:01:56Z")

</div>

Got it. So it makes sense to proceed in the following way.

1. Retrieve document secret of the rich field or linked document
2. Retrieve MD content

```auto
<%
const fibery = context.getService('fibery');
const markdownContent = await fibery.getDocumentContent(`secret`, `md`);
%>

```

1. Paste into the corresponding place of the template `<%= markdownContent.content %>`

Thanks,  
Oleg

---

<div class="post-metadata">

**Author:** ![Chr1sG](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/chr1sg/32/3941_2.png) [@Chr1sG](https://community.fibery.io/u/Chr1sG)\
**Post date:** [June 14, 2021, 1:03pm UTC](https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664/19 "2021-06-14T13:03:25Z")

</div>

Thanks.  
Can you give a template for retrieving the secret please, I’m not sure I fully understand the api documentation.

---

<div class="post-metadata">

**Author:** ![Oleg](https://sea2.discourse-cdn.com/flex020/user_avatar/community.fibery.io/oleg/32/1887_2.png) [@Oleg](https://community.fibery.io/u/Oleg)\
**Post date:** [June 14, 2021, 1:18pm UTC](https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664/20 "2021-06-14T13:18:18Z")

</div>

Here we go

```auto
<%
const fibery = context.getService('fibery'); 
const entity = await fibery.getEntityById(Entity.Type, Entity.Id, ['Description']);
%>
There is a document secret: <%= entity["Description"].secret %>

```

[Next page](https://community.fibery.io/t/upload-file-to-fibery-in-action-button/1664.md?page=2)
