# \_2.10 JsonAPI

![Vị trí thẻ JSON API (Cuộn xuống hoặc tìm kiếm hoặc chọn trong cột SmaxBot)](https://634492474-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Ln1Gs55tBcLrVgnJ9tC%2F-MdGx3wyoD_8KKAN47Th%2F-MdGxi6jMUtLgAcaiIum%2Fimage.png?alt=media\&token=3ba0ef5a-6b3f-4fa9-82eb-1e10b0730d54)

**JSON API**&#x20;

The JSON API plugin enables you to integrate your backend into your chat bots on **Smax bot**.

It allows you to

* Generate dynamic content
* Get and set user attributes
* Redirect users to another block in the bot
* Create postbacks

You can use GET and POST requests - the max. timeout is always 10 seconds. There are four options to enter data that will be sent with your request:

1\. URL — This field supports user attributes, they will be URL-encoded with your request

![](https://634492474-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Ln1Gs55tBcLrVgnJ9tC%2F-MLLENudQju-owqYgpq9%2F-MLLIz_nGCJLLRURSEp8%2Fimage.png?alt=media\&token=e326bb05-55fd-493d-9cab-0802e3abe050)

2\. Full JSON profile (POST requests only) — This will send all the user attributes of the user to your backend

![](https://634492474-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Ln1Gs55tBcLrVgnJ9tC%2F-MLLENudQju-owqYgpq9%2F-MLLJ5Seon84Nh9HrDHJ%2Fimage.png?alt=media\&token=4d7e1289-bd20-4b41-989e-1be68fb8e2a5)

3\. JSON Body (POST requests only) — This is a customizable field and will be validated as JSON.

![](https://634492474-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Ln1Gs55tBcLrVgnJ9tC%2F-MLLENudQju-owqYgpq9%2F-MLLJFI4RDJT-pX0ser3%2Fimage.png?alt=media\&token=7eeed2ea-62e7-49b7-aadd-a1211a3a87f2)

4\. URL Encoded (POST requests only) — The data will be encoded before sending your request.

![](https://634492474-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Ln1Gs55tBcLrVgnJ9tC%2F-MLLENudQju-owqYgpq9%2F-MLLJM3GwrQkdpcG6W9q%2Fimage.png?alt=media\&token=d7997c71-4438-4891-a15c-ab4cc79a636e)

In your responses, you can

* combine several messages in one answer by sending several dictionaries in the messages array.&#x20;
* use any content type header.
* send an empty response to not show the user any dynamic content.

### Response Reference <a href="#response-reference" id="response-reference"></a>

**Sending text**

Use this response to send text messages.

```
{
 "messages": [
   {"text": "Welcome to the Smax Rockets!"},
   {"text": "What are you up to?"}
 ]
}
```

**Sending images**

Use this response to send image files. Messenger supports JPG, PNG and GIF images. If you are having issues with GIF rendering, please try to reduce the file size.

```
{
  "messages": [
    {
      "attachment": {
        "type": "image",
        "payload": {
          "url": "https://smax.bot/assets/images/homepage/ourprod-bot.png"
        }
      }
    }
  ]
}
```

You can also directly use Facebook Posts with media instead of uploading it manually:

```
{
  "messages": [
    {
      "attachment": {
        "type": "template",
        "payload": {
          "template_type": "media",
          "elements": [
            {
              "media_type": "image",
              "url": "https://www.facebook.com/smaxbot/photos/1087668107975064",
              "buttons": [
                {
                  "title": "Go to Smax!",
                  "type": "web_url",
                  "url": "https://smax.bot/"
                }
              ]
            }
          ]
        }
      },
      "quick_replies": [
        {
          "title": "That's cool!",
          "payload": "string"
        }
      ]
    }
  ]
}
```

**Sending video**

Use this response to send video files. Messenger supports MP4 videos, which are up to 25MB in size.&#x20;

```
{
  "messages": [
    {
      "attachment": {
        "type": "video",
        "payload": {
          "url": "https://rockets.smax.bot/assets/video.mp4"
        }
      }
    }
  ]
}
```

You can also directly use Facebook Posts with media instead of uploading it manually:

```
{
  "messages": [
    {
      "attachment": {
        "type": "template",
        "payload": {
          "template_type": "media",
          "elements": [
            {
              "media_type": "video",
              "url": "https://www.facebook.com/smaxbot/videos/252894858962779/",
              "buttons": [
                {
                  "title": "Go to Chatfuel!",
                  "type": "web_url",
                  "url": "https://smax.bot/"
                }
              ]
            }
          ]
        }
      },
      "quick_replies": [
        {
          "title": "That's cool!",
          "payload": "string"
        }
      ]
    }
  ]
}
```

**Sending audio**

Use this response to send audio files. Messenger supports MP3, OGG, WAV audios, which are up to 25MB in size.

```
{
  "messages": [
    {
      "attachment": {
        "type": "audio",
        "payload": {
          "url": "https://rockets.smax.bot/assets/hello.mp3"
        }
      }
    }
  ]
}
```

**Sending files**

Use this response to send any other files, which are no larger than 25 MB.

```
{
  "messages": [
    {
      "attachment": {
        "type": "file",
        "payload": {
          "url": "https://rockets.smax.bot/assets/ticket.pdf"
        }
      }
    }
  ]
}
```

**Sending galleries**

Use this response to send a horizontal scrollable gallery. Each item is composed of an image attachment, short description and buttons to request input from the user.\
Note: messenger\_extensions should only be added if you are using [Messenger Extensions](https://docs.chatfuel.com/configure/chat-extensions).

```
{
 "messages": [
    {
      "attachment":{
        "type":"template",
        "payload":{
          "template_type":"generic",
          "image_aspect_ratio": "square",
          "elements":[
            {
              "title":"Chatfuel Rockets Jersey",
              "image_url":"https://rockets.smax.bot/assets/shirt.jpg",
              "subtitle":"Size: M",
              "buttons":[
                {
                  "type":"web_url",
                  "url":"https://rockets.smax.bot/store",
                  "title":"View Item"
                }
              ]
            },
            {
              "title":"Chatfuel Rockets Jersey",
              "image_url":"https://rockets.smax.bot/assets/shirt.jpg",
              "subtitle":"Size: L",
              "default_action": {
                "type": "web_url",
                "url": "https://rockets.smax.bot/store",
                "messenger_extensions": true
              },
              "buttons":[
                {
                  "type":"web_url",
                  "url":"https://rockets.smax.bot/store",
                  "title":"View Item"
                }
              ]
            }
          ]
        }
      }
    }
  ]
}
```

**Sending receipts**

Use this response to send an order confirmation. It may include an order summary, payment details, and shipping information.

```
{
  "messages": [
    {
      "attachment": {
        "type": "template",
        "payload": { 
          "template_type": "receipt",
          "recipient_name": "Mark Zuckerberg",
          "order_number": "12345678901",
          "currency": "USD",
          "payment_method": "Visa 2345",
          "order_url": "https://rockets.smax.bot/store?order_id=12345678901",
          "timestamp": "1428444666",
          "address": {
            "street_1": "1 Hacker Way",
            "street_2": "",
            "city": "Menlo Park",
            "postal_code": "94025",
            "state": "CA",
            "country": "US"
          },
          "summary": {
            "subtotal": 105,
            "shipping_cost": 4.95,
            "total_tax": 9,
            "total_cost": 118.95
          },
          "adjustments": [
            {
              "name": "CF Rockets Superstar",
              "amount": -25
            }
          ],
          "elements": [
            {
              "title": "Chatfuel Rockets Jersey",
              "subtitle": "Size: M",
              "quantity": 1,
              "price": 65,
              "currency": "USD",
              "image_url":   "http://rockets.smax.bot/assets/shirt.jpg"
            },
            {
              "title": "Chatfuel Rockets Jersey",
              "subtitle": "Size: L",
              "quantity": 1,
              "price": 65,
              "currency": "USD",
              "image_url":   "http://rockets.smax.bot/assets/shirt.jpg"
            }
          ]
        }
      }
    }
  ]
}
```

**Buttons**

Use this JSON to add buttons to your responses. You can set buttons to link to a block in the dashboard, open a website, or send another request to your backend. Buttons are limited to 3 items per message.

```
{
  "messages": [
    {
      "attachment": {
        "type": "template",
        "payload": {
          "template_type": "button",
          "text": "Hello!",
          "buttons": [
            {
              "type": "show_block",
              "block_names": ["name of block"],
              "title": "Show Block"
            },
            {
              "type": "web_url",
              "url": "https://rockets.chatfuel.com",
              "title": "Visit Website"
            },
            {
              "url": "https://rockets.smax.bot/api/welcome",
              "type":"json_url",
              "title":"Postback"
            }
          ]
        }
      }
    }
  ]
}
```

You can also use the Call button, this button dials a phone number when tapped.

```
{
  "messages":[
    {
      "attachment":{
        "type":"template",
        "payload":{
          "template_type":"generic",
          "elements":[
            {
              "title":"Get in touch",
              "image_url":"https://rockets.smax.bot/assets/contact.jpg",
              "subtitle":"Feel free to hit us up!",
              "buttons":[
                {
                  "type":"phone_number",
                  "phone_number":"+19268881413",
                  "title":"Call"
                }
              ]
            }
          ]
        }
      }
    }
  ]
}
```

**Quick replies**

Use this JSON to add quick replies to your responses. Quick replies are limited to 11 items per message.

```
{
  "messages": [
    {
      "text":  "Did you enjoy the last game of the CF Rockets?",
      "quick_replies": [
        {
          "title":"Loved it!",
          "block_names": ["Block 1", "Block 2"]
        },
        {
          "title":"Not really...",
          "url": "https://rockets.smax.bot/api/sad-match",
          "type":"json_url"
        },
        {
          "title": "More...",
          "payload": "string"
        }
      ]
    }
  ]
}
```

**Setting user attributes**

You can set user attributes by having the field set\_attributes as bellow&#x20;

```
{
  "set_attributes":
    {
      "some attribute": "some value",
      "another attribute": "another value"
    },
  "messages":[
    . . .
  ]
}
```

**Redirect to blocks**

You can redirect a user to a block or to a sequence of blocks — no user action is needed.

```
{
  "redirect_to_blocks": ["Welcome Message", "Default Answer"]
}
```

\
Do keep in mind that for other functionalities or compiling functions to work altogether is out of Smax's scope of support and we suggest to get help from an [Expert](https://www.messenger.com/t/smax.apps).
