---
schema_version: "1"
id: fb1e2090d6a944ff9d2007f80549e1a6ff2fc210e14df10e7383dc069ab5ea85
title: Java Example
collection: tableau
version: current
locale: en-us
portal_url: https://docs.salesforce.com/tableau/current/en-us/api/explore-tableau/docs/example-java.md
canonical_url: https://help.tableau.com/current/api/explore-tableau/en-us/docs/example-java.html
source_site: help.tableau.com
content_type: documentation
content_hash: 911db11836f93a55720979d5dc533df1e5636fe13e165334ce4656f2992788aa
description: Documentation for the Explore in Tableau API
---
# Java Example

  

## Generating the JWT

A JSON Web Token (JWT) is a standard and secure way to transmit information between parties using JSON. General information about JWTs can be found at [jwt.io](https://jwt.io/).

This example uses the [JJWT library](https://github.com/jwtk/jjwt).

```
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.security.Keys;

import java.security.Key;
import java.time.Instant;
import java.util.Date;

public class JwtGenerator {
    public static void main(String[] args) {
        if (args.length == 0) {
            System.out.println("Usage: java JwtGenerator <api_key>");
            System.exit(1);
        }

        String apiKey = args[0];
        
        // Define the key
        final Key key = Keys.hmacShaKeyFor(apiKey.getBytes());
        
        // Generate the JWT
        final String jwt = Jwts.builder()
            .setHeaderParam("typ", "JWT")
            .setIssuer("Put any value")
            .setSubject("Put any value")
            .setIssuedAt(Date.from(Instant.now())) // Use UTC for issued-at timestamp
            .signWith(key)
            .compact();
        
        System.out.println("Authorization: C2C:" + jwt.toString());
    }
}
```

## Sending the request

Replace:

- `<API_KEY>` with the API key
- `<REJOIN>` with the Salesforce region
- `<BASE64_URLENCODED_TDS>` with the base64 URL encoded TDS

```
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class ExploreInTableau {
    public static void main(String[] args) throws Exception {
        String apiKey = "<API_KEY>";

        // Generate JWT using script from above
        String jwtToken = generateJwt(apiKey);
        HttpResponse<String> response = makeApiCall(jwtToken);

        if (response.statusCode() == 201) {
            System.out.println("Resource created successfully (201). No response body.");

            String locationHeader = response.headers().map().get("Location").get(0);
            if (locationHeader != null) {
                System.out.println("Location Header: " + locationHeader);
            } else {
                System.out.println("Location Header not found.");
            }
        } else {
            System.out.println("Failed to call API. Status Code: " + response.statusCode());
        }
    }
    
    public static HttpResponse<String> makeApiCall(String jwtToken) throws Exception {
        // Create an HTTP client (Java 11 and above)
        HttpClient client = HttpClient.newHttpClient();
    
        String apiUrl = "https://api.salesforce.com/analytics/integration/explore-in-tableau/v1/upload-tds-content/example";
    
        // Create the JSON payload (base64-encoded TDS content here)
        String jsonPayload = "{\"tdsContent\":\"<BASE64_URLENCODED_TDS>\"}";
    
        // Create the POST request with the necessary headers
        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create(apiUrl))
                .header("Authorization", "C2C:" + jwtToken)
                .header("x-salesforce-region", "<REGION>")
                .header("Content-Type", "application/json")
                .POST(HttpRequest.BodyPublishers.ofString(jsonPayload))
                .build();
    
        return client.send(request, HttpResponse.BodyHandlers.ofString());
    }
}
```