Resources API

Resources API

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

Authentication

To use the API, you’ll need to obtain an access token and pass this along in each call – please see our authentication topic for more information. Your API token can be obtained from your “Edit Organization” screen.

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 your organization has, simply issue an HTTP GET request to the Base URL.

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

This will return a list of all the resources. e.g.

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.json

e.g.

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

An example post:

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

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

 

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

where

  1. [resource_id] is the id of the resource

For the update you just need to send through parameters you would like to change.

An example: 

{
    "resource": {
        "file": {
            "file_name": "R2_D2_2.jpg",
            "file_data": "<Base64_Econded_Data>",
            "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.

Have more questions? Submit a request

Comments

Powered by Zendesk