Zami
BETA

Getting Started

Zami is the chat API for developers. To start sending or receiving messages you must first connect an account on one of our supported networks.

Sending text

Sends a text message to a recipient

Body Params
connection_id
string
The connection from which to send the message
recipient
string
The message recipient
body
string
The message body
reply_to_id (optional)
string
The ID of a message to respond to
Response fields
success
boolean
true if the message was sent. false if not
id
string
The ID of the newly created message. null if request failed
error
string
Reason the message was not sent. null if message was sent
import { Zami } from 'zami';

const zami = new Zami('om-secret-abcdefghijklmnopqrstuvwxyz');

zami.sendText({
  connection_id: '<connection_id>',
  recipient: 'zamiapi',
  body: 'Hello from Zami',
})
javascript
curl

Sending media

Sends a media message to a recipient. Media needs to be uploaded before calling this endpoint

Body Params
connection_id
string
The connection from which to send the message
recipient
string
The message recipient
media_id
string
The message body
reply_to_id (optional)
string
The ID of a message to respond to
Response fields
success
boolean
true if the message was sent. false if not
id
string
The ID of the newly created message. null if request failed
error
string
Reason the message was not sent. null if message was sent
import { Zami } from 'zami';

const zami = new Zami('om-secret-abcdefghijklmnopqrstuvwxyz');

zami.sendMedia({
  connection_id: '<connection_id>',
  recipient: 'zamiapi',
  media_id: '<media_id>',
});
javascript
curl

Uploading media

Uploads media and returns a media ID. You can use this ID to send media to recipients across supported networks.

Headers
Content-Type
enum
MIME type of the media being uploaded
Allowed values
image/jpeg
image/png
audio/ogg
video/mp4
Authorization
string
Your API secret
Response fields
id
string
The ID of the uploaded media
import { Zami } from 'zami';

const zami = new Zami('om-secret-abcdefghijklmnopqrstuvwxyz')

async function upload() {
  const buffer = await fs.readFile('path/to/your/file.png');
  const mediaId = await zami.uploadMedia({
    media: buffer,
    content_type: 'image/png',
  });
  console.log('Uploaded media id is ', mediaId);
}

upload();
javascript
curl

Downloading media

Downloads media given media ID. Media IDs are received via webhook when receiving media messages

Headers
Authorization
string
Your API secret
Response headers
Content-Type
string
MIME type of the media being downloaded
Response body
The response body will contain the contents of the media.

import { Zami } from 'zami';

const zami = new Zami('om-secret-abcdefghijklmnopqrstuvwxyz');

async function download() {
  const buffer = await zami.downloadMedia('<media_id>');
  await fs.writeFile('path/to/your/file.png', buffer);
}

download();
javascript
curl

message.created

Body params
name
string
The value will be message.created for new incoming messages
connection_id
string
The ID of the connection receiving the message
timestamp
int
Server's UNIX timestamp
object
object
The message object
Message fields
id
string
Message ID
body
string
Message body if it's a text message. null if it's a media message
media_id
string
Media ID of the message. null if it's a text message
mimetype
string
MIME type of the message
reply_to_id
string
Optional ID of a message being replied to. null if not a reply
const express = require('express');
const bodyParser = require('body-parser');

const app = express();
const port = 3000;

// Middleware to parse JSON bodies
app.use(bodyParser.json());

app.post('/process-zami-webhook', (req, res) => {
  if (req.body.name === 'message.created') {
    console.log(
      'New message',
      req.body.connection_id,
      req.body.object.id,
    )
  }
  res.send('OK');
});

app.listen(port, () => {
  console.log(`Server running on ${port}`);
});

Installing

You can use the client library in your web application to let your users connect their chat accounts in order to obtain API access to them.

Include the following script tag on every page of your site

<script src="https://cdn.zamiapi.com/link.js" />

Zami.createConnection

Opens a modal that lets users pick their network and authenticate their accounts. The result is a connection object which you can use to send and receive messages

Params
publicToken
string
Your public token. You can obtain one by clicking here.
onSuccess
callback
A function that will be called when the user successfully connects an account
Callback params
connectionId
string
The ID of the newly created connection. You can use this ID to send messages
onExit (optional)
callback
A function that will be called when the user exits the modal
network (optional)
enum
The network for the new connection. If empty the user will be asked to pick one
Allowed values
whatsapp
instagram
linkedin
x
telegram
messenger
Zami.createConnection({
  publicToken: 'LOG IN TO SEE YOUR PUBLIC TOKEN',
  network: 'whatsapp',
  onSuccess: (connectionId) => {
    alert('success. connection id: ' + connectionId);
  },
  onExit: () => {
    alert('the user closed the modal');
  },
})