Getting Started with the Modelshop Data API

The Modelshop Data API is organized around REST. Our API has simple to construct URLs and uses built in HTTP features for authentication and error handling. Below we will show basic examples of how to interact with the Modelshop Data API to send and retrieve data from Modelshop Models. These examples are built using the Requests Library for Python, but should provide clear examples of how to perfotm these tasks in your client language of choice. Additionally, the Modelshop Data API is highly flexible, with a wide array of optional parameters. This reference is not intended to be an an exhaustive list of all options. For further detail, please see the complete API documentation.

# Import the lib
import requests

For this example, we will be using a sample user (creatively name sampleuser) that has been created on a demo installation of Modelshop Server. Additionally, we have created a very simple model (SampleModel), owned by sampleuser to demonstrate sending and getting data. This model consists of a single DataList, with a single View into it.

Here we set up the parameters required to access this model and view as sampleuser.

server_url = "https://demo.modelshop.com/modelshop"  # The base url for the location of the Modelshop installation.
username = "sampleuser" # Username for authentication
password = "P@ssword12345" # Password for authentication
model = "SampleModel" # The name of the model to be accessed
model_owner = "sampleuser" # The username of the user who owns the model, this can difffer from username if the model has been shared
view = "Accounts" # View to be used

Sample GET Requests

Get bulk records from a view

url = "{}/api/data/{}/{}/{}".format(server_url,model_owner,model,view)

r = requests.get(url, auth=(username, password))
r.json()
URL:

https://demo.modelshop.com/modelshop/api/data/sampleuser/SampleModel/Accounts

Response:
{'errors': [],
 'resultsId': 299,
 'success': True,
 'totalRecords': 16,
 'moreData': False,
 'hasModelErrors': False,
 'hasErrors': False,
 'hasWarnings': False,
 'hasInfos': False,
 'moreMessages': False,
 'viewStale': False,
 'records': [{'id': 1,
   'version': 34,
   'accountId': '4551',
   'name': 'James Smith',
   'value': '212068.61'},
  {'id': 2,
   'version': 35,
   'accountId': '9223',
   'name': 'Michael Smith',
   'value': '82570.24'},
  {'id': 3,
   'version': 36,
   'accountId': '3830',
   'name': 'Robert Smith',
   'value': '119642.18'},
  {'id': 4,
   'version': 37,
   'accountId': '4265',
   'name': 'Maria Garcia',
   'value': '138076.94'},
  {'id': 5,
   'version': 38,
   'accountId': '5883',
   'name': 'David Smith',
   'value': '111261.13'},
  {'id': 6,
   'version': 39,
   'accountId': '6234',
   'name': 'Maria Rodriguez',
   'value': '67762.81'},
  {'id': 7,
   'version': 40,
   'accountId': '1099',
   'name': 'Mary Smith',
   'value': '138447.26'},
  {'id': 8,
   'version': 41,
   'accountId': '6301',
   'name': 'Maria Hernandez',
   'value': '112133.83'},
  {'id': 9,
   'version': 42,
   'accountId': '1032',
   'name': 'Mark Jones',
   'value': '75693.29'},
  {'id': 10,
   'version': 43,
   'accountId': '9205',
   'name': 'Ted Stevens',
   'value': '144999.34'},
   ...
   ]}

Get limited bulk records from a view

url = "{}/api/data/{}/{}/{}".format(server_url,model_owner,model,view)

params = {
    'limit' : 2
}
r = requests.get(url, auth=(username, password), params=params)
r.json()
URL:

https://demo.modelshop.com/modelshop/api/data/sampleuser/SampleModel/Accounts?limit=2

Response:
{'errors': [],
 'resultsId': 298,
 'success': True,
 'totalRecords': 16,
 'moreData': True,
 'hasModelErrors': False,
 'hasErrors': False,
 'hasWarnings': False,
 'hasInfos': False,
 'moreMessages': False,
 'viewStale': False,
 'records': [{'id': 1,
   'version': 34,
   'accountId': '4551',
   'name': 'James Smith',
   'value': '212068.61'},
  {'id': 2,
   'version': 35,
   'accountId': '9223',
   'name': 'Michael Smith',
   'value': '82570.24'}]
}

Get records from a view using a simple filter

field = 'accountId' # The field to be filtered on
value = '1032' # The value to be used as a filter
url = "{}/api/data/{}/{}/{}/{}/{}".format(server_url,model_owner,model,view,field,value)
r = requests.get(url, auth=(username, password))
URL:

https://demo.modelshop.com/modelshop/api/data/sampleuser/SampleModel/Accounts/accountId/1032

Response:
{'errors': [],
 'resultsId': 301,
 'success': True,
 'totalRecords': 17,
 'moreData': True,
 'hasModelErrors': False,
 'hasErrors': False,
 'hasWarnings': False,
 'hasInfos': False,
 'moreMessages': False,
 'viewStale': False,
 'records': [{'id': 9,
   'version': 42,
   'accountId': '1032',
   'name': 'Mark Jones',
   'value': '75693.29'}]}

Sample PUT Request

url = "{}/api/data/{}/{}/{}".format(server_url,model_owner,model,view)

## Payload should be wrapped in a 'records' envelope
payload = {
    'records': [
        {
            'accountId': '12345',
            'name': 'John Snow',
            'value': 1000000
        }
    ]
}

r = requests.put(url, auth=(username, password), json=payload)
r.json()
URL:

https://demo.modelshop.com/modelshop/api/data/sampleuser/SampleModel/Accounts

Response:
{'errors': [],
 'resultsId': 0,
 'success': True,
 'totalRecords': 0,
 'moreData': False,
 'hasModelErrors': False,
 'hasErrors': False,
 'hasWarnings': False,
 'hasInfos': False,
 'moreMessages': False}