API: inviaFattura

Descrizione

Il metodo inviaFattura permette di inviare una fattura in formato XML tramite l'API.

Parametri

  • fattura_xml (obbligatorio): Il contenuto della fattura da inviare, codificato in base64.
  • nome_file (obbligatorio): Il nome del file da inviare.

Chiamata API

La chiamata deve essere effettuata tramite POST all'endpoint:

https://www.fattureweb.com/api/

Esempio di Chiamata POST

{
    "action": "call",
    "key": "95415ceca602e867e573f65a50c9b70bd6906828",
    "code": "abcdef",
    "payload": {
        "api_name": "Fattura",
        "method": "inviaFattura",
        "input": {
            "fattura_xml": "base64 XML content",
            "nome_file": "IT01296270091_J7BIZ.XML"
        }
    }
}

Esempi di Codice



$url = 'https://www.fattureweb.com/api/';
$data = array(
    'action' => 'call',
    'key' => '95415ceca602e867e573f65a50c9b70bd6906828',
    'code' => 'abcdef',
    'payload' => array(
        'api_name' => 'Fattura',
        'method' => 'inviaFattura',
        'input' => array(
            'fattura_xml' => 'base64 XML content',
            'nome_file' => 'IT01296270091_J7BIZ.XML'
        )
    )
);
$options = array(
    'http' => array(
        'header'  => "Content-Type: application/json\r\n",
        'method'  => 'POST',
        'content' => json_encode($data),
    ),
);
$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) { /* Handle error */ }

var_dump($result);

                    

import requests

url = 'https://www.fattureweb.com/api/'
data = {
    'action': 'call',
    'key': '95415ceca602e867e573f65a50c9b70bd6906828',
    'code': 'abcdef',
    'payload': {
        'api_name': 'Fattura',
        'method': 'inviaFattura',
        'input': {
            'fattura_xml': 'base64 XML content',
            'nome_file': 'IT01296270091_J7BIZ.XML'
        }
    }
}

response = requests.post(url, json=data)
print(response.text)
                    

import java.net.HttpURLConnection;
import java.net.URL;
import java.io.OutputStream;

public class Main {
    public static void main(String[] args) {
        try {
            URL url = new URL("https://www.fattureweb.com/api/");
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("POST");
            conn.setRequestProperty("Content-Type", "application/json; utf-8");
            conn.setDoOutput(true);

            String jsonInputString = "{\"action\": \"call\", \"key\": \"95415ceca602e867e573f65a50c9b70bd6906828\", \"code\": \"abcdef\", \"payload\": {\"api_name\": \"Fattura\", \"method\": \"inviaFattura\", \"input\": {\"fattura_xml\": \"base64 XML content\", \"nome_file\": \"IT01296270091_J7BIZ.XML\"}}}";
            try (OutputStream os = conn.getOutputStream()) {
                byte[] input = jsonInputString.getBytes("utf-8");
                os.write(input, 0, input.length);
            }

            int responseCode = conn.getResponseCode();
            System.out.println("Response Code: " + responseCode);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
                    

Risposta di Successo

Se la chiamata ha successo, riceverai una risposta come la seguente:

{
    "code": "200",
    "result": {
        "status": "success",
        "message": "Fattura inviata con successo",
        "id_sdi": "1234567890"
    }
}

Risposta di Errore

Se si verifica un errore, riceverai una risposta come questa:

{
    "code": "409.0",
    "error": "Errore nell'invio della fattura: Dettagli dell'errore qui"
}