To use this SDK, initialize the Credentials class and create a new client. The Credentials class is JSON enabled. Ensure that INTX API credentials are stored in a secure manner.The JSON format expected for credentials is:
The following code snippet demonstrates how to make your first API call using the INTX Java SDK. This example lists all portfolios associated with your provided API key.
package com.coinbase.examples;import com.coinbase.intx.client.CoinbaseIntxClient;import com.coinbase.intx.credentials.CoinbaseIntxCredentials;import com.coinbase.intx.errors.CoinbaseIntxException;import com.coinbase.intx.factory.IntxServiceFactory;import com.coinbase.intx.model.portfolios.*;import com.coinbase.intx.portfolios.PortfoliosService;import com.coinbase.intx.portfolios.PortfoliosServiceImpl;import com.fasterxml.jackson.databind.ObjectMapper;public class Main { public static void main(String[] args) throws CoinbaseIntxException { String credsStringBlob = System.getenv("INTX_CREDENTIALS"); ObjectMapper mapper = new ObjectMapper(); try { CoinbaseIntxCredentials credentials = new CoinbaseIntxCredentials(credsStringBlob); CoinbaseIntxClient client = new CoinbaseIntxClient(credentials); PortfoliosService portfoliosService = IntxServiceFactory.createPortfoliosService(client); ListPortfoliosResponse listResponse = portfoliosService.listPortfolios(); System.out.println("List Portfolios Response:"); System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(listResponse)); } catch (Throwable e) { throw new CoinbaseIntxException("Failed to retrieve the list portfolios response", e); } }}