mycaule / smooch-java

Smooch API Library for Java

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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 this dependency to your project's POM:

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

Gradle users

Add this dependency to your project's build file:

compile "io.smooch:api:1.12.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();
        }
    }
}

Documentation for API Endpoints

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

Class Method HTTP request Description
AppApi createApp POST /apps
AppApi createSecretKey POST /apps/{appId}/keys
AppApi deleteApp DELETE /apps/{appId}
AppApi deleteSecretKey DELETE /apps/{appId}/keys/{keyId}
AppApi getApp GET /apps/{appId}
AppApi getAppJwt GET /apps/{appId}/keys/{keyId}/jwt
AppApi getSecretKey GET /apps/{appId}/keys/{keyId}
AppApi listApps GET /apps
AppApi listSecretKeys GET /apps/{appId}/keys
AppApi updateApp PUT /apps/{appId}
AppUserApi appUserDeviceUpdate PUT /appusers/{userId}/devices/{deviceId}
AppUserApi deleteAppUserProfile DELETE /appusers/{userId}/profile
AppUserApi getAppUser GET /appusers/{userId}
AppUserApi getAppUserEntityIds GET /appusers/{userId}/channels
AppUserApi linkAppUser POST /appusers/{userId}/channels
AppUserApi postImageMessage POST /appusers/{userId}/images
AppUserApi preCreateAppUser POST /appusers
AppUserApi trackEvent POST /appusers/{userId}/events
AppUserApi unlinkAppUser DELETE /appusers/{userId}/channels/{channel}
AppUserApi updateAppUser PUT /appusers/{userId}
AttachmentsApi uploadAttachment POST /apps/{appId}/attachments
ConversationApi deleteMessages DELETE /appusers/{userId}/messages
ConversationApi getMessages GET /appusers/{userId}/messages
ConversationApi postMessage POST /appusers/{userId}/messages
ConversationApi resetUnreadCount POST /appusers/{userId}/conversation/read
ConversationApi triggerTypingActivity POST /appusers/{userId}/conversation/activity
InitApi init POST /init
IntegrationApi createIntegration POST /apps/{appId}/integrations
IntegrationApi createIntegrationMenu POST /apps/{appId}/integrations/{integrationId}/menu
IntegrationApi deleteIntegration DELETE /apps/{appId}/integrations/{integrationId}
IntegrationApi deleteIntegrationMenu DELETE /apps/{appId}/integrations/{integrationId}/menu
IntegrationApi getIntegration GET /apps/{appId}/integrations/{integrationId}
IntegrationApi getIntegrationMenu GET /apps/{appId}/integrations/{integrationId}/menu
IntegrationApi listIntegrations GET /apps/{appId}/integrations
IntegrationApi updateIntegrationMenu PUT /apps/{appId}/integrations/{integrationId}/menu
MenuApi deleteMenu DELETE /menu
MenuApi getMenu GET /menu
MenuApi updateMenu PUT /menu
WebhookApi createWebhook POST /apps/{appId}/webhooks
WebhookApi deleteWebhook DELETE /apps/{appId}/webhooks/{webhookId}
WebhookApi getWebhook GET /apps/{appId}/webhooks/{webhookId}
WebhookApi listWebhooks GET /apps/{appId}/webhooks
WebhookApi updateWebhook PUT /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.

About

Smooch API Library for Java


Languages

Language:Java 99.6%Language:Shell 0.3%Language:Scala 0.1%