Conversations API

Requirements

The Conversations API is available in Weavy 8.x and later.

What you can do with the API

The Conversations API can be used to create, display and edit conversations from Weavy.

You can use the API from any 3rd party application and framework, such as React, Angular, Web, etc.

Authentication

Before you can use the API, you need to authenticate your users. This is done the same way as you authenticate when you use the Client SDK.

For more information on how authentication works, please take a look at Configuring Authentication on Client Side

Example

This is a JavaScript example of how you can use the Conversations API.

Server SDK

Before you start, you need to have a Server SDK up and running. If you already have an existing Server SDK, please make sure it’s updated to version 8.7 or later.

If you need to set up a new Server SDK, follow these instructions.

Authenticate the user

If you have set up the Authentication Client described above in the section Authentication, you should be able to create a JWT with user information.

If you don’t have a backend to generate the JWT, you could use https://jwt.io/ to create a hard-coded JWT for test purposes.

Just make sure you include all the necessary claims needed for successful authentication.

const API_URL = "[weavy_root_url]";

const token = "[jwt_token]";

fetch(API_URL + "/client/sign-in", {

    method: "GET",

    credentials: "include",

    headers: {

        Accept: "application/json",

        Authorization: "Bearer " + token,

    }

})

.then((res) => res.json())

.then((user) => {

    // do something;

});

The [weavy_root_url] refers to the hostname where you installed the Server SDK. You can use https://showcase.weavycloud.com for demo purposes.

Replace the [API_URL] and [jwt_token] with your current setup details. 

The /client/sign-in endpoint returns a cookie which we make sure to store by supplying the credentials: include option. If you don’t want to store the cookie, exclude this option and make sure to pass in the JWT in each subsequent API call instead.

Get the conversations

Now that we are authenticated, we can fetch the user’s conversations.

const getConversations = async () => {

    const response = await fetch(API_URL + "/api/conversations", {

        method: "GET",

        credentials: "include",

    });

    const conversations = await response.json();

    return conversations;

};

If you went for the cookie option, make sure to include it in the fetch. The conversations are returned as JSON and you can display them in your own UI.

API Reference

The API reference is available at https://[weavy_root_url]/docs/conversations. Where weavy_root_url is the URL to your instance of Server SDK.

The reference contains examples and response data for all the available endpoints.

Demo

KendoMessenger

We have a fully working demo using Kendo UI for React to render the output from the Conversations API.