In this article, you'll be given a walkthrough of dispatching a form to a device via our Push API. In this example, a free REST Client extension for Google Chrome is used to send dispatches. Please view our article on our Push API before continuing with this sample as we'll be referencing it throughout this article. Before you dispatch a form to a device, you'll need to collect three pieces of data from your Device Magic account.

  1. Device Magic API Key
  2. Device Identifier
  3. Form Namespace

To find your Device Magic API Key, click the Settings icon and then "API Access".

On the following page, you'll find your authorization details.  The HTTP Auth Header Value is required in this sample so save a copy of this value for later.

Next, you'll need the device identifier of the device you're going to dispatch the form to. When on your Devices page, click the name of the device you wish to send the form to.

On the following page, you'll see the identifier in the Properties section. Save this value for later.

Lastly, go to your Forms page and click the name of the form you'd like to dispatch.

On the next page, the namespace will be the first value in the Summary Info.

Now that you have all the information to dispatch the form, go to your REST Client to perform the dispatch.

First, you'll need to provide the URL which you're sending the POST request to.

https://www.devicemagic.com/clients/[device_identifier]/oneshots

Replace "[device_identifier}" with the device identifier value you captured earlier. Also, switch the type of request to POST.

After, specify the payload where you'll need to include the form namespace you collected previously and any form attributes for the dispatch.  The JSON should look similar to:

{
    "form_namespace" : "your_form_namespace",
    "payload" : {
    }
}

Next, replace "your_form_namespace" with the form namespace information you collected previously and add any additional form attributes. The attributes in the below screenshot are form name, form description, and an answer to the job description question in the form.

In the "Custom Headers" section, set the header to "Content-Type: application/json". Then, add the HTTP Auth Header Value you saved previously to the "Authentication" section.

Next, click the "Send Request" button and you'll see a successful 202 server response in green.

The device has received the form which can be found on the Dispatches tab in the mobile app. The name and description of the form match the values you specified in our POST Request.

The Job description value also matches the data you specified in our POST Request as well.

If you have any questions or comments feel free to send us a message at support@devicemagic.com.

Did this answer your question?