Smooch API Library for Java
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.

README.md

smooch-java

The Java package for the Smooch API

The Smooch API is a unified interface for powering messaging in your customer experiences across every channel. Our API speeds access to new markets, reduces time to ship, eliminates complexity, and helps you build the best experiences for your customers. For more information, visit our official documentation.

This SDK is automatically generated by the Swagger Codegen project using the Smooch api spec.

Installation

Maven users

Add the following remote repo to your project's POM:

<project ...>
<repositories>
    <repository>
      <id>smooch.io</id>
      <url>https://smoochorg.bintray.com/maven/</url>
    </repository>
 </repositories>
</project>

Add this dependency to your project's POM:

<dependency>
    <groupId>io.smooch</groupId>
    <artifactId>api</artifactId>
    <version>3.17.0</version>
    <scope>compile</scope>
</dependency>

Gradle users

Add this dependency to your project's build file:

compile "io.smooch:api:3.17.0"

Getting Started

Authentication with JSON Web Tokens (JWTs)

JSON Web Tokens (JWTs) are an industry standard authentication mechanism. A great introduction to the technology is available here, and a broad set of supported JWT libraries for a variety of languages and platforms are available.

A JWT is composed of a header, a payload, and a signature. The payload contains information called claims which describe the subject to whom the token was issued.

Before you can make calls to the Smooch API, you'll need to create a JWT that proves you are authorized to use the API.

Step 1 Generate a KEY ID and SECRET on the settings tab in the Smooch Dashboard.

secret key and id

Step 2 Generate the JWT

Using the jjwt package:

import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.impl.crypto.MacProvider;
import java.security.Key;

import static io.jsonwebtoken.JwsHeader.KEY_ID;

// ...

String jwt = Jwts.builder()
  .claim("scope", "app")
  .setHeaderParam(KEY_ID, "YOUR_KEY_ID")
  .signWith(
    SignatureAlgorithm.HS256,
    "YOUR_SECRET".getBytes("UTF-8")
  )
  .compact();

Running the code

import io.smooch.client.ApiClient;
import io.smooch.client.ApiException;
import io.smooch.client.Configuration;
import io.smooch.client.auth.*;
import io.smooch.client.api.AppApi;

import java.io.File;
import java.util.*;

public class AppApiExample {

    public static void main(String[] args) {
        ApiClient defaultClient = Configuration.getDefaultApiClient();
        
        // Configure API key authorization: jwt
        ApiKeyAuth jwt = (ApiKeyAuth) defaultClient.getAuthentication("jwt");
        jwt.setApiKey("YOUR JWT");
        jwt.setApiKeyPrefix("Bearer");

        AppApi apiInstance = new AppApi();
        AppCreate appCreateBody = new AppCreate(); // AppCreate | Body for a createApp request.
        try {
            AppResponse result = apiInstance.createApp(appCreateBody);
            System.out.println(result);
        } catch (ApiException e) {
            System.err.println("Exception when calling AppApi#createApp");
            e.printStackTrace();
        }
    }
}

Region

Smooch is available in the following regions. The US region will be used by default. To target any other region, specify the region API host in setBasePath(). For example:

defaultClient.setBasePath("https://api.eu-1.smooch.io");

Documentation for API Endpoints

All URIs are relative to https://api.smooch.io

Class Method HTTP request Description
AppApi createApp POST /v1/apps
AppApi createSecretKey POST /v1/apps/{appId}/keys
AppApi deleteApp DELETE /v1/apps/{appId}
AppApi deleteSecretKey DELETE /v1/apps/{appId}/keys/{keyId}
AppApi getApp GET /v1/apps/{appId}
AppApi getAppJwt GET /v1/apps/{appId}/keys/{keyId}/jwt
AppApi getSecretKey GET /v1/apps/{appId}/keys/{keyId}
AppApi listApps GET /v1/apps
AppApi listSecretKeys GET /v1/apps/{appId}/keys
AppApi updateApp PUT /v1/apps/{appId}
AppUserApi deleteAppUser DELETE /v1/apps/{appId}/appusers/{userId}
AppUserApi deleteAppUserProfile DELETE /v1/apps/{appId}/appusers/{userId}/profile
AppUserApi getAppUser GET /v1/apps/{appId}/appusers/{userId}
AppUserApi getAppUserAuthCode GET /v1/apps/{appId}/appusers/{userId}/authcode
AppUserApi getAppUserBusinessSystemIds GET /v1/apps/{appId}/appusers/{userId}/businesssystems
AppUserApi getAppUserEntityIds GET /v1/apps/{appId}/appusers/{userId}/channels
AppUserApi getLinkRequests GET /v1/apps/{appId}/appusers/{userId}/linkrequest
AppUserApi linkAppUser POST /v1/apps/{appId}/appusers/{userId}/channels
AppUserApi postImageMessage POST /v1/apps/{appId}/appusers/{userId}/images
AppUserApi preCreateAppUser POST /v1/apps/{appId}/appusers
AppUserApi unlinkAppUser DELETE /v1/apps/{appId}/appusers/{userId}/channels/{channel}
AppUserApi updateAppUser PUT /v1/apps/{appId}/appusers/{userId}
AttachmentsApi removeAttachment POST /v1/apps/{appId}/attachments/remove
AttachmentsApi uploadAttachment POST /v1/apps/{appId}/attachments
ConversationApi deleteMessage DELETE /v1/apps/{appId}/appusers/{userId}/messages/{messageId}
ConversationApi deleteMessages DELETE /v1/apps/{appId}/appusers/{userId}/messages
ConversationApi getMessages GET /v1/apps/{appId}/appusers/{userId}/messages
ConversationApi postMessage POST /v1/apps/{appId}/appusers/{userId}/messages
ConversationApi resetUnreadCount POST /v1/apps/{appId}/appusers/{userId}/conversation/read
ConversationApi triggerTypingActivity POST /v1/apps/{appId}/appusers/{userId}/conversation/activity
IntegrationApi createIntegration POST /v1/apps/{appId}/integrations
IntegrationApi createIntegrationMenu POST /v1/apps/{appId}/integrations/{integrationId}/menu
IntegrationApi deleteIntegration DELETE /v1/apps/{appId}/integrations/{integrationId}
IntegrationApi deleteIntegrationMenu DELETE /v1/apps/{appId}/integrations/{integrationId}/menu
IntegrationApi getIntegration GET /v1/apps/{appId}/integrations/{integrationId}
IntegrationApi getIntegrationMenu GET /v1/apps/{appId}/integrations/{integrationId}/menu
IntegrationApi listIntegrations GET /v1/apps/{appId}/integrations
IntegrationApi updateIntegration PUT /v1/apps/{appId}/integrations/{integrationId}
IntegrationApi updateIntegrationMenu PUT /v1/apps/{appId}/integrations/{integrationId}/menu
MenuApi deleteMenu DELETE /v1/apps/{appId}/menu
MenuApi getMenu GET /v1/apps/{appId}/menu
MenuApi updateMenu PUT /v1/apps/{appId}/menu
ServiceAccountApi createSecretKey POST /v1/serviceaccounts/{serviceAccountId}/keys
ServiceAccountApi createServiceAccount POST /v1/serviceaccounts
ServiceAccountApi deleteSecretKey DELETE /v1/serviceaccounts/{serviceAccountId}/keys/{keyId}
ServiceAccountApi deleteServiceAccount DELETE /v1/serviceaccounts/{serviceAccountId}
ServiceAccountApi getJwt GET /v1/serviceaccounts/{serviceAccountId}/keys/{keyId}/jwt
ServiceAccountApi getSecretKey GET /v1/serviceaccounts/{serviceAccountId}/keys/{keyId}
ServiceAccountApi getServiceAccount GET /v1/serviceaccounts/{serviceAccountId}
ServiceAccountApi listSecretKeys GET /v1/serviceaccounts/{serviceAccountId}/keys
ServiceAccountApi listServiceAccounts GET /v1/serviceaccounts
ServiceAccountApi updateServiceAccount PUT /v1/serviceaccounts/{serviceAccountId}
TemplateApi createTemplate POST /v1/apps/{appId}/templates
TemplateApi deleteTemplate DELETE /v1/apps/{appId}/templates/{templateId}
TemplateApi getTemplate GET /v1/apps/{appId}/templates/{templateId}
TemplateApi listTemplates GET /v1/apps/{appId}/templates
TemplateApi updateTemplate PUT /v1/apps/{appId}/templates/{templateId}
WebhookApi createWebhook POST /v1/apps/{appId}/webhooks
WebhookApi deleteWebhook DELETE /v1/apps/{appId}/webhooks/{webhookId}
WebhookApi getWebhook GET /v1/apps/{appId}/webhooks/{webhookId}
WebhookApi listWebhooks GET /v1/apps/{appId}/webhooks
WebhookApi updateWebhook PUT /v1/apps/{appId}/webhooks/{webhookId}

Documentation for Models

Documentation for Authorization

Authentication schemes defined for the API:

jwt

  • Type: API key
  • API key parameter name: Authorization
  • Location: HTTP header

Recommendation

It's recommended to create an instance of ApiClient per thread in a multithreaded environment to avoid any potential issues.