- Notifications
You must be signed in to change notification settings - Fork3
License
segmentio/public-api-sdk-java
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
The Segment Public API helps you manage your Segment Workspaces and its resources. You can use the API to perform CRUD (create, read, update, delete) operations at no extra charge. This includes working with resources such as Sources, Destinations, Warehouses, Tracking Plans, and the Segment Destinations and Sources Catalogs. The full documentation is available athttps://docs.segmentapis.com.
All endpoints in the API follow REST conventions and use standard HTTP methods. Different URL endpoints represent different resources in a Workspace.
See the next sections for more information on how to use the Segment Public API Java SDK.
Latest API and SDK version: 58.13.0
Building the API client library requires:
- Java 1.8+
- Maven (3.8.3+)/Gradle (7.2+)
Add this dependency to your project's POM:
<dependency> <groupId>com.segment.publicapi</groupId> <artifactId>segment-publicapi</artifactId> <version>58.13.0</version> <scope>compile</scope></dependency>
Add this dependency to your project's build file:
repositories { mavenCentral()// Needed if the 'segment-publicapi' jar has been published to maven central. mavenLocal()// Needed if the 'segment-publicapi' jar has been published to the local maven repo. } dependencies { implementation"com.segment.publicapi:segment-publicapi:58.13.0" }
At first generate the JAR by executing:
mvn clean package
Then manually install the following JARs:
target/segment-publicapi-58.13.0.jar
target/lib/*.jar
You are now ready to start making calls to Public API!
importcom.segment.publicapi.ApiClient;importcom.segment.publicapi.ApiException;importcom.segment.publicapi.Configuration;importcom.segment.publicapi.auth.*;importcom.segment.publicapi.models.*;importcom.segment.publicapi.api.SourcesApi;importcom.segment.publicapi.api.WorkspacesApi;importjava.math.BigDecimal;publicclassExample {publicstaticvoidmain(String[]args) {ApiClientdefaultClient =Configuration.getDefaultApiClient();defaultClient.setBasePath("https://api.segmentapis.com");// Configure HTTP bearer authorization: tokenHttpBearerAuthtoken = (HttpBearerAuth)defaultClient.getAuthentication("token");token.setBearerToken("<TOKEN>");ActivationsApiapiInstance =newActivationsApi(defaultClient);StringspaceId ="spa_9aQ1Lj62S4bomZKLF4DPqW";// String |StringaudienceId ="aud_0ujsszwN8NRY24YaXiTIE2VWDTS";// String |StringconnectionId ="ii_123456789";// String |AddActivationToAudienceAlphaInputaddActivationToAudienceAlphaInput =newAddActivationToAudienceAlphaInput();// AddActivationToAudienceAlphaInput |// Make an API call without Paginationtry {WorkspacesApiapiInstance =newWorkspacesApi(defaultClient);GetWorkspace200ResponseworkspaceResponse =apiInstance.getWorkspace(); }catch (ApiExceptione) {System.err.println("Exception when calling WorkspacesApi#getWorkspace");System.err.println("Status code: " +e.getCode());System.err.println("Reason: " +e.getResponseBody());System.err.println("Response headers: " +e.getResponseHeaders());e.printStackTrace(); }// Make an API call with Paginationtry {SourcesApisourceApiInstance =newSourcesApi(defaultClient);PaginationInputpaginationInput =newPaginationInput();paginationInput.count(BigDecimal.valueOf(20));Stringcurrent =null;do {paginationInput.setCursor(current);ListSources200ResponsesourcesResponse =sourceApiInstance.listSources(paginationInput);current =sourcesResponse.getData().getPagination().getNext(); }while(current !=null); }catch (ApiExceptione) {System.err.println("Exception when calling SourcesApi#sourceApiInstance");System.err.println("Status code: " +e.getCode());System.err.println("Reason: " +e.getResponseBody());System.err.println("Response headers: " +e.getResponseHeaders());e.printStackTrace(); } }}
It's recommended to create an instance ofApiClient
per thread in a multithreaded environment to avoid any potential issues.
The contents of this repository are automatically generated, so we can't take contributions from external developers. If you have any issues with this SDK, please raise an issue or reach out tofriends@segment.com instead of opening a pull request. Pull requests will not be reviewed.
About
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors2
Uh oh!
There was an error while loading.Please reload this page.