This API allows you to view, add and update resources in your organization.

Authentication

The API requires you to authenticate each call with your API token. Please see our authentication article for more information.

Base URL

Requests will be based on the following URL (note the HTTPS):

https://www.devicemagic.com/api/resources

Viewing Resources

To get an overview of all the resources within your organization, simply issue an HTTP GET request to the Base URL.

https://www.devicemagic.com/api/resources.(xml|json)

This will return a list of all the resources.

Request

HTTP GET https://www.devicemagic.com/api/resources.json

Response

{
    "resources": [
        {
            "id": 1,
            "original_filename": "R2-D2.jpg",
            "version": 0,
            "description": "r1"
        },
        {
            "id": 2,
            "original_filename": "R2-D2.jpg",
            "version": 0,
            "description": "r2"
        }
    ]
}

Downloading a Resource

To download a resource, issue an HTTP GET request to the Base URL with the resource_id.

HTTP GET https://www.devicemagic.com/api/resources/[resource_id]

Viewing Resource Details

To view the details of a single resource, issue an HTTP GET request to the describe URL with the resource_id.

https://www.devicemagic.com/api/resources/[resource_id]/describe.(xml|json)

Request

HTTP GET https://www.devicemagic.com/api/resources/3/describe.json

Response

{
    "resource": {
        "id": 3,
        "identifier": "dbfd3a10-249c-0133-5179-14109fd23119",
        "original_filename": "text_resource.xlsx",
        "version": 1,
        "description": "r3",
        "generated_content_summary": [
            {
                "table_name": "text_resource.Sheet1",
                "table_id": "dc341ce0-249c-0133-5179-14109fd23119",
                "columns": [
                    {
                        "column_name": "ID",
                        "column_number": 1,
                        "column_id": "dc3420b0-249c-0133-5179-14109fd23119"
                    },
                    {
                        "column_name": "Description",
                        "column_number": 2,
                        "column_id": "dc3421a0-249c-0133-5179-14109fd23119"
                    },
                    {
                        "column_name": "Price",
                        "column_number": 3,
                        "column_id": "dc342260-249c-0133-5179-14109fd23119"
                    },
                    {
                        "column_name": "Rating",
                        "column_number": 4,
                        "column_id": "dc342330-249c-0133-5179-14109fd23119"
                    }
                ]
            }
        ]
    }
}

Creating a Resource via JSON

To create a new resource, you need to send an HTTP POST with the resource settings to:

HTTP POST https://www.devicemagic.com/api/resources.json

In the POST you need to specify a few things for the resource:

  • description
  • file 

Which consists of:

  • file_name
  • file_data - Base64 encoded file data
  • content_type

Example JSON POST Request Body:

{
    "resource": {
        "description": "r3",
        "file": {
            "file_name": "R2_D3.jpg",
            "file_data": "TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdC...",
            "content_type": "image/jpeg"
        }
    }
}


The following are allowed MIME types:

  • image/png
  • image/jpeg
  • application/xml
  • text/xml
  • text/plain
  • application/json
  • application/pdf
  • application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
  • application/vnd.openxmlformats-officedocument.wordprocessingml.document

If the creation is successful you will get the resource details returned in the same format as "View resource details" above.

Map Overlay Resources 

The Map Overlay resource is a JSON file that follows the KML conventions for orienting an image onto a map:

{
  "north": "37.038079163474556",
  "south": "33.6349012701535",
  "east": "-75.10778066888042",
  "west": "-85.39281798106992",
  "rotation": "0",
  "opacity": "0.4",
  "image": "/9j/4QUhEUgAAA0gAAAGQCAYAAACUFUCwAAAKxmlDQ..."
}

content_type should be set to application/json  

Updating a Resource via JSON

To update a resource, you need to send an HTTP PUT with the resource settings to:

HTTP PUT https://www.devicemagic.com/api/resources/[resource_id].json

To update, only send through parameters you would like to change.

Example JSON PUT Request Body:

{
    "resource": {
        "file": {
            "file_name": "R2_D2_2.jpg",
            "file_data": ""TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdC..."",
            "content_type": "image/jpeg"
        }
    }
}

Destroying a Resource

To remove a resource, you need to send an HTTP DELETE to:

HTTP DELETE https://www.devicemagic.com/api/resources/[resource_id]

You’ll receive a 200 OK if the delete succeeded, and an HTTP error response otherwise.

Did this answer your question?