Export to File
Usually, the best way to retrieve the Fatture in Cloud resources is to include the related API calls in your code, but in some cases, being able to export our data from Fatture in Cloud to a file can be extremely important.
For example, when using Zapier it can be challenging to retrieve the IDs of some resources, such as Products, Clients, Suppliers, Payment Methods, Payment Accounts, etc... Knowing these IDs is mandatory when creating new documents using Zapier, but it can be complicated to retrieve them using Zapier itself.
In this guide, we'll show you a simple way to retrieve your data and store them in a Spreadsheet file. From there, you'll be able to use the extracted data as you prefer.
We provide the same functionality described here in our Utilities tool! Please check it out before starting implementing it from scratch!
๐ฎย Authentication and Companyโ
To execute this code, you will need to replace two parameters in the code with your values. These parameters are:
- The Access Token, that will be used to authenticate your API calls
- The Company ID, which is used by our APIs to identify the Company you're working on
The Access Token can be retrieved in multiple ways, but for this use case, we strongly suggest the Manual Token.
When you create a Token, you will need to select the correct Scopes. For example, the List Products method requires the product:r scope. Check the scopes required by your API method before creating the token.
The Company ID is the identifier of the Company, so you can retrieve it only once and use it for every API call. It can be retrieved as explained here. To make this task easier for you, we also added the code to retrieve the Company ID, but we commented it so that you can use it only if needed.
๐ย Wait a minute!โ
Before showing you our code, we must discuss a moment about why we decided to create this guide.
First of all, the main problem performing the export is that some of these operations are paginated; this means that the API will return only a subset of the resources (the maximum page size is 100), and you'll need to perform multiple API requests to obtain the whole set of resources.
For the List methods that don't require pagination (such as the List Payment Accounts) this operation is trivial, so we won't show it here; this code can be easily adapted to be used also for this kind of resources.
You can recognize a paginated method because it contains dedicated fields, such as page and per_page.
This operation should NOT be used to obtain the most advanced resources, such as the Issued Documents. This kind of resource usually comes in a much higher set size than the Products, and it will likely consume your quotas fast. If you still want to use this code to retrieve the documents, we suggest you at least filter the results to limit the number of exported documents as much as possible.
On this page, we decided to show you how to export the Products using the List Products method. We selected this API method because it is paginated, and its IDs can be used while creating new documents; also, you will probably have more than a single page of products, so it would be impossible to export the whole set by using a single API call.
By proceeding forward, you'll also notice that we provided only Python code. We decided to use Python because it is relatively easy to install, and also because it is one of the few languages supported by Zapier in their Actions. You can still decide to use our code as a guide to implementing the same functionality in your favorite language.
We will provide three different use cases, select the one you prefer:
๐ย Export with Zapierโ
Zapier is an extremely useful no-code tool, that lets users without coding competences to be able to create simple integrations.
At the same time, it can be complicated to use in slightly complicated use cases, such as the pagination management.
Our Zapier integration provides the Actions to use List API methods such as the List Products, but the pagination can make it extremely difficult (but not impossible) to retrieve the whole set of resources.
Zapier has its own limits, based on the plan you are currently using. Most probably, the free plan will NOT be enough to perform the export if you have more than one page.
You can check the limits in the Zap limits and in the Code by Zapier rate limits
The Export Zap would be composed of three different steps.
The first step is the Trigger, that is used to define then a Zap must be executed. In this case we won't use any data coming from the Trigger, so you can just use the trigger that you prefer, but we strongly suggest to use the Zapier Chrome Extension that lets you to trigger a Zap by clicking a button on your browser.
The second step is where the magic happens, this is why we decided to describe it in two different subsections:
If the method is NOT paginated, you can simply select one of the Fatture in Cloud Actions (for example the List Payment Methods) and use it to extract the data.
If the method is paginated, using one of our actions can be really complicated so we suggest to use the Code by Zapier Action.
When you test a List Action, Zap will always return just one of the elements returned to the action; this is because you can use this element to link the next steps. The whole list of resources will be returned only after the Zap publication.
The third step will let you write the retrieved resources to its final destination.
You could for example use the Google Sheets' Create Multiple Spreadsheet Rows action, or Microsoft Excel's Add Row(s) action, or one of the other actions offered by Zapier. The decision is up to you.