<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Nicola Iarocci</title>
    <description>The latest articles on DEV Community by Nicola Iarocci (@nicolaiarocci).</description>
    <link>https://dev.to/nicolaiarocci</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F54833%2F6c55f887-2e94-4eac-8e30-7163eb281a53.png</url>
      <title>DEV Community: Nicola Iarocci</title>
      <link>https://dev.to/nicolaiarocci</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nicolaiarocci"/>
    <language>en</language>
    <item>
      <title>Come inviare fatture a SDI FatturaPA in C#</title>
      <dc:creator>Nicola Iarocci</dc:creator>
      <pubDate>Wed, 01 Oct 2025 08:40:33 +0000</pubDate>
      <link>https://dev.to/nicolaiarocci/come-inviare-fatture-a-sdi-fatturapa-in-c-5gkp</link>
      <guid>https://dev.to/nicolaiarocci/come-inviare-fatture-a-sdi-fatturapa-in-c-5gkp</guid>
      <description>&lt;p&gt;In questo tutorial creiamo una semplice applicazione C# per spedire fatture a SDI FatturaPA. L'app si connette e autentica con &lt;a href="https://invoicetronic.com" rel="noopener noreferrer"&gt;Invoicetronic API&lt;/a&gt;, quindi invia le fatture ai loro destinatari.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisiti
&lt;/h2&gt;

&lt;p&gt;Presupponiamo che questi prerequisiti siano soddisfatti:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Il .NET SDK è stato &lt;a href="https://dotnet.microsoft.com/en-us/download" rel="noopener noreferrer"&gt;scaricato&lt;/a&gt; e &lt;a href="https://learn.microsoft.com/en-us/dotnet/core/install/" rel="noopener noreferrer"&gt;installato&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Hai ottenuto una &lt;a href="https://invoicetronic.com/en/docs/apikeys/" rel="noopener noreferrer"&gt;Chiave API&lt;/a&gt; attiva&lt;/li&gt;
&lt;li&gt;Ti sei &lt;a href="https://invoicetronic.com/docs/prerequisites/#registrati-con-agenzia-delle-entrate" rel="noopener noreferrer"&gt;registrato presso l'Agenzia delle Entrate&lt;/a&gt; (necessario per l'ambiente di produzione)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Utilizziamo lo strumento &lt;a href="https://learn.microsoft.com/en-us/dotnet/core/tools/" rel="noopener noreferrer"&gt;&lt;code&gt;dotnet&lt;/code&gt;&lt;/a&gt; e &lt;a href="https://code.visualstudio.com" rel="noopener noreferrer"&gt;VS Code&lt;/a&gt; in quanto sono disponibili sulla maggior parte dei sistemi, ma puoi seguire con il tuo IDE preferito (Visual Studio, Rider, ecc.) se preferisci.&lt;/p&gt;

&lt;p&gt;Per un'esperienza C# ottimale in VS Code, assicurati che l'estensione &lt;a href="https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csdevkit" rel="noopener noreferrer"&gt;C# Dev Kit&lt;/a&gt; sia installata e abilitata. Per ulteriori informazioni, consulta &lt;a href="https://code.visualstudio.com/docs/csharp/get-started" rel="noopener noreferrer"&gt;Iniziare con C# in VS Code&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Crea l'app
&lt;/h3&gt;

&lt;p&gt;Il primo passo è creare l'applicazione:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dotnet new console &lt;span class="nt"&gt;-n&lt;/span&gt; send
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Il comando ha creato un nuovo progetto C# chiamato "quickstart" in una directory con lo stesso nome. Entra in quella directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;send
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Installa l'SDK
&lt;/h3&gt;

&lt;p&gt;Una volta nella directory quickstart, installa l'SDK C#:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; dotnet add package Invoicetronic.Sdk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Una volta fatto, apri VS Code nella directory corrente:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;code &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Clicca sul file Program.cs per vedere il suo contenuto nel pannello destro di VS Code.&lt;/p&gt;

&lt;h3&gt;
  
  
  Configura l'SDK
&lt;/h3&gt;

&lt;p&gt;Sostituisci il contenuto predefinito di Program.cs con il seguente:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;Invoicetronic.Sdk.Api&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;Invoicetronic.Sdk.Client&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;Invoicetronic.Sdk.Model&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Configura l'SDK.&lt;/span&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;config&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;Configuration&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;BasePath&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"https://api.invoicetronic.com/v1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;Username&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"LA TUA CHIAVE API DI TEST (inizia con ik_test_)"&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Come puoi vedere, inizializziamo un'istanza di &lt;code&gt;Configuration&lt;/code&gt; impostando il percorso base dell'API e la tua &lt;strong&gt;chiave API di test&lt;/strong&gt; (non quella live). Nota come &lt;strong&gt;utilizziamo la proprietà &lt;code&gt;Username&lt;/code&gt; per impostare la chiave API&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Quando crei il tuo account, ottieni una coppia di chiavi API. Una è la chiave di test per la &lt;a href="https://invoicetronic.com/en/docs/sandbox/" rel="noopener noreferrer"&gt;Sandbox API&lt;/a&gt;, e l'altra è quella live dell'API. Puoi distinguerle perché la prima inizia con &lt;code&gt;ik_test_&lt;/code&gt;, mentre la seconda inizia con &lt;code&gt;ik_live_&lt;/code&gt;. In questo tutorial, &lt;strong&gt;usa sempre la chiave di test&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Invia una fattura
&lt;/h3&gt;

&lt;p&gt;Siamo pronti per effettuare una richiesta. Vogliamo inviare una fattura allo SDI. Aggiungi il seguente codice:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;
&lt;span class="c1"&gt;// Invia una fattura&lt;/span&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;filePath&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"/qualche/percorso/file/nomefile.xml"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;metaData&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;Dictionary&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;"internal_id"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"123"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;"created_with"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"myapp"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;"some_other_custom_data"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"value"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;sendApi&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;SendApi&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;try&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;sentInvoice&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;sendApi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;SendPostAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;Send&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;FileName&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetFileName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;filePath&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="n"&gt;Payload&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;File&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ReadAllText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;filePath&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="n"&gt;MetaData&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;metaData&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;$"La fattura è stata inviata con successo, ora ha l'Id univoco &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;sentInvoice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Id&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s"&gt;."&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ApiException&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;$"&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Message&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s"&gt; - &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ErrorCode&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Passa al terminale poi digita:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dotnet run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Dovresti ottenere un output simile a questo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;La fattura nomefile.xml è stata inviata con successo, ora ha l&lt;span class="s1"&gt;'Id univoco 123.
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Cosa abbiamo imparato
&lt;/h3&gt;

&lt;p&gt;In questo esempio, abbiamo imparato diverse cose.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Dobbiamo configurare l'SDK impostando sia la proprietà &lt;code&gt;BasePath&lt;/code&gt; che &lt;code&gt;Username&lt;/code&gt;, quest'ultima inizializzata con la chiave API.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Dobbiamo istanziare una classe che rappresenta l'endpoint con cui vogliamo lavorare. In questo caso, sfruttiamo &lt;code&gt;SendApi&lt;/code&gt; per inviare fatture. Le classi endpoint come &lt;code&gt;SendApi&lt;/code&gt; offrono metodi per interagire con la loro entità target. Chiamiamo &lt;code&gt;InvoiceV1SendPosttAsync&lt;/code&gt; per inviare una fattura.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;La classe &lt;code&gt;Send&lt;/code&gt; espone proprietà preziose come &lt;code&gt;FileName&lt;/code&gt;, &lt;code&gt;MetaData&lt;/code&gt; e &lt;code&gt;Payload&lt;/code&gt;. Quest'ultima contiene il contenuto della fattura, mentre &lt;code&gt;MetaData&lt;/code&gt; è opzionale e associa dati personalizzati al documento.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>programming</category>
      <category>dotnet</category>
      <category>csharp</category>
      <category>tutorials</category>
    </item>
    <item>
      <title>Come scaricare fatture da SDI FatturaPA in C#</title>
      <dc:creator>Nicola Iarocci</dc:creator>
      <pubDate>Wed, 01 Oct 2025 08:40:11 +0000</pubDate>
      <link>https://dev.to/nicolaiarocci/come-scaricare-fatture-da-sdi-fatturapa-in-c-2a6m</link>
      <guid>https://dev.to/nicolaiarocci/come-scaricare-fatture-da-sdi-fatturapa-in-c-2a6m</guid>
      <description>&lt;p&gt;In questo tutorial creiamo una semplice applicazione C# per scaricare (download) fatture da SDI FatturaPA. L'app si connette e autentica con &lt;a href="https://invoicetronic.com" rel="noopener noreferrer"&gt;Invoicetronic API&lt;/a&gt;, quindi scarica le nuove fatture di acquisto.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisiti
&lt;/h2&gt;

&lt;p&gt;Presupponiamo che questi prerequisiti siano soddisfatti:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Il .NET SDK è stato &lt;a href="https://dotnet.microsoft.com/en-us/download" rel="noopener noreferrer"&gt;scaricato&lt;/a&gt; e &lt;a href="https://learn.microsoft.com/en-us/dotnet/core/install/" rel="noopener noreferrer"&gt;installato&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Hai ottenuto una &lt;a href="https://invoicetronic.com/en/docs/apikeys/" rel="noopener noreferrer"&gt;Chiave API&lt;/a&gt; attiva&lt;/li&gt;
&lt;li&gt;Ti sei &lt;a href="https://invoicetronic.com/docs/prerequisites/#registrati-con-agenzia-delle-entrate" rel="noopener noreferrer"&gt;registrato presso l'Agenzia delle Entrate&lt;/a&gt; (necessario per l'ambiente di produzione)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Utilizziamo lo strumento &lt;a href="https://learn.microsoft.com/en-us/dotnet/core/tools/" rel="noopener noreferrer"&gt;&lt;code&gt;dotnet&lt;/code&gt;&lt;/a&gt; e &lt;a href="https://code.visualstudio.com" rel="noopener noreferrer"&gt;VS Code&lt;/a&gt; in quanto sono disponibili sulla maggior parte dei sistemi, ma puoi seguire con il tuo IDE preferito (Visual Studio, Rider, ecc.) se preferisci.&lt;/p&gt;

&lt;p&gt;Per un'esperienza C# ottimale in VS Code, assicurati che l'estensione &lt;a href="https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csdevkit" rel="noopener noreferrer"&gt;C# Dev Kit&lt;/a&gt; sia installata e abilitata. Per ulteriori informazioni, consulta &lt;a href="https://code.visualstudio.com/docs/csharp/get-started" rel="noopener noreferrer"&gt;Iniziare con C# in VS Code&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Crea l'app
&lt;/h2&gt;

&lt;p&gt;Il primo passo è creare l'applicazione:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dotnet new console &lt;span class="nt"&gt;-n&lt;/span&gt; receive
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Il comando ha creato un nuovo progetto C# chiamato "receive" in una directory con lo stesso nome. Entra in quella directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;receive
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Installa l'SDK
&lt;/h3&gt;

&lt;p&gt;Una volta nella directory receive, installa l'SDK C#:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; dotnet add package Invoicetronic.Sdk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Una volta fatto, apri VS Code nella directory corrente:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;code &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Clicca sul file Program.cs per vedere il suo contenuto nel pannello destro di VS Code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Configura l'SDK
&lt;/h2&gt;

&lt;p&gt;Sostituisci il contenuto predefinito di Program.cs con il seguente:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;Invoicetronic.Sdk.Api&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;Invoicetronic.Sdk.Client&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;static&lt;/span&gt; &lt;span class="n"&gt;Invoicetronic&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Sdk&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Receive&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Configura l'SDK.&lt;/span&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;config&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;Configuration&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;BasePath&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"https://api.invoicetronic.com/v1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;Username&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"LA TUA CHIAVE API DI TEST (inizia con ik_test_)"&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Come puoi vedere, inizializziamo un'istanza di &lt;code&gt;Configuration&lt;/code&gt; impostando il percorso base dell'API e la tua &lt;strong&gt;chiave API di test&lt;/strong&gt; (non quella live). Nota come &lt;strong&gt;utilizziamo la proprietà &lt;code&gt;Username&lt;/code&gt; per impostare la chiave API&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Quando crei il tuo account, ottieni una coppia di chiavi API. Una è la chiave di test per la &lt;a href="https://invoicetronic.com/en/docs/sandbox/" rel="noopener noreferrer"&gt;Sandbox API&lt;/a&gt;, e l'altra è quella live dell'API. Puoi distinguerle perché la prima inizia con &lt;code&gt;ik_test_&lt;/code&gt;, mentre la seconda inizia con &lt;code&gt;ik_live_&lt;/code&gt;. In questo tutorial, &lt;strong&gt;usa sempre la chiave di test&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Scarica le fatture
&lt;/h2&gt;

&lt;p&gt;Siamo pronti per effettuare una richiesta. Vogliamo scaricare nuove fatture dei fornitori che potrebbero essere disponibili dallo SDI. Aggiungi queste righe:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;
&lt;span class="c1"&gt;// Scarica le fatture non lette.&lt;/span&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;receiveApi&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;ReceiveApi&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;try&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;inboundInvoices&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;receiveApi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ReceiveGetAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;unread&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="k"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;includePayload&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="k"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;$"Ricevute &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;inboundInvoices&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Count&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s"&gt; fatture"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;invoice&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;inboundInvoices&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;invoice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Encoding&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;EncodingEnum&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Xml&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;File&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteAllText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;invoice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;FileName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;invoice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Payload&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
                &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;EncodingEnum&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Base64&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;File&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteAllBytes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;invoice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;FileName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Convert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;FromBase64String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;invoice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Payload&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
                &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;$"Scaricato &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;invoice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;FileName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s"&gt; da un fornitore con Partita IVA &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;invoice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Prestatore&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ApiException&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;$"&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Message&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s"&gt; - &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ErrorCode&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Impostiamo &lt;code&gt;includePayload: true&lt;/code&gt; per recuperare il contenuto effettivo della fattura nella proprietà &lt;code&gt;Payload&lt;/code&gt;. Senza questo parametro, il campo &lt;code&gt;Payload&lt;/code&gt; sarebbe &lt;code&gt;null&lt;/code&gt; per impostazione predefinita, il che aumenta le prestazioni e riduce le dimensioni della risposta quando hai bisogno solo dei metadati.&lt;/p&gt;

&lt;p&gt;Passa al terminale poi digita:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dotnet run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Dovresti ottenere un output simile a questo:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Ricevute 3 fatture
Scaricato file1.xml da un fornitore con Partita IVA IT06157670966
Scaricato file2.xml.p7m da un fornitore con Partita IVA IT01280270057
Scaricato file3.xml.p7m da un fornitore con Partita IVA IT01280270057
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I file sono nella directory corrente, pronti per essere ispezionati.&lt;/p&gt;

&lt;h3&gt;
  
  
  Cosa abbiamo imparato
&lt;/h3&gt;

&lt;p&gt;In questo esempio, abbiamo imparato diverse cose.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Dobbiamo configurare l'SDK impostando sia la proprietà &lt;code&gt;BasePath&lt;/code&gt; che &lt;code&gt;Username&lt;/code&gt;, quest'ultima inizializzata con la chiave API.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Dobbiamo istanziare una classe che rappresenta l'endpoint con cui vogliamo lavorare. In questo caso, sfruttiamo &lt;code&gt;ReceiveApi&lt;/code&gt; per scaricare le fatture in arrivo.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Le classi endpoint come &lt;code&gt;ReceiveApi&lt;/code&gt; offrono metodi per interagire con la loro entità target. Chiamiamo &lt;code&gt;ReceiveGetAsync&lt;/code&gt; per recuperare le fatture. Poiché vogliamo solo fatture nuove e non lette, passiamo &lt;code&gt;unread: true&lt;/code&gt;. Passiamo anche &lt;code&gt;includePayload: true&lt;/code&gt; per recuperare il contenuto effettivo della fattura (se esegui l'esempio una seconda volta, probabilmente non riceverai alcuna fattura a meno che non ne sia arrivata qualcuna).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;La classe &lt;code&gt;Receive&lt;/code&gt; espone proprietà preziose come &lt;code&gt;Encoding&lt;/code&gt;, &lt;code&gt;FileName&lt;/code&gt; e &lt;code&gt;Payload&lt;/code&gt;. Quest'ultima contiene il contenuto della fattura, come testo normale o codificato in Base64, come descritto da &lt;code&gt;Encoding&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>programming</category>
      <category>dotnet</category>
      <category>csharp</category>
      <category>tutorials</category>
    </item>
    <item>
      <title>How to upload SDI FatturaPA invoices with C#</title>
      <dc:creator>Nicola Iarocci</dc:creator>
      <pubDate>Wed, 01 Oct 2025 08:39:13 +0000</pubDate>
      <link>https://dev.to/nicolaiarocci/how-to-upload-sdi-fatturapa-invoices-with-c-2kl1</link>
      <guid>https://dev.to/nicolaiarocci/how-to-upload-sdi-fatturapa-invoices-with-c-2kl1</guid>
      <description>&lt;p&gt;In this tutorial we build a simple C# console application that connects and authenticates with the &lt;a href="https://invoicetronic.com/en" rel="noopener noreferrer"&gt;Invoicetronic API&lt;/a&gt; and uploads outbound invoices to SDI FatturaPA.&lt;/p&gt;

&lt;p&gt;Before continuing, make sure all the prerequisites below are met.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;We assume that these prerequisites are met:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The .NET SDK has been &lt;a href="https://dotnet.microsoft.com/en-us/download" rel="noopener noreferrer"&gt;downloaded&lt;/a&gt; and &lt;a href="https://learn.microsoft.com/en-us/dotnet/core/install/" rel="noopener noreferrer"&gt;installed&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;You obtained an active &lt;a href="https://invoicetronic.com/en/docs/apikeys/" rel="noopener noreferrer"&gt;API Key&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;You &lt;a href="https://invoicetronic.com/en/docs/prerequisites/#register-with-the-italian-revenue-service" rel="noopener noreferrer"&gt;registered with the Italian Revenue Service&lt;/a&gt; (needed for the live environment)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We use the &lt;a href="https://learn.microsoft.com/en-us/dotnet/core/tools/" rel="noopener noreferrer"&gt;&lt;code&gt;dotnet&lt;/code&gt;&lt;/a&gt; tool and &lt;a href="https://code.visualstudio.com" rel="noopener noreferrer"&gt;VS Code&lt;/a&gt; as they are available on most systems, but you can follow along with your favourite IDE (Visual Studio, Rider, etc.) if you prefer.&lt;/p&gt;

&lt;p&gt;For an optimal C# experience in VS Code, you want to ensure that the &lt;a href="https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csdevkit" rel="noopener noreferrer"&gt;C# Dev Kit&lt;/a&gt; extension is installed and enabled. For more information, see &lt;a href="https://code.visualstudio.com/docs/csharp/get-started" rel="noopener noreferrer"&gt;Getting Started with C# in VS Code&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create the app
&lt;/h2&gt;

&lt;p&gt;The first step is to create the application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dotnet new console &lt;span class="nt"&gt;-n&lt;/span&gt; send
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The command created a new C# project named "quickstart" in a directory with the same name. Step into that directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;send
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Install the SDK
&lt;/h2&gt;

&lt;p&gt;Once in the quickstart directory, install the C# SDK:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; dotnet add package Invoicetronic.Sdk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once that's done, open VS Code in the current directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;code &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Click on the Program.cs file to see its contents in VS Code right pane.&lt;/p&gt;

&lt;h2&gt;
  
  
  Configure the SDK
&lt;/h2&gt;

&lt;p&gt;Replace Program.cs default content with the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;Invoicetronic.Sdk.Api&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;Invoicetronic.Sdk.Client&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;Invoicetronic.Sdk.Model&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Configure the SDK.&lt;/span&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;config&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;Configuration&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;BasePath&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"https://api.invoicetronic.com/v1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;Username&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"YOUR TEST API KEY (starts with ik_test_)"&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, we initialize a &lt;code&gt;Configuration&lt;/code&gt; instance by setting the API's base path and your &lt;strong&gt;test API Key&lt;/strong&gt; (not the live one). Notice how &lt;strong&gt;we use the &lt;code&gt;Username&lt;/code&gt; property to set the API Key&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;When you create your account, you obtain a pair of API Keys. One is the test key for the &lt;a href="https://invoicetronic.com/en/docs/sandbox/" rel="noopener noreferrer"&gt;API Sandbox&lt;/a&gt;, and the other is the live API's. You can tell the difference because the former starts with &lt;code&gt;ik_test_&lt;/code&gt;, while the latter begins with &lt;code&gt;ik_live_&lt;/code&gt;. In this tutorial, &lt;strong&gt;always use the test key&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Send an invoice
&lt;/h2&gt;

&lt;p&gt;We are ready to make a request. We want to send an invoice to the SDI. Add the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;
&lt;span class="c1"&gt;// Send an invoice&lt;/span&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;filePath&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"/some/file/path/filename.xml"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;metaData&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;Dictionary&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;"internal_id"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"123"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;"created_with"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"myapp"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s"&gt;"some_other_custom_data"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"value"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;sendApi&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;SendApi&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;try&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;sentInvoice&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;sendApi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;SendPostAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;Send&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;FileName&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;GetFileName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;filePath&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="n"&gt;Payload&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;File&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ReadAllText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;filePath&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="n"&gt;MetaData&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;metaData&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;$"The invoice was sent successfully, it now has the unique Id of &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;sentInvoice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Id&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s"&gt;."&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ApiException&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;$"&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Message&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s"&gt; - &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ErrorCode&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Switch to the terminal and type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dotnet run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should obtain an output similar to this one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;The invoice filename.xml was sent successfully, it now has the unique Id of 123.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What we learned
&lt;/h2&gt;

&lt;p&gt;In this example, we learned several things.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;We must configure the SDK by setting both the &lt;code&gt;BasePath&lt;/code&gt; and &lt;code&gt;Username&lt;/code&gt; properties, the latter initialized with the API key.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We must instantiate a class representing the endpoint we want to work with. In this case, we leverage &lt;code&gt;SendApi&lt;/code&gt; to send invoices. Endpoint classes like &lt;code&gt;SendApi&lt;/code&gt; offer methods for interacting with their target entity. We call &lt;code&gt;InvoiceV1SendPosttAsync&lt;/code&gt; to send an invoice.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;code&gt;Send&lt;/code&gt; class exposes valuable properties such as &lt;code&gt;FileName&lt;/code&gt;, &lt;code&gt;MetaData&lt;/code&gt;, and &lt;code&gt;Payload&lt;/code&gt;. The last one contains the invoice content, while &lt;code&gt;MetaData&lt;/code&gt; is optional and binds custom data to the document.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>programming</category>
      <category>tutorials</category>
      <category>dotnet</category>
      <category>csharp</category>
    </item>
    <item>
      <title>How to download SDI FatturaPA invoices with C#</title>
      <dc:creator>Nicola Iarocci</dc:creator>
      <pubDate>Wed, 01 Oct 2025 08:38:27 +0000</pubDate>
      <link>https://dev.to/nicolaiarocci/how-to-download-sdi-fatturapa-invoices-with-c-fo9</link>
      <guid>https://dev.to/nicolaiarocci/how-to-download-sdi-fatturapa-invoices-with-c-fo9</guid>
      <description>&lt;p&gt;In this tutorial we build a simple C# console application that connects and authenticates with the &lt;a href="https://invoicetronic.com/en" rel="noopener noreferrer"&gt;Invoicetronic API&lt;/a&gt; and downloads incoming invoices from SDI FatturaPA.&lt;/p&gt;

&lt;p&gt;Before continuing, make sure all the prerequisites below are met.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;We assume that these prerequisites are met:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The .NET SDK has been &lt;a href="https://dotnet.microsoft.com/en-us/download" rel="noopener noreferrer"&gt;downloaded&lt;/a&gt; and &lt;a href="https://learn.microsoft.com/en-us/dotnet/core/install/" rel="noopener noreferrer"&gt;installed&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;You obtained an active &lt;a href="https://invoicetronic.com/en/docs/apikeys/" rel="noopener noreferrer"&gt;API Key&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;You &lt;a href="https://invoicetronic.com/en/docs/prerequisites/#register-with-the-italian-revenue-service" rel="noopener noreferrer"&gt;registered with the Italian Revenue Service&lt;/a&gt; (needed for the live environment)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We use the &lt;a href="https://learn.microsoft.com/en-us/dotnet/core/tools/" rel="noopener noreferrer"&gt;&lt;code&gt;dotnet&lt;/code&gt;&lt;/a&gt; tool and &lt;a href="https://code.visualstudio.com" rel="noopener noreferrer"&gt;VS Code&lt;/a&gt; as they are available on most systems, but you can follow along with your favourite IDE (Visual Studio, Rider, etc.) if you prefer.&lt;/p&gt;

&lt;p&gt;For an optimal C# experience in VS Code, you want to ensure that the &lt;a href="https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csdevkit" rel="noopener noreferrer"&gt;C# Dev Kit&lt;/a&gt; extension is installed and enabled. For more information, see &lt;a href="https://code.visualstudio.com/docs/csharp/get-started" rel="noopener noreferrer"&gt;Getting Started with C# in VS Code&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create the app
&lt;/h2&gt;

&lt;p&gt;The first step is to create the application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dotnet new console &lt;span class="nt"&gt;-n&lt;/span&gt; receive
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The command created a new C# project named "quickstart" in a directory with the same name. Step into that directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;receive
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Install the SDK
&lt;/h2&gt;

&lt;p&gt;Once in the quickstart directory, install the C# SDK:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt; dotnet add package Invoicetronic.Sdk
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once that's done, open VS Code in the current directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;code &lt;span class="nb"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Click on the Program.cs file to see its contents in VS Code right pane.&lt;/p&gt;

&lt;h2&gt;
  
  
  Configure the SDK
&lt;/h2&gt;

&lt;p&gt;Replace Program.cs default content with the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;Invoicetronic.Sdk.Api&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;Invoicetronic.Sdk.Client&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;static&lt;/span&gt; &lt;span class="n"&gt;Invoicetronic&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Sdk&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Receive&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Configure the SDK.&lt;/span&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;config&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;Configuration&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;BasePath&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"https://api.invoicetronic.com/v1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;Username&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"YOUR TEST API KEY (starts with ik_test_)"&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see, we initialize a &lt;code&gt;Configuration&lt;/code&gt; instance by setting the API's base path and your &lt;strong&gt;test API Key&lt;/strong&gt; (not the live one). Notice how &lt;strong&gt;we use the &lt;code&gt;Username&lt;/code&gt; property to set the API Key&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;When you create your account, you obtain a pair of API Keys. One is the test key for the &lt;a href="https://invoicetronic.com/en/docs/sandbox/" rel="noopener noreferrer"&gt;API Sandbox&lt;/a&gt;, and the other is the live API's. You can tell the difference because the former starts with &lt;code&gt;ik_test_&lt;/code&gt;, while the latter begins with &lt;code&gt;ik_live_&lt;/code&gt;. In this tutorial, &lt;strong&gt;always use the test key&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Download invoices
&lt;/h2&gt;

&lt;p&gt;We are ready to make a request. We want to download new vendor invoices that may be avaiable from the SDI. Add these lines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;
&lt;span class="c1"&gt;// Download unread invoices.&lt;/span&gt;
&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;receiveApi&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;ReceiveApi&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;try&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;inboundInvoices&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;receiveApi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ReceiveGetAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;unread&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="k"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;includePayload&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="k"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;$"Received &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;inboundInvoices&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Count&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s"&gt; invoices"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;foreach&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;invoice&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;inboundInvoices&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;invoice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Encoding&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;EncodingEnum&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Xml&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;File&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteAllText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;invoice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;FileName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;invoice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Payload&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
                &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;EncodingEnum&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Base64&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;File&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteAllBytes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;invoice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;FileName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Convert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;FromBase64String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;invoice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Payload&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
                &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;$"Downloaded &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;invoice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;FileName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s"&gt; from a vendor with VAT ID &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;invoice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Prestatore&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ApiException&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;Console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WriteLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;$"&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Message&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s"&gt; - &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ErrorCode&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We set &lt;code&gt;includePayload: true&lt;/code&gt; to retrieve the actual invoice content in the &lt;code&gt;Payload&lt;/code&gt; property. Without this parameter, the &lt;code&gt;Payload&lt;/code&gt; field would be &lt;code&gt;null&lt;/code&gt; by default, which increases performance and reduces response size when you only need metadata.&lt;/p&gt;

&lt;p&gt;Switch to the terminal then type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dotnet run
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should obtain an output similar to this one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Received 3 invoices
Downloaded file1.xml from a vendor with VAT ID IT06157670966
Downloaded file2.xml.p7m from a vendor with VAT ID IT01280270057
Downloaded file3.xml.p7m from a vendor with VAT ID IT01280270057
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The files are in the current directory, ready for you to inspect them.&lt;/p&gt;

&lt;h2&gt;
  
  
  What we learned
&lt;/h2&gt;

&lt;p&gt;In this example, we learned several things.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;We must configure the SDK by setting both the &lt;code&gt;BasePath&lt;/code&gt; and &lt;code&gt;Username&lt;/code&gt; properties, the latter initialized with the API key.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We must instantiate a class representing the endpoint we want to work with. In this case, we leverage &lt;code&gt;ReceiveApi&lt;/code&gt; to download incoming invoices.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Endpoint classes like &lt;code&gt;ReceiveApi&lt;/code&gt; offer methods for interacting with their target entity. We call &lt;code&gt;ReceiveGetAsync&lt;/code&gt; to retrieve invoices. Because we only want new, unread invoices, we pass &lt;code&gt;unread: true&lt;/code&gt;. We also pass &lt;code&gt;includePayload: true&lt;/code&gt; to retrieve the actual invoice content (if you run the example a second time, you'll likely not receive any invoice unless some has arrived).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;code&gt;Receive&lt;/code&gt; class exposes valuable properties such as &lt;code&gt;Encoding&lt;/code&gt;, &lt;code&gt;FileName&lt;/code&gt;, and &lt;code&gt;Payload&lt;/code&gt;. The last one contains the invoice content, as plain text or Base64-encoded, as described by &lt;code&gt;Encoding&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>programming</category>
      <category>tutorials</category>
      <category>dotnet</category>
      <category>csharp</category>
    </item>
  </channel>
</rss>
