Sending Messages

The Magnet Max REST APIs support sending messages to one or many users using recipientUserIds.

For details on how to obtain recipientUserIds and access tokens to make the request, please refer to Authentication and User Management.

Send Message to User IDs

To send message to user ids:

* Path
```
POST https://<server>/message/api/v2/messages/send_to_user_ids```

* Sample Request
```
curl -X POST \
    -H "Authorization: <valid-access-token>" \
    -H "Content-Type: application/json" \
    -d '{"receipt": true, "recipientUserIds": ["ff80818150bfea110150c04b20a6001f", "ff80818150bfea110150c049e6e10016"], "content": { "header1": "data1", "header2": "data2" }, "metadata":{ "content-type":"text", "content-encoding":"simple"}}' \
    https://<server>/message/api/v2/messages/send_to_user_ids
```

* Sample Response
```
{
    "count": {
        "requested": 2,
        "sent": 2,
        "unsent": 0
    },
    "sentList": [
        {
            "messageId": "46591c56a7bca27610bef63326bb716a",
            "deviceId": null,
            "recipientUsername": "ff80818150bfea110150c04b20a6001f"
        },
        {
            "messageId": "604dfb5f1dc76df654f80208b22e3bd4",
            "deviceId": null,
            "recipientUsername": "ff80818150bfea110150c049e6e10016"
        }
    ],
    "unsentList": []
}
```

* Parameters

<table>
    <tbody>
        <tr> 
            <td >receipt</td>
            <td >set true/false to request receipt confirmation upon message received</td>
        </tr>
        <tr >

            <td >recipientUserIds</td>
            <td >list of user Ids the message is sending to
            </td>
        </tr>
        <tr >
            <td >content</td>
            <td >dictionary list of key/value pairs of the actual message contents</td>
        </tr>
        <tr >
            <td >metadata</td>
            <td >dictionary list of key/value pairs of any additional information being sent with the message (optional)</td>
        </tr>
        <tr >
            <td >count</td>
            <td >dictionary providing count information returned from server:
                <ul>
                <li> <b>requested:</b>Count of users that matched the request</li>
                <li> <b>sent:</b> Count of users to which the system sent a push message</li>
                <li> <b>unsent:</b> Count of users to which the system was unable to send a push message </li></ul>
            </td>
        </tr>
        <tr >
            <td >sentList</td>
            <td >dictionary list of element providing information about send push message:
                <ul>
                <li> <b>messageId:</b> Id of the message sent </li>
                <li> <b>deviceId:</b> id of the device to which the message was sent</li>
                <li> <b>recipientUsername:</b> the username to which the message was sent</li>
                </ul>
            </td>
        </tr>
        <tr >
            <td >unsentList</td>
            <td >dictionary list of element providing information about unsent push messages</td>
        </tr>
    </tbody>
</table>

Get Message Delivery Status by Message ID

To get message delivery status by the message ID:

* Path
```
GET https://<server>/message/api/v2/messages/{messageId}
```

* Sample Request
```
curl -X GET \
    -H "Authorization: <valid-access-token>" \
    https://<server>/message/api/v2/messages/46591c56a7bca27610bef63326bb716a

```

* Sample Response
```
[  
   {  
      "state":"WAKEUP_REQUIRED",
      "recipient":"4028e51250d496a60150d49791670007",
      "sender":"4028e51250d496a60150d49791670007",
      "appId":"p9digldd03a",
      "deviceId":"11-22-33-44",
      "messageId":"62bd69e86614d227bea18df061b90396",
      "queuedAt":"2015-11-04T22:21:54.000+0000",
      "receivedAt":null
   }
]
```

* Parameters
```
messageId: id of the message sent
```