Join & Transform issued documents
Fatture in Cloud makes it possible to transform a document into another type, for example, a proforma into an invoice, or to join two documents together. Of course, our APIs provide the same functionality, here we explain how to do it.
In this example, we'll suppose you have to manage just one Company, so we simply inserted its ID directly in the code. If instead, you need to be able to manage multiple companies, you'll need to retrieve the ID of the current company in some way. Check the Company-scoped Methods page for more info.
โ Join or Transformโ
Although the transform and join use cases may seem very different, our APIs similarly treat them.
Executing a join or transform call will NOT create the new document but, instead, it will return a body that you will need to pass to the create document method.
Before diving into the functionality details it's better to define the two methods:
๐จโ๐ฉโ๐งโ๐ฆย Joinโ
You can use the Join Issued Document method to merge two documents into an invoice. The type of documents that can be joined are delivery_notes, orders, quotes, and work_reports.
The required query parameters for the request are:
- ids: List of the document ids you want to join (eg. "876991,876993,876997").
- group: If this flag is set to 1, the request will group the items (e.g. if you have the same products in two different documents, they will be grouped); otherwise the items will be kept separate.
- e_invoice: If this flag is set to 1, your new document will be electronic.
GET /c/1235/issued_documents/join?ids=876991,876993,876997&group=1&e_invoice=1 HTTP/1.1
Accept: application/json
Host: api-v2.fattureincloud.it
The corresponding code with our SDKs:
- C#
- Go
- Java
- JavaScript
- PHP
- Python
- Ruby
- TypeScript
using System;
using It.FattureInCloud.Sdk.Api;
using It.FattureInCloud.Sdk.Client;
using It.FattureInCloud.Sdk.Model;
namespace test
{
class Program
{
static void Main(string[] args)
{
Configuration config = new Configuration();
//set your access token
config.AccessToken = "YOUR_ACCESS_TOKEN";
//set your company id
var companyId = 12345;
var apiInstance = new IssuedDocumentsApi(config);
// Join documents: https://github.com/fattureincloud/fattureincloud-csharp-sdk/blob/master/docs/IssuedDocumentsApi.md#joinissueddocuments
try
{
JoinIssuedDocumentsResponse result = apiInstance.JoinIssuedDocuments(companyId, "876991,876993,876997", 1, 1);
Console.Write(result);
}
catch (ApiException e)
{
Console.WriteLine("Exception when calling IssuedDocumentsApi.JoinIssuedDocuments: " + e.Message);
Console.WriteLine("Status Code: " + e.ErrorCode);
Console.WriteLine(e.StackTrace);
}
}
}
}
package main
import (
"context"
"encoding/json"
"fmt"
"os"
fattureincloudapi "github.com/fattureincloud/fattureincloud-go-sdk/v2/api"
)
func main() {
//set your access token
auth := context.WithValue(context.Background(), fattureincloudapi.ContextAccessToken, "YOUR_ACCESS_TOKEN")
configuration := fattureincloudapi.NewConfiguration()
apiClient := fattureincloudapi.NewAPIClient(configuration)
//set your company id
companyId := int32(12345)
// Transform the document: https://github.com/fattureincloud/fattureincloud-go-sdk/blob/master/docs/IssuedDocumentsAPI.md#joinissueddocuments
resp, r, err := apiClient.IssuedDocumentsAPI.JoinIssuedDocuments(auth, companyId).Ids("876991,876993,876997").Group(1).EInvoice(1).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `IssuedDocumentsAPI.JoinIssuedDocuments``: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
json.NewEncoder(os.Stdout).Encode(resp)
}
import it.fattureincloud.sdk.ApiClient;
import it.fattureincloud.sdk.ApiException;
import it.fattureincloud.sdk.Configuration;
import it.fattureincloud.sdk.auth.*;
import it.fattureincloud.sdk.model.*;
import it.fattureincloud.sdk.api.IssuedDocumentsApi;
public class Application {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
//set your access token
OAuth OAuth2AuthenticationCodeFlow = (OAuth) defaultClient.getAuthentication("OAuth2AuthenticationCodeFlow");
OAuth2AuthenticationCodeFlow.setAccessToken("YOUR_ACCESS_TOKEN");
IssuedDocumentsApi apiInstance = new IssuedDocumentsApi(defaultClient);
//set your company id
Integer companyId = 12345;
// Join documents: https://github.com/fattureincloud/fattureincloud-java-sdk/blob/master/docs/IssuedDocumentsApi.md#joinissueddocuments
try {
JoinIssuedDocumentsResponse result = apiInstance.joinIssuedDocuments(companyId, "876991,876993,876997", 1, 1);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling IssuedDocumentsApi#joinIssuedDocuments");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
var fattureInCloudSdk = require("@fattureincloud/fattureincloud-js-sdk");
let defaultClient = fattureInCloudSdk.ApiClient.instance;
//set your access token
let OAuth2AuthenticationCodeFlow =
defaultClient.authentications["OAuth2AuthenticationCodeFlow"];
OAuth2AuthenticationCodeFlow.accessToken = "YOUR_ACCESS_TOKEN";
let apiInstance = new fattureInCloudSdk.IssuedDocumentsApi();
//set your company id
let companyId = 12345;
let opts = {
group: 1,
eInvoice: 1,
};
// Join documents: https://github.com/fattureincloud/fattureincloud-js-sdk/blob/master/docs/IssuedDocumentsApi.md#joinIssuedDocuments
apiInstance.joinIssuedDocuments(companyId, "876991,876993,876997", opts).then(
(result) => {
console.log(
"API called successfully. Returned result: " + JSON.stringify(result)
);
},
(error) => {
console.error(error);
}
);
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use FattureInCloud\Configuration;
use FattureInCloud\Api\IssuedDocumentsApi;
//set your access token
$config = Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN');
$apiInstance = new IssuedDocumentsApi(
new GuzzleHttp\Client(),
$config
);
//set your company id
$company_id = 12345;
// Join documents: https://github.com/fattureincloud/fattureincloud-php-sdk/blob/master/docs/Api/IssuedDocumentsApi.md#joinissueddocuments
try {
$result = $apiInstance->joinIssuedDocuments($company_id, "876991,876993,876997", 1, 1);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling IssuedDocumentsApi->joinIssuedDocuments: ', $e->getMessage(), PHP_EOL;
}
import fattureincloud_python_sdk
from fattureincloud_python_sdk.api import issued_documents_api
from pprint import pprint
# set your access token
configuration = fattureincloud_python_sdk.Configuration()
configuration.access_token = "YOUR_ACCESS_TOKEN"
# set your company id
company_id = 12345
# Join documents: https://github.com/fattureincloud/fattureincloud-python-sdk/blob/master/docs/IssuedDocumentsApi.md#join_issued_documents
with fattureincloud_python_sdk.ApiClient(configuration) as api_client:
api_instance = issued_documents_api.IssuedDocumentsApi(api_client)
try:
api_response = api_instance.join_issued_documents(company_id, "876991,876993,876997", group=1, e_invoice=1)
pprint(api_response)
except fattureincloud_python_sdk.ApiException as e:
print("Exception when calling IssuedDocumentsApi->join_issued_documents: %s\n" % e)
require 'time'
require 'fattureincloud_ruby_sdk'
FattureInCloud_Ruby_Sdk.configure do |config|
# set your access token
config.access_token = 'YOUR ACCESS TOKEN'
end
api_instance = FattureInCloud_Ruby_Sdk::IssuedDocumentsApi.new
# set your company id
company_id = 12345
opts = {
group: 1,
e_invoice: 1
}
# Join documents: https://github.com/fattureincloud/fattureincloud-ruby-sdk/blob/master/docs/IssuedDocumentsApi.md#join_issued_documents
begin
result = api_instance.join_issued_documents(company_id, "876991,876993,876997", opts)
p result
rescue FattureInCloud_Ruby_Sdk::ApiError => e
puts "Error when calling IssuedDocumentsApi->join_issued_documents: #{e}"
end
import {
Configuration,
IssuedDocumentsApi,
} from "@fattureincloud/fattureincloud-ts-sdk";
//set your access token
const apiConfig = new Configuration({
accessToken: "YOUR_ACCESS_TOKEN",
});
let apiInstance = new IssuedDocumentsApi(apiConfig);
//set your company id
let companyId = 12345;
// Join documents: https://github.com/fattureincloud/fattureincloud-ts-sdk/blob/master/docs/IssuedDocumentsApi.md#joinIssuedDocuments
apiInstance.joinIssuedDocuments(companyId, "876991,876993,876997", 1, 1).then(
(data) => {
console.log(data);
},
(error) => {
console.error(error);
}
);
๐ย Transformโ
The Transform Issued Document method makes it possible to transform a document into another type of document. Here you can find which types can be transformed and what they can become.
Actual Type | New Type |
---|---|
Quote | Order, Proforma, Receipt, Invoice |
Work Report | Order, Proforma, Receipt, Invoice |
Order | Proforma, Receipt, Invoice |
Proforma | Receipt, Invoice |
The required query parameters for the request are:
- original_document_id: The id of the document you want to transform (eg. 876993).
- new_type: The type of document you want to obtain (eg. "invoice").
- e_invoice: If this flag is set to 1, your new document will be electronic.
- transform_keep_copy: If this flag is set to 1, your old document will be preserved.
GET /c/1235/issued_documents/transform?original_document_id=876993&new_type=invoice&e_invoice=1&transform_keep_copy=1 HTTP/1.1
Accept: application/json
Host: api-v2.fattureincloud.it
The correspondig code with our SDKs:
- C#
- Go
- Java
- JavaScript
- PHP
- Python
- Ruby
- TypeScript
using System;
using It.FattureInCloud.Sdk.Api;
using It.FattureInCloud.Sdk.Client;
using It.FattureInCloud.Sdk.Model;
namespace test
{
class Program
{
static void Main(string[] args)
{
Configuration config = new Configuration();
//set your access token
config.AccessToken = "YOUR_ACCESS_TOKEN";
//set your company id
var companyId = 12345;
var apiInstance = new IssuedDocumentsApi(config);
// Transform the document: https://github.com/fattureincloud/fattureincloud-csharp-sdk/blob/master/docs/IssuedDocumentsApi.md#transformissueddocument
try
{
TransformIssuedDocumentResponse result = apiInstance.TransformIssuedDocument(companyId, 876993, "invoice", 1, 1);
Console.Write(result);
}
catch (ApiException e)
{
Console.WriteLine("Exception when calling IssuedDocumentsApi.TransformIssuedDocument: " + e.Message);
Console.WriteLine("Status Code: " + e.ErrorCode);
Console.WriteLine(e.StackTrace);
}
}
}
}
package main
import (
"context"
"encoding/json"
"fmt"
"os"
fattureincloudapi "github.com/fattureincloud/fattureincloud-go-sdk/v2/api"
)
func main() {
//set your access token
auth := context.WithValue(context.Background(), fattureincloudapi.ContextAccessToken, "YOUR_ACCESS_TOKEN")
configuration := fattureincloudapi.NewConfiguration()
apiClient := fattureincloudapi.NewAPIClient(configuration)
//set your company id
companyId := int32(12345)
// Transform the document: https://github.com/fattureincloud/fattureincloud-go-sdk/blob/master/docs/IssuedDocumentsAPI.md#transformIssuedDocument
resp, r, err := apiClient.IssuedDocumentsAPI.TransformIssuedDocument(auth, companyId).OriginalDocumentId(876993).NewType("invoice").EInvoice(1).TransformKeepCopy(1).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `IssuedDocumentsAPI.TransformIssuedDocument``: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}
json.NewEncoder(os.Stdout).Encode(resp)
}
import it.fattureincloud.sdk.ApiClient;
import it.fattureincloud.sdk.ApiException;
import it.fattureincloud.sdk.Configuration;
import it.fattureincloud.sdk.auth.*;
import it.fattureincloud.sdk.model.*;
import it.fattureincloud.sdk.api.IssuedDocumentsApi;
public class Application {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
//set your access token
OAuth OAuth2AuthenticationCodeFlow = (OAuth) defaultClient.getAuthentication("OAuth2AuthenticationCodeFlow");
OAuth2AuthenticationCodeFlow.setAccessToken("YOUR_ACCESS_TOKEN");
IssuedDocumentsApi apiInstance = new IssuedDocumentsApi(defaultClient);
//set your company id
Integer companyId = 12345;
// Transform the document: https://github.com/fattureincloud/fattureincloud-java-sdk/blob/master/docs/IssuedDocumentsApi.md#transformissueddocument
try {
TransformIssuedDocumentResponse result = apiInstance.transformIssuedDocument(companyId, 876993, "invoice", 1, 1);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling IssuedDocumentsApi#transformIssuedDocument");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
var fattureInCloudSdk = require("@fattureincloud/fattureincloud-js-sdk");
let defaultClient = fattureInCloudSdk.ApiClient.instance;
//set your access token
let OAuth2AuthenticationCodeFlow =
defaultClient.authentications["OAuth2AuthenticationCodeFlow"];
OAuth2AuthenticationCodeFlow.accessToken = "YOUR_ACCESS_TOKEN";
let apiInstance = new fattureInCloudSdk.IssuedDocumentsApi();
//set your company id
let companyId = 12345;
let opts = {
eInvoice: 1,
transformKeepCopy: 1,
};
// Transform issued document: https://github.com/fattureincloud/fattureincloud-js-sdk/blob/master/docs/IssuedDocumentsApi.md#transformIssuedDocument
apiInstance.transformIssuedDocument(companyId, 876993, "invoice", opts).then(
(result) => {
console.log(
"API called successfully. Returned result: " + JSON.stringify(result)
);
},
(error) => {
console.error(error);
}
);
<?php
require_once(__DIR__ . '/vendor/autoload.php');
use FattureInCloud\Configuration;
use FattureInCloud\Api\IssuedDocumentsApi;
//set your access token
$config = Configuration::getDefaultConfiguration()->setAccessToken('YOUR_ACCESS_TOKEN');
$apiInstance = new IssuedDocumentsApi(
new GuzzleHttp\Client(),
$config
);
//set your company id
$company_id = 12345;
// Transform the document: https://github.com/fattureincloud/fattureincloud-php-sdk/blob/master/docs/Api/IssuedDocumentsApi.md#transformissueddocument
try {
$result = $apiInstance->transformIssuedDocument($company_id, 876993, "invoice", 1, 1);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling IssuedDocumentsApi->transformIssuedDocument: ', $e->getMessage(), PHP_EOL;
}
import fattureincloud_python_sdk
from fattureincloud_python_sdk.api import issued_documents_api
from pprint import pprint
# set your access token
configuration = fattureincloud_python_sdk.Configuration()
configuration.access_token = "YOUR_ACCESS_TOKEN"
# set your company id
company_id = 12345
# Transform the document: https://github.com/fattureincloud/fattureincloud-python-sdk/blob/master/docs/IssuedDocumentsApi.md#transform_issued_document
with fattureincloud_python_sdk.ApiClient(configuration) as api_client:
api_instance = issued_documents_api.IssuedDocumentsApi(api_client)
try:
api_response = api_instance.transform_issued_document(company_id, 876993, "invoice", e_invoice=1, transform_keep_copy=1)
pprint(api_response)
except fattureincloud_python_sdk.ApiException as e:
print("Exception when calling IssuedDocumentsApi->transform_issued_document: %s\n" % e)
require 'time'
require 'fattureincloud_ruby_sdk'
FattureInCloud_Ruby_Sdk.configure do |config|
# set your access token
config.access_token = 'YOUR ACCESS TOKEN'
end
api_instance = FattureInCloud_Ruby_Sdk::IssuedDocumentsApi.new
# set your company id
company_id = 12345
opts = {
e_invoice: 1,
transform_keep_copy: 1
}
# Transform the document: https://github.com/fattureincloud/fattureincloud-ruby-sdk/blob/master/docs/IssuedDocumentsApi.md#transform_issued_document
begin
result = api_instance.transform_issued_document(company_id, 876993, "invoice", opts)
p result
rescue FattureInCloud_Ruby_Sdk::ApiError => e
puts "Error when calling IssuedDocumentsApi->transform_issued_document: #{e}"
end
import {
Configuration,
IssuedDocumentsApi,
} from "@fattureincloud/fattureincloud-ts-sdk";
//set your access token
const apiConfig = new Configuration({
accessToken: "YOUR_ACCESS_TOKEN",
});
let apiInstance = new IssuedDocumentsApi(apiConfig);
//set your company id
let companyId = 12345;
// Transform the document: https://github.com/fattureincloud/fattureincloud-ts-sdk/blob/master/docs/IssuedDocumentsApi.md#transformIssuedDocument
apiInstance.transformIssuedDocument(companyId, 876993, "invoice", 1, 1).then(
(data) => {
console.log(data);
},
(error) => {
console.error(error);
}
);
You can set the Access Token in the dedicated section, for more informations look here.
๐ฌย Send It!โ
The two methods above won't perform any modification, but they will just return the body that you'll need to use to perform the desired action. This lets you eventually review the final result and modify it if needed.
The request also includes an options section, that makes it possible for our APIs to distinguish a normal document creation from a join or transform request; it is critical that you don't modify this section, but you must send it exactly as it is returned by the API.
Make sure to pass also the options field to the creation call, it's the most important part of the process.
The response will look like this:
HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
{
"data": {
"type": "invoice",
"e_invoice": true,
...,
},
"options": {
"create_from": [
"89144071"
],
"transform": true,
"keep_copy": true
}
}
To persist the operation you must use the Create Issued Document method, using the previously returned body as input of the request; of course, you can modify it if needed, but please remember to leave the options section as it is. You can also check the Issued Document Creation Guide for more details.