### Vanilla Code Quickstart Example Source: https://developers.fattureincloud.it/docs/FAQs This example demonstrates how to get started with Fatture in Cloud APIs using vanilla HTTP requests, useful if you are not using the provided SDKs. ```HTTP POST /v1/issued_documents HTTP/1.1 Host: api.fattureincloud.it Authorization: Bearer YOUR_API_KEY Content-Type: application/json { "data": { "customer": { "name": "Mario Rossi" }, "date": "2023-01-01", "number": 1, "net_price": 100.00 } } ``` -------------------------------- ### index.js Server Setup Source: https://developers.fattureincloud.it/docs/quickstarts/js-sdk-quickstart Sets up an HTTP server to handle requests for OAuth and quickstart endpoints. It imports and uses modules from './oauth.js' and './quickstart.js'. ```javascript const http = require("http"); const url = require("url"); const oauthPath = require("./oauth.js"); //import the oauth methods const quickstart = require("./quickstart.js"); //import the quickstart const hostname = "127.0.0.1"; //set your hostname const port = 8000; //set your port const server = http.createServer(async (req, res) => { let pathname = url.parse(req.url).pathname; //url routing switch (pathname) { case "/oauth": //oauth endpoint res.end(oauthPath.getOAuthAccessToken(req, res)); break; case "/quickstart": //quickstart endpoint try { const suppliers = await quickstart.getFirstCompanySuppliers(req, res); res.end(suppliers); } catch (error) { res.statusCode = 500; res.end(JSON.stringify(error)); } break; default: res.end(); break; } res.end(); }); server.listen(port, hostname, () => { console.log(`Server running at http://${hostname}:${port}/`); }); ``` -------------------------------- ### Go GET Request Source: https://developers.fattureincloud.it/docs/authentication/manual-authentication Example of making a GET request using Go's standard http package. ```go package main import ( "io/ioutil" "log" "net/http" ) func main() { // for this example we define the token as string, but you should have obtained it in the previous steps token := "Bearer " + "a/eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyZWYiOiJZMElqc1pVWEpUZkxCSkZ3aG5iZmpSYTRJRktYTDk3ayIsImV4cCI6MTU4OTY0MjAzMX0.qn869ICUSS3_hx84ZTToMsB5slWQZjGZXGklSIiBkB4" // these parameters are usually retrieved through our APIs or stored in a DB companyId := "16" supplierId := "17" uri := "http://api-v2.local.fattureincloud.it/c/" + companyId + "/entities/suppliers/" + supplierId req, _ := http.NewRequest("GET", uri, nil) req.Header.Add("Authorization", token) client := &http.Client{} resp, err := client.Do(req) if err != nil { log.Println("Error on response.\n[ERROR] -", err) } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { log.Println("Error while reading the response bytes:", err) } log.Println(string([]byte(body))) } ``` -------------------------------- ### Create Client with JavaScript SDK Source: https://developers.fattureincloud.it/docs/guides/client-creation Example of creating a client entity using the Fatture in Cloud JavaScript SDK. Install the SDK using npm. ```javascript // NOTE: this is a partial request, please wait before sending it // in this example we are using our JS SDK // https://www.npmjs.com/package/@fattureincloud/fattureincloud-js-sdk let entity = new fattureInCloudSdk.Client(); entity.type = new fattureInCloudSdk.ClientType().company; entity.name = "Mario Rossi"; entity.vat_number = "47803200154"; entity.tax_code = "RSSMRA91M20B967Q"; entity.address_street = "Via Italia, 66"; entity.address_postal_code = "20900"; entity.address_city = "Milano"; entity.address_province = "MI"; ``` -------------------------------- ### Create Client with Python SDK Source: https://developers.fattureincloud.it/docs/guides/client-creation Example of creating a client entity using the Fatture in Cloud Python SDK. Install the SDK via pip. ```python # NOTE: this is a partial request, please wait before sending it # in this example we are using our Python SDK # https://pypi.org/project/fattureincloud-python-sdk/ entity = Client( type = ClientType("company"), name="Mario Rossi", vat_number="47803200154", tax_code="RSSMRA91M20B967Q", address_street="Via Italia, 66", address_postal_code="20900", address_city="Milano", address_province="MI" ) ``` -------------------------------- ### index.ts: Server Setup and Routing Source: https://developers.fattureincloud.it/docs/quickstarts/ts-sdk-quickstart Sets up an HTTP server with routing for OAuth and quickstart endpoints. This file handles incoming requests and directs them to the appropriate SDK functions. ```typescript import * as http from "http"; import * as url from "url"; import { getOAuthAccessToken } from "./oauth"; import { getFirstCompanySuppliers } from "./quickstart"; const hostname = "127.0.0.1"; //set your hostname const port = 8000; //set your port const server = http.createServer(async (req, res) => { var pathname = url.parse(req.url ?? "").pathname; //url routing switch (pathname) { case "/oauth": //oauth endpoint res.end(await getOAuthAccessToken(req, res)); break; case "/quickstart": //quickstart endpoint res.end(await getFirstCompanySuppliers()); break; default: res.end(); break; } res.end(); }); server.listen(port, hostname, () => { console.log(`Server running at http://${hostname}:${port}/`); }); ``` -------------------------------- ### Create Client with Go SDK Source: https://developers.fattureincloud.it/docs/guides/client-creation Example of creating a client entity using the Fatture in Cloud Go SDK. Refer to the SDK documentation for installation and usage details. ```go // NOTE: this is a partial request, please wait before sending it // in this example we are using our Go SDK // https://github.com/fattureincloud/fattureincloud-go-sdk entity := *fattureincloud.NewClient(). SetType(fattureincloud.ClientTypes.COMPANY). SetName("Mario Rossi"). SetVatNumber("47803200154"). SetTaxCode("RSSMRA91M20B967Q"). SetAddressStreet("Via Italia, 66"). SetAddressPostalCode("20900"). SetAddressCity("Milano"). SetAddressProvince("MI") ``` -------------------------------- ### Create Client with PHP SDK Source: https://developers.fattureincloud.it/docs/guides/client-creation Example of creating a client entity using the Fatture in Cloud PHP SDK. Use Composer to install the package. ```php // NOTE: this is a partial request, please wait before sending it // in this example we are using our PHP SDK // https://packagist.org/packages/fattureincloud/fattureincloud-php-sdk $entity = new Client; $entity ->setType(ClientType::COMPANY) ->setName("Mario Rossi") ->setVatNumber("47803200154") ->setTaxCode("RSSMRA91M20B967Q") ->setAddressStreet("Via Italia, 66") ->setAddressPostalCode("20900") ->setAddressCity("Milano") ->setAddressProvince("MI"); ``` -------------------------------- ### Create Client with C# SDK Source: https://developers.fattureincloud.it/docs/guides/client-creation Example of creating a client entity using the Fatture in Cloud C# SDK. Ensure you have installed the `It.FattureInCloud.Sdk` NuGet package. ```csharp // NOTE: this is a partial request, please wait before sending it // in this example we are using our C# SDK // https://www.nuget.org/packages/It.FattureInCloud.Sdk/ ModelClient entity = new ModelClient( type: ClientType.Company, name: "Mario Rossi", vatNumber: "47803200154", taxCode: "RSSMRA91M20B967Q", addressStreet: "Via Italia, 66", addressPostalCode: "20900", addressCity: "Milano", addressProvince: "MI" ); ``` -------------------------------- ### Java GET Request for Supplier using OkHttp Source: https://developers.fattureincloud.it/docs/authentication/device-code Example in Java using OkHttp to construct and execute a GET request for supplier data. It shows how to build the URL and set the Authorization header. ```java import okhttp3.HttpUrl; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; import java.io.IOException; import java.net.URL; public class Application { public static void main(String[] args) throws IOException { // for this example we define the token as string, but you should have obtained it in the previous steps String token = "a/eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyZWYiOiJZMElqc1pVWEpUZkxCSkZ3aG5iZmpSYTRJRktYTDk3ayIsImV4cCI6MTU4OTY0MjAzMX0.qn869ICUSS3_hx84ZTToMsB5slWQZjGZXGklSIiBkB4"; // these parameters are usually retrieved through our APIs or stored in a DB Integer companyId = 16; Integer supplierId = 17; URL url = new HttpUrl.Builder() .scheme("https") .host("api-v2.fattureincloud.it") .addPathSegments("c/" + companyId + "/entities/suppliers/" + supplierId) .build().url(); OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder() .header("Authorization", "Bearer " + token) .url(url) .build(); ``` -------------------------------- ### Create Invoice with Basic Data in Go Source: https://developers.fattureincloud.it/docs/guides/invoice-creation Example of creating an invoice using the Fatture in Cloud Go SDK. Refer to the SDK documentation for installation and usage details. ```go // NOTE: this is a partial request, please wait before sending it // in this example we are using our Go SDK // https://github.com/fattureincloud/fattureincloud-go-sdk entity := *fattureincloud.NewEntity(). SetId(1). SetName("Mario Rossi"). SetVatNumber("RSSMRA91M20B967Q"). SetTaxCode("RSSMRA91M20B967Q"). SetAddressStreet("Via Italia, 66"). SetAddressPostalCode("20900"). SetAddressCity("Milano"). SetAddressProvince("MI"). SetCountry("Italia") invoice := *fattureincloud.NewIssuedDocument(). SetEntity(entity). SetType(fattureincloud.IssuedDocumentTypes.INVOICE). SetDate("2022-01-20"). SetNumber(1). SetNumeration("/fatt"). SetSubject("internal subject"). SetVisibleSubject("visible subject"). // Retrieve the currencies: https://github.com/fattureincloud/fattureincloud-go-sdk/blob/master/docs/InfoApi.md#listcurrencies SetCurrency(*fattureincloud.NewCurrency().SetId("EUR")), // Retrieve the languages: https://github.com/fattureincloud/fattureincloud-go-sdk/blob/master/docs/InfoApi.md#ListLanguages SetLanguage(*fattureincloud.NewLanguage().SetCode("it").SetName("italiano")) ``` -------------------------------- ### Initialize SDK and Authentication Source: https://developers.fattureincloud.it/docs/sdks/go-sdk Import the SDK and set up authentication using your access token. This is the first step before making any API calls. ```go package main import ( "context" "encoding/json" "os" fattureincloudapi "github.com/fattureincloud/fattureincloud-go-sdk/v2/api" fattureincloud "github.com/fattureincloud/fattureincloud-go-sdk/v2/model" ) func main() { // Configure OAuth2 access token for authorization: auth := context.WithValue(context.Background(), fattureincloudapi.ContextAccessToken, "YOUR_ACCESS_TOKEN") configuration := fattureincloudapi.NewConfiguration() } ``` -------------------------------- ### C# GET Request with RestSharp Source: https://developers.fattureincloud.it/docs/authentication/manual-authentication Example of making a GET request using RestSharp in C#. Ensure you have the RestSharp NuGet package installed. ```csharp // this code uses RestSharp Client: https://restsharp.dev // you can install it with the following command: // dotnet add package RestSharp using System; using RestSharp; namespace restclient { class Program { static void Main(string[] args) { // for this example we define the token as string, but you should have obtained it in the previous steps var token = "a/eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyZWYiOiJZMElqc1pVWEpUZkxCSkZ3aG5iZmpSYTRJRktYTDk3ayIsImV4cCI6MTU4OTY0MjAzMX0.qn869ICUSS3_hx84ZTToMsB5slWQZjGZXGklSIiBkB4"; // these parameters are usually retrieved through our APIs or stored in a DB var companyId = 16; var supplierId = 17; var url = "https://api-v2.fattureincloud.it/c/" + companyId + "/entities/suppliers/" + supplierId,; var client = new RestClient(url); var request = new RestRequest(Method.GET); request.AddHeader("authorization", "Bearer " + token); IRestResponse response = client.Execute(request); Console.Write(response.Content.ToString()); } } } ``` -------------------------------- ### Customize Response with Fields (C# RestSharp) Source: https://developers.fattureincloud.it/docs/basics/customize-response C# example using RestSharp to make a GET request, specifying `fields` and `type` parameters. Ensure you have the RestSharp NuGet package installed. ```csharp // this code uses RestSharp Client: https://restsharp.dev // you can install it with the following command: // dotnet add package RestSharp using System; using RestSharp; namespace restclient { class Program { static void Main(string[] args) { // for this example we define the token as a string, but you should have obtained it in the previous steps // the token is valid for the "received_documents:r" scope needed to perform this operation var token = "YOUR_ACCESS_TOKEN"; // these parameters are usually retrieved through our APIs or stored in a DB var companyId = 17; var query = System.Web.HttpUtility.ParseQueryString(string.Empty); query.Add("fields", "type,description"); query.Add("type", "expense"); var url = "https://api-v2.fattureincloud.it/c/" + companyId + "/received_documents" + "?" + query; var client = new RestClient(url); var request = new RestRequest(Method.GET); request.AddHeader("authorization", "Bearer " + token); IRestResponse response = client.Execute(request); Console.Write(response.Content.ToString()); } } } ``` -------------------------------- ### HTTP GET Request Source: https://developers.fattureincloud.it/docs/authentication/manual-authentication Example of an HTTP GET request line. ```http GET /c/17/entities/suppliers/16 HTTP/1.1 ``` -------------------------------- ### quickstart.js SDK Usage Source: https://developers.fattureincloud.it/docs/quickstarts/js-sdk-quickstart Demonstrates how to use the Fatture in Cloud JavaScript SDK to authenticate, retrieve user companies, and fetch the list of suppliers for the first company. It reads the access token from 'token.json'. ```javascript const fattureInCloudSdk = require("@fattureincloud/fattureincloud-js-sdk"); const fs = require("fs"); async function getFirstCompanySuppliers() { try { let rawdata = fs.readFileSync(__dirname + "/token.json"); let json = JSON.parse(rawdata); let defaultClient = fattureInCloudSdk.ApiClient.instance; let OAuth2AuthenticationCodeFlow = defaultClient.authentications["OAuth2AuthenticationCodeFlow"]; OAuth2AuthenticationCodeFlow.accessToken = json["access_token"]; // Retrieve the first company id let userApiInstance = new fattureInCloudSdk.UserApi(); let userCompaniesResponse = await userApiInstance.listUserCompanies(); let firstCompanyId = userCompaniesResponse.data.companies[0].id; // Retrieve the list of the Suppliers let suppliersApiInstance = new fattureInCloudSdk.SuppliersApi(); let companySuppliers = await suppliersApiInstance.listSuppliers( firstCompanyId ); return JSON.stringify(companySuppliers.data); } catch (e) { return JSON.stringify(e); } } module.exports = { getFirstCompanySuppliers, }; ``` -------------------------------- ### Java GET Request with OkHttp Source: https://developers.fattureincloud.it/docs/authentication/manual-authentication Example of making a GET request using OkHttp in Java. ```java import okhttp3.HttpUrl; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; import java.io.IOException; import java.net.URL; public class Application { public static void main(String[] args) throws IOException { // for this example we define the token as string, but you should have obtained it in the previous steps String token = "a/eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyZWYiOiJZMElqc1pVWEpUZkxCSkZ3aG5iZmpSYTRJRktYTDk3ayIsImV4cCI6MTU4OTY0MjAzMX0.qn869ICUSS3_hx84ZTToMsB5slWQZjGZXGklSIiBkB4"; // these parameters are usually retrieved through our APIs or stored in a DB Integer companyId = 16; Integer supplierId = 17; URL url = new HttpUrl.Builder() .scheme("https") .host("api-v2.fattureincloud.it") .addPathSegments("c/" + companyId + "/entities/suppliers/" + supplierId) .build().url(); OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder() .header("Authorization", "Bearer " + token) .url(url) .build(); Response response = client.newCall(request).execute(); System.out.println(response.body().string()); } } ``` -------------------------------- ### Go SDK: List Products with Exponential Backoff Source: https://developers.fattureincloud.it/docs/guides/syncronization-using-polling This Go example demonstrates how to list products using the Fatture in Cloud SDK. It includes setting up authentication, configuring the API client, and implementing exponential backoff for retrying requests. The retrieved products are saved to a JSON Lines file. ```go // The following dependencies is required // go get github.com/fattureincloud/fattureincloud-go-sdk/ // go get github.com/cenkalti/backoff/v4 package main import ( "context" "encoding/json" "fmt" "os" backoff "github.com/cenkalti/backoff/v4" fattureincloudapi "github.com/fattureincloud/fattureincloud-go-sdk/v2/api" fattureincloud "github.com/fattureincloud/fattureincloud-go-sdk/v2/model" ) var ( f, _ = os.OpenFile("products.jsonl", os.O_APPEND|os.O_WRONLY, 0644) // The Access Token is retrieved using the "getToken" method auth = context.WithValue(context.Background(), fattureincloudapi.ContextAccessToken, getToken()) configuration = fattureincloudapi.NewConfiguration() apiClient = fattureincloudapi.NewAPIClient(configuration) companyId = int32(16) // This is the ID of the company we're working on // Here we define the parameters for the first request. nextPage = 1 attempts = 0 ) func main() { // This code should be executed periodically using a cron library or job scheduler. syncProducts() } func syncProducts() { // In this example we suppose to export the data to a JSON Lines file. // First, we cancel the content of the destination file f.Truncate(0) // Here we define the operation that retrieves the products operation := func() error { attempts++ fmt.Printf("Attempt: %d\n", attempts) // In this example we're using the Products API // Here we execute the actual SDK method resp, _, err := apiClient.ProductsAPI.ListProducts(auth, companyId).Page(int32(nextPage)).PerPage(5).Execute() if resp != nil { // We check if there are other pages to retrieve if resp.NextPageUrl.Get() == nil { nextPage = 0 } else { nextPage++ } // We write the products of this page to the file // "data" contains an array of products appendProductsToFile(resp.Data) } return err } // For all the pages for nextPage != 0 { attempts = 0 // We call the operation function using Exponential Backoff err := backoff.Retry(operation, backoff.NewExponentialBackOff()) if err != nil { fmt.Fprintf(os.Stderr, "Error %v\n", err) return } } f.Close() fmt.Println("products succesfully retrieved and saved in ./products.jsonl") } // In this function we append the products in the JSON Lines file. // You can replace this function to perform the operations you need. // For example, you can build SQL queries or call a third-party API using the retrieved products. func appendProductsToFile(products []fattureincloud.Product) { // For each product in the array for _, element := range products { // We obtain the related JSON and append it to the file as single line jsonStr, _ := json.Marshal(element) f.WriteString(string(jsonStr) + "\n") } } // This is just a mock: this function should contain the code to retrieve the Access Token func getToken() string { return "YOUR_TOKEN" } ``` -------------------------------- ### cURL GET Request Source: https://developers.fattureincloud.it/docs/authentication/manual-authentication Example of making a GET request using cURL with an Authorization header. ```bash curl --request GET \ --url https://api-v2.fattureincloud.it/c/17/entities/suppliers/16 \ --header 'Accept: application/json' \ --header 'Authorization: Bearer a/eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyZWYiOiJZMElqc1pVWEpUZkxCSkZ3aG5iZmpSYTRJRktYTDk3ayIsImV4cCI6MTU4OTY0MjAzMX0.qn869ICUSS3_hx84ZTToMsB5slWQZjGZXGklSIiBkB4' ``` -------------------------------- ### Fatture in Cloud SDK Sample (quickstart.php) Source: https://developers.fattureincloud.it/docs/quickstarts/php-sdk-quickstart This script demonstrates how to use the Fatture in Cloud PHP SDK to retrieve company information and list suppliers. It requires a valid OAuth access token stored in the session. ```php setAccessToken($accessToken); $userApi = new FattureInCloud\Api\UserApi( new GuzzleHttp\Client(), $config ); $suppliersApi = new FattureInCloud\Api\SuppliersApi( new GuzzleHttp\Client(), $config ); try { // Retrieve the first company id $companies = $userApi->listUserCompanies(); $firstCompanyId = $companies->getData()->getCompanies()[0]->getId(); // Retrieve the list of first 10 Suppliers for the selected company $suppliers = $suppliersApi->listSuppliers($firstCompanyId, null, null, null, 1, 10); foreach ($suppliers->getData() as $supplier) { $name = $supplier->getName(); echo("$name n"); } } catch (Exception $e) { echo 'Exception when calling the API: ', $e->getMessage(), PHP_EOL; } ?> ``` -------------------------------- ### Run the Sample Application Source: https://developers.fattureincloud.it/docs/quickstarts/ts-sdk-quickstart Command to execute the TypeScript server application. This starts the local server for testing the SDK integration. ```bash ts-node index.ts ``` -------------------------------- ### Get Supplier Example Source: https://developers.fattureincloud.it/docs/authentication/device-code This example shows how to retrieve supplier information using the API. It requires the 'entity.suppliers:r' scope to be authorized. ```APIDOC ## GET /c/{company_id}/entities/suppliers/{supplier_id} ### Description Retrieves a specific supplier's information. ### Method GET ### Endpoint /c/{company_id}/entities/suppliers/{supplier_id} ### Parameters #### Path Parameters - **company_id** (integer) - Required - The ID of the company. - **supplier_id** (integer) - Required - The ID of the supplier. #### Headers - **Authorization** (string) - Required - Bearer token for authentication. Example: `Bearer YOUR_ACCESS_TOKEN` - **Accept** (string) - Required - `application/json` ### Request Example ``` curl --request GET \ --url https://api-v2.fattureincloud.it/c/17/entities/suppliers/16 \ --header 'Accept: application/json' \ --header 'Authorization: Bearer a/eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyZWYiOiJZMElqc1pVWEpUZkxCSkZ3aG5iZmpSYTRJRktYTDk3ayIsImV4cCI6MTU4OTY0MjAzMX0.qn869ICUSS3_hx84ZTToMsB5slWQZjGZXGklSIiBkB4' ``` ### Response #### Success Response (200) - **data** (object) - Contains the supplier details. #### Response Example ```json { "data": { "id": 17, "name": "Supplier Name", "type": "supplier", "contact_name": "Contact Person", "contact_email": "contact@example.com", "contact_phone": "123456789", "fiscal_code": "12345678901", "vat_number": "IT12345678901", "country": "IT", "country_iso": "IT", "city": "Rome", "postal_code": "00100", "Примечания": "Some notes" } } ``` ``` -------------------------------- ### Invoice Totals Response Example Source: https://developers.fattureincloud.it/docs/guides/invoice-totals This is an example of a successful response from the Get New Issued Document Totals method, showing calculated invoice totals. ```json { "data": { "amount_net": 74, "amount_global_cassa_taxable": 74, "taxable_amount": 74, "vat_list": { "21": { "amount_net": 74, "amount_vat": 15.54 } }, "amount_vat": 15.54, "amount_gross": 89.54, "amount_enasarco_taxable": 0, "amount_due": 89.54, "amount_due_discount": null, "payments_sum": 0 } } ``` -------------------------------- ### Run the PHP Development Server Source: https://developers.fattureincloud.it/docs/quickstarts/php-sdk-quickstart Start a local development server to run the PHP application. This command is used to serve the `oauth.php` and `quickstart.php` files. ```bash php -S localhost:8000 ``` -------------------------------- ### Create Client with Ruby SDK Source: https://developers.fattureincloud.it/docs/guides/client-creation This Ruby snippet shows how to create a client. Configure your access token and company ID before execution. ```ruby require 'time' require 'fattureincloud_ruby_sdk' FattureInCloud_Ruby_Sdk.configure do |config| config.access_token = 'YOUR ACCESS TOKEN' end api_instance = FattureInCloud_Ruby_Sdk::ClientsApi.new company_id = 12345 entity = FattureInCloud_Ruby_Sdk::Client.new( type: FattureInCloud_Ruby_Sdk::ClientType::COMPANY, name: "Mario Rossi", vat_number: "47803200154", tax_code: "RSSMRA91M20B967Q", address_street: "Via Italia, 66", address_postal_code: "20900", address_city: "Milano", address_province: "MI" ) opts = { create_client_request: FattureInCloud_Ruby_Sdk::CreateClientRequest.new(data: entity) } begin result = api_instance.create_client(company_id, opts) p result rescue FattureInCloud_Ruby_Sdk::ApiError => e puts "Error when calling ClientsApi->create_client: #{e}" end ``` -------------------------------- ### Go GET Request for Supplier Source: https://developers.fattureincloud.it/docs/authentication/device-code Example in Go for making a GET request to retrieve supplier information. It demonstrates setting the Authorization header and reading the response body. ```go package main import ( "io/ioutil" "log" "net/http" ) func main() { // for this example we define the token as string, but you should have obtained it in the previous steps token := "Bearer " + "a/eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyZWYiOiJZMElqc1pVWEpUZkxCSkZ3aG5iZmpSYTRJRktYTDk3ayIsImV4cCI6MTU4OTY0MjAzMX0.qn869ICUSS3_hx84ZTToMsB5slWQZjGZXGklSIiBkB4" // these parameters are usually retrieved through our APIs or stored in a DB companyId := "16" supplierId := "17" uri := "http://api-v2.local.fattureincloud.it/c/" + companyId + "/entities/suppliers/" + supplierId req, _ := http.NewRequest("GET", uri, nil) req.Header.Add("Authorization", token) client := &http.Client{} resp, err := client.Do(req) if err != nil { log.Println("Error on response.\n[ERROR] -", err) } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { log.Println("Error while reading the response bytes:", err) } log.Println(string([]byte(body))) } ``` -------------------------------- ### Customize Response with Fields (HTTP GET) Source: https://developers.fattureincloud.it/docs/basics/customize-response Example of an HTTP GET request URL that specifies desired fields (`type`, `description`) and a filter (`type=expense`) in the query string. ```http GET https://api-v2.fattureincloud.it/c/{companyId}/received_documents?type=expense&fields=type,description ``` -------------------------------- ### Create Client with TypeScript SDK Source: https://developers.fattureincloud.it/docs/guides/client-creation Use this TypeScript example to create a client. Remember to set your access token and company ID. ```typescript import { Configuration, ClientsApi, Client, ClientType, CreateClientRequest, } from "@fattureincloud/fattureincloud-ts-sdk"; const apiConfig = new Configuration({ accessToken: "YOUR ACCESS TOKEN", }); let apiInstance = new ClientsApi(apiConfig); let companyId = 12345; let entity: Client = {}; entity.type = ClientType.Company; entity.name = "Mario Rossi"; entity.vat_number = "47803200154"; entity.tax_code = "RSSMRA91M20B967Q"; entity.address_street = "Via Italia, 66"; entity.address_postal_code = "20900"; entity.address_city = "Milano"; entity.address_province = "MI"; let createClientRequest: CreateClientRequest = { data: entity, }; apiInstance.apiInstance.createClient(companyId, createClientRequest).then( (data) => { console.log(data); }, (error) => { console.error(error); } ); ``` -------------------------------- ### C# Example to Obtain Access Token Source: https://developers.fattureincloud.it/docs/authentication/code-flow/vanilla-code This C# example uses the RestSharp library to make a POST request to the /oauth/token endpoint. Ensure you have installed the RestSharp NuGet package. ```csharp // this code uses RestSharp Client: https://restsharp.dev // you can install it with the following command: // dotnet add package RestSharp using System; using RestSharp; namespace restclient { class Program { static void Main(string[] args) { // for this example we define the code as string, but you should have obtained it in the previous steps var code = "c/eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyZWYiOiJDRENzRVlGaE5YZ0NkWDhldW1GRnVxcllIUDdYTTk2dyIsImV4cCI6MTU4OTQ2NjYzNn0.v9yyzsdC50mRF8gue46WjXqO2ADfSPZH9SZc-QTHO54"; var baseUrl = "https://api-v2.fattureincloud.it"; var tokenPath = "/oauth/token"; var redirectUrl = "https://www.yourapplication.com/redirect"; // the endpoint you exposed var clientId = "CLIENT_ID"; // your client id var clientSecret = "CLIENT_SECRET"; // your client secret var params = new { grant_type = "authorization_code", client_id = clientId, client_secret = clientSecret, redirect_uri = redirectUrl, code = code }; var client = new RestClient(baseUrl + tokenPath); var request = new RestRequest(Method.POST); request.AddHeader("content-type", "application/json"); request.AddJsonBody(params); IRestResponse response = client.Execute(request); Console.Write(response.Content.ToString()); } } } ``` -------------------------------- ### cURL GET Request for Supplier Source: https://developers.fattureincloud.it/docs/authentication/device-code Example of making a GET request to retrieve supplier information using cURL. Ensure the Authorization header contains a valid Bearer token. ```bash curl --request GET \ --url https://api-v2.fattureincloud.it/c/17/entities/suppliers/16 \ --header 'Accept: application/json' \ --header 'Authorization: Bearer a/eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyZWYiOiJZMElqc1pVWEpUZkxCSkZ3aG5iZmpSYTRJRktYTDk3ayIsImV4cCI6MTU4OTY0MjAzMX0.qn869ICUSS3_hx84ZTToMsB5slWQZjGZXGklSIiBkB4' ``` -------------------------------- ### Layout Page for Quickstart App Source: https://developers.fattureincloud.it/docs/quickstarts/csharp-sdk-quickstart This HTML layout file defines the basic structure for the Quickstart application. It includes essential meta tags and a container for the main content, which will be rendered by the @RenderBody() directive. ```html