Vai al contenuto

Java Quickstart

Work in progress

The contents of this page currently mirror the README file in the Java SDK repository. For an up-to-date version, make sure to check the repository itself.

Interested?

Are you interested in a stand-alone Quickstart for your language? Let us know, or contribute one yourself!

Not receiving invoices in the live environment?

Ensure your correspondents use 7HD37X0 as the value of their invoices' Codice Destinatario field. That is how SDI knows they should be forwarded to the Invoicetronic API.

Requirements

Building the API client library requires:

  1. Java 1.8+
  2. Maven/Gradle

Installation

To install the API client library to your local Maven repository, simply execute:

mvn clean install

To deploy it to a remote Maven repository instead, configure the settings of the repository and execute:

mvn clean deploy

Refer to the OSSRH Guide for more information.

Maven users

Add this dependency to your project's POM:

<dependency>
  <groupId>com.invoicetronic.invoice</groupId>
  <artifactId>java-sdk</artifactId>
  <version>1.0.0</version>
  <scope>compile</scope>
</dependency>

Gradle users

Add this dependency to your project's build file:

  repositories {
    mavenCentral()     // Needed if the 'java-sdk' jar has been published to maven central.
    mavenLocal()       // Needed if the 'java-sdk' jar has been published to the local maven repo.
  }

  dependencies {
     implementation "com.invoicetronic.invoice:java-sdk:1.0.0"
  }

Others

At first generate the JAR by executing:

mvn clean package

Then manually install the following JARs:

  • target/java-sdk-1.0.0.jar
  • target/lib/*.jar

Getting Started

Please follow the installation instruction and execute the following Java code:

import com.invoicetronic.invoice.sdk.*;
import com.invoicetronic.invoice.sdk.auth.*;
import com.invoicetronic.invoice.sdk.model.*;
import com.invoicetronic.invoice.sdk.api.CompanyApi;

public class CompanyApiExample {

    public static void main(String[] args) {
        ApiClient defaultClient = Configuration.getDefaultApiClient();
        defaultClient.setBasePath("http://localhost");

        // Configure HTTP basic authorization: Basic
        HttpBasicAuth Basic = (HttpBasicAuth) defaultClient.getAuthentication("Basic");
        Basic.setUsername("YOUR USERNAME");
        Basic.setPassword("YOUR PASSWORD");

        CompanyApi apiInstance = new CompanyApi(defaultClient);
        Integer page = 1; // Integer | Page number. Defaults to 1.
        Integer pageSize = 100; // Integer | Items per page. Defaults to 50. Cannot be greater than 200.
        try {
            List<Company> result = apiInstance.invoiceV1CompanyGet(page, pageSize);
            System.out.println(result);
        } catch (ApiException e) {
            System.err.println("Exception when calling CompanyApi#invoiceV1CompanyGet");
            System.err.println("Status code: " + e.getCode());
            System.err.println("Reason: " + e.getResponseBody());
            System.err.println("Response headers: " + e.getResponseHeaders());
            e.printStackTrace();
        }
    }
}