Upload file to Fibery in Action button

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

2 Likes

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:

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 ?

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

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.

  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
  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

1 Like

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

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

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

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

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?

Hi, Chr1sG

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

1 Like

Hi, Sylvain

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

Thanks,
Oleg

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

2 Likes

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

1 Like

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

2 Likes

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? :frowning:

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

1 Like

@Chr1sG

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

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

Thanks,
Oleg

1 Like

Hi, @Sylvain_Vuilliot

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

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

2 Likes

I just meant that, at the moment, the guide for how to create 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).

1 Like

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
<%
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

1 Like

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

Here we go

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