Sample Asset Service API Requests
Sample Asset Service API Requests
Use the Asset service APIs to retrieve and manipulate resources like assets, classifications, and custom domain objects.
To run the sample requests, use the asset-service-asset-model.html#reference_99274c09-7d07-40fe-95a7-3219cd905ca1 within a POST
method. See asset-service-set-started.html#task_24953dd7-22e0-421c-8f7c-cb65f423c3e0.
The samples on this page abbreviate the base URL for the host that processes Asset service API requests. You need to include the full URI of your Asset service instance, from the VCAP_SERVICES environment variable, in your requests.
Pagination Requests
Use the pageSize
parameter to indicate the number of entities to be returned per page. The default value is 100. The maximum pageSize
is 1000.
For example, this request returns four locomotive objects:
<asset-app-url>/locomotives?pageSize=4
The response headers contain a link to the next page of locomotive objects. Copy and paste the link in a GET
request to display the next page.
Partial Response Requests
Example API requests and responses for Predix Asset service.
You can submit an API request in which you specify the fields that will be included in the API response. Use the field
clause in a request method to retrieve selected fields of a large object or a collection of large objects. For example, to retrieve a few attributes from an asset with many attributes, indicate your selected fields in the field
clause.
Get all fields of an object
<asset-app-url>/locomotives/1
Returns
[
{
"uri": "/locomotives/1",
"type": "Diesel-electric",
"model": "ES44AC",
"serial_no": "001",
"emission_tier": "0+",
"fleet": "/fleets/up-1",
"manufacturer": "/manufacturers/GE",
"engine": "/engines/v12-1",
"installedOn": "01/12/2005",
"dateIso": "2005-12-01T13:15:31Z",
"hqLatLng": {
"lat": 33.914605,
"lng": -117.253374
}
},
]
Get selected fields of an object
<asset-app-url>/locomotives/1?fields=uri,type,manufacturer
Returns
[
{
"uri": "/locomotives/1",
"type": "Diesel-electric",
"manufacturer": "/manufacturers/GE"
}
]
Get selected fields of a collection of objects
<asset-app-url>/locomotives?fields=uri,type,manufacturer
Returns
[
{
"uri": "/locomotives/1",
"type": "Diesel-electric",
"manufacturer": "/manufacturers/GE"
},
{
"uri": "/locomotives/10",
"type": "Diesel-electric",
"manufacturer": "/manufacturers/electro-motive-diesel"
},
{
"uri": "/locomotives/11",
"type": "Diesel-electric",
"manufacturer": "/manufacturers/GE"
},
{
"uri": "/locomotives/12",
"type": "Diesel-electric",
"manufacturer": "/manufacturers/electro-motive-diesel"
},
... SNIP
EQUALS (=) Operator Requests
EQUALS
The EQUALS operator returns any objects that match the specified value.
<asset-app-url>/locomotives?filter=serial_no=0084
Returns
[
{
"uri": "/locomotives/84",
"type": "Diesel-electric",
"model": "3GS21B",
"serial_no": "0084",
"emission_tier": "0+",
"fleet": "/fleets/cn-4",
"manufacturer": "/manufacturers/national-railway-equipment",
"engine": "/engines/QSK19-26",
"hqLatLng": {
"lat": 49.296307,
"lng": -118.827314
}
}
]
EQUALS (=) combined with AND (:)
Read the colon character “:” as AND. The ampersand “&” is a reserved character in URLs.
<asset-app-url>/locomotives?filter=model=SD70ACe:fleet=/fleets/up-5
Returns
[
{
"uri": "/locomotives/15",
"type": "Diesel-electric",
"model": "SD70ACe",
"serial_no": "0015",
"emission_tier": "0+",
"fleet": "/fleets/up-5",
"manufacturer": "/manufacturers/electro-motive-diesel",
"engine": "/engines/v16-2-8",
"hqLatLng": {
"lat": 45.314087,
"lng": -90.969283
}
}
]
EQUALS (=) combined with OR (|)
Read the pipe | as OR.
<asset-app-url>/locomotives?filter=engine=/engines/v16-2-5|fleet=/fleets/csx-1
Returns
[
{
"uri": "/locomotives/10",
"type": "Diesel-electric",
"model": "SD70ACe",
"serial_no": "0010",
"emission_tier": "0+",
"fleet": "/fleets/up-4",
"manufacturer": "/manufacturers/electro-motive-diesel",
"engine": "/engines/v16-2-5",
"hqLatLng": {
"lat": 47.941049,
"lng": -100.126484
}
},
{
"uri": "/locomotives/37",
"type": "Diesel-electric",
"model": "ES44AC",
"serial_no": "0037",
"emission_tier": "0+",
"fleet": "/fleets/csx-1",
"manufacturer": "/manufacturers/GE",
"engine": "/engines/v12-15",
"hqLatLng": {
"lat": 43.488604,
"lng": -116.913932
}
},
{
"uri": "/locomotives/38",
"type": "Diesel-electric",
"model": "GL23TCe",
"serial_no": "0038",
"emission_tier": "0+",
"fleet": "/fleets/csx-1",
"manufacturer": "/manufacturers/electro-motive-diesel",
"engine": "/engines/v16-2-9",
"hqLatLng": {
"lat": 40.26462,
"lng": -74.496063
}
},
{
"uri": "/locomotives/39",
"type": "Diesel-electric",
"model": "ES44AC",
"serial_no": "0039",
"emission_tier": "0+",
"fleet": "/fleets/csx-1",
"manufacturer": "/manufacturers/GE",
"engine": "/engines/v12-16",
"hqLatLng": {
"lat": 43.650927,
"lng": -74.570743
}
}
]
Data Validation Requests
Example schema updates for Predix Asset domain objects.
Use these examples as guidelines to define your own schema updates. Data uploaded to your domain is validated against the schema you have in place at the time of the upload. If you add properties to an existing schema or replace an existing schema, you should update your data to comply with the new schema; Queries can fail
Successful Schema PUT Request
PUT
Request:<asset-url>/system/schema/entities/assets
{
"type" : "object",
"properties" : { "uri" : { "type" :"string" }, "name" : { "type" : "string" }},
"required" : [ "uri", "name"]
}
PUT Request to Add New Properties to an Existing Schema
{
"type": "object",
"properties":{
"uri": {
"type": "string"
},
"name": {
"type": "string"
},
"required":[
"uri",
"name"
]
}
PUT
request to add properties to the schema. This example shows adding a "description"
property to the existing schema.
{
"type": "object",
"properties":{
"uri": {
"type": "string"
},
"name": {
"type": "string"
},
"description": {
"type": "string"
}
},
"required":[
"uri",
"name"
]
}
{
"type": "object",
"properties":{
"uri": {
"type": "string"
},
"name": {
"type": "string"
},
"required":[
"uri",
"name"
]
}
Response:
[
{
"code":"PA_SCHEMA_VALIDATION_PROP_REMOVED",
"message":"Provided schema cannot remove existing schema property",
"suggestion":"Property 'description' cannot be removed",
Sample Audit History API Requests
Use the Asset audit history service APIs to retrieve historical information about your assets.
To run the sample requests, use the asset-service-asset-model.html#reference_99274c09-7d07-40fe-95a7-3219cd905ca1 within a POST
method. See asset-service-set-started.html#task_24953dd7-22e0-421c-8f7c-cb65f423c3e0.
The samples on this page abbreviate the base URL for the host that processes Asset service API requests. You need to include the full URI of your Asset service instance, from the VCAP_SERVICES environment variable, in your requests.
PATCH Requests
Predix Asset API PATCH request method description and examples. Update properties of a resource using the PATCH request method.
Use the PATCH
method to replace, add, modify, or copy values in an existing asset record. Predix Asset Supports the entire RFC that defines the PATCH
API method. For more details about PATCH
, refer to the RFC5789 at https://tools.ietf.org/html/rfc5789
Example Asset Model
[
{
uri: '/assets/patchJson',
A1: 'A',
A2: 'B',
A3: 'C'
}
]
PATCH Request to Replace an Existing Value in the Asset Record
PATCH request: /assets/patchJson
with body: [{“op": “replace=", “path": “/A1", value: “X”}]
[
{
uri: '/assets/patchJson',
A1: 'X',
A2: 'B',
A3: 'C'
}
]
PATCH Request to Remove a Value from an Asset Record
PATCH request: /assets/patchJson
with body:
[{“op": "remove", “path": "/A1"}]
[
{
uri:'assets/patchjson',
A2 'B',
A3: 'C'
}
]
PATCH Request to Add a Value to an Asset Record
/assets/patchjson
[
{
"op": "add",
"path":"/A4",
"value": "D"
}
]
[
{
uri: '/assets/patchjson',
A1: 'A',
A2: 'B',
A3: 'C',
A4: 'D'
}
]
PATCH Request to Copy A Value
/asset/patchjson
[
{
"op":"copy",
"from":"/A1",
"path":"/A2"
}
]
[
{
uri: '/assets/patchjson',
A1: "A",
A2: "C",
A3: "C"
}
]
PATCH Request to Move a Value
/asset/patchjson
[
{
"op":"move",
"from": "/A1",
"path": "/A2"
}
]
[
{
uri: '/assets/patchjson',
A2: 'A',
A3: 'C'
}
]
RANGE (..) Operator Requests
Read two periods (..) as a range between two numbers, two dates, or two strings.
RANGE (..) between Two Numbers
<asset-app-url>/locomotives?filter=serial_no=001..004
Returns
[
{
"uri": "/locomotives/1",
"type": "Diesel-electric",
"model": "ES44AC",
"serial_no": "001",
"emission_tier": "0+",
"fleet": "/fleets/up-1",
"manufacturer": "/manufacturers/GE",
"engine": "/engines/v12-1",
"installedOn": "01/12/2005",
"dateIso": "2005-12-01T13:15:31Z",
"hqLatLng": {
"lat": 33.914605,
"lng": -117.253374
}
},
{
"uri": "/locomotives/2",
"type": "Diesel-electric",
"model": "SD70ACe",
"serial_no": "002",
"emission_tier": "0+",
"fleet": "/fleets/up-1",
"manufacturer": "/manufacturers/electro-motive-diesel",
"engine": "/engines/v16-2-1",
"hqLatLng": {
"lat": 47.655492,
"lng": -117.427025
}
},
{
"uri": "/locomotives/3",
"type": "Diesel-electric",
"model": "ES44AC",
"serial_no": "003",
"emission_tier": "0+",
"fleet": "/fleets/up-1",
"manufacturer": "/manufacturers/GE",
"engine": "/engines/v12-2",
"installedOn": "02/12/2005",
"dateIso": "2005-12-02T13:15:31Z",
"hqLatLng": {
"lat": 46.860395,
"lng": -109.473494
}
},
{
"uri": "/locomotives/4",
"type": "Diesel-electric",
"model": "AD40SPe",
"serial_no": "004",
"emission_tier": "0+",
"fleet": "/fleets/up-2",
"manufacturer": "/manufacturers/electro-motive-diesel",
"engine": "/engines/v16-2-2",
"hqLatLng": {
"lat": 45.784314,
"lng": -108.500856
}
}
]
RANGE (..) between Two Strings
<asset-app-url>/locomotive?filter=model=ES43AC..ES44AC
Returns
[
{
"uri": "/locomotives/1",
"type": "Diesel-electric",
"model": "ES44AC",
"serial_no": "001",
"emission_tier": "0+",
"fleet": "/fleets/up-1",
"manufacturer": "/manufacturers/GE",
"engine": "/engines/v12-1",
"installedOn": "01/12/2005",
"dateIso": "2005-12-01T13:15:31Z",
"hqLatLng": {
"lat": 33.914605,
"lng": -117.253374
}
},
{
"uri": "/locomotives/11",
"type": "Diesel-electric",
"model": "ES44AC",
"serial_no": "0011",
"emission_tier": "0+",
"fleet": "/fleets/up-4",
"manufacturer": "/manufacturers/GE",
"engine": "/engines/v12-6",
"hqLatLng": {
"lat": 32.7086,
"lng": -108.190375
}
},
{
"uri": "/locomotives/14",
"type": "Diesel-electric",
"model": "ES44AC",
"serial_no": "0014",
"emission_tier": "0+",
"fleet": "/fleets/up-5",
"manufacturer": "/manufacturers/GE",
"engine": "/engines/v12-7",
"hqLatLng": {
"lat": 35.931077,
"lng": -79.643374
}
},
{
"uri": "/locomotives/3",
"type": "Diesel-electric",
"model": "ES44AC",
"serial_no": "003",
"emission_tier": "0+",
"fleet": "/fleets/up-1",
"manufacturer": "/manufacturers/GE",
"engine": "/engines/v12-2",
"installedOn": "02/12/2005",
"dateIso": "2005-12-02T13:15:31Z",
"hqLatLng": {
"lat": 46.860395,
"lng": -109.473494
}
},
{
"uri": "/locomotives/37",
"type": "Diesel-electric",
"model": "ES44AC",
"serial_no": "0037",
"emission_tier": "0+",
"fleet": "/fleets/csx-1",
"manufacturer": "/manufacturers/GE",
"engine": "/engines/v12-15",
"hqLatLng": {
"lat": 43.488604,
"lng": -116.913932
}
},
{
"uri": "/locomotives/39",
"type": "Diesel-electric",
"model": "ES44AC",
"serial_no": "0039",
"emission_tier": "0+",
"fleet": "/fleets/csx-1",
"manufacturer": "/manufacturers/GE",
"engine": "/engines/v12-16",
"hqLatLng": {
"lat": 43.650927,
"lng": -74.570743
}
},
{
"uri": "/locomotives/41",
"type": "Diesel-electric",
"model": "ES44AC",
"serial_no": "0041",
"emission_tier": "0+",
"fleet": "/fleets/csx-2",
"manufacturer": "/manufacturers/GE",
"engine": "/engines/v12-17",
"hqLatLng": {
"lat": 45.40759,
"lng": -103.471649
}
},
{
"uri": "/locomotives/43",
"type": "Diesel-electric",
"model": "ES44AC",
"serial_no": "0043",
"emission_tier": "0+",
"fleet": "/fleets/csx-2",
"manufacturer": "/manufacturers/GE",
"engine": "/engines/v12-18",
"hqLatLng": {
"lat": 39.173252,
"lng": -90.552123
}
},
{
"uri": "/locomotives/45",
"type": "Diesel-electric",
"model": "ES44AC",
"serial_no": "0045",
"emission_tier": "0+",
"fleet": "/fleets/csx-3",
"manufacturer": "/manufacturers/GE",
"engine": "/engines/v12-19",
"hqLatLng": {
"lat": 41.394707,
"lng": -119.079633
}
},
{
"uri": "/locomotives/5",
"type": "Diesel-electric",
"model": "ES44AC",
"serial_no": "005",
"emission_tier": "0+",
"fleet": "/fleets/up-2",
"manufacturer": "/manufacturers/GE",
"engine": "/engines/v12-3",
"installedOn": "10/12/2005",
"dateIso": "2005-12-10T13:15:31Z",
"hqLatLng": {
"lat": 35.022757,
"lng": -83.009365
}
},
{
"uri": "/locomotives/7",
"type": "Diesel-electric",
"model": "ES44AC",
"serial_no": "007",
"emission_tier": "0+",
"fleet": "/fleets/up-3",
"manufacturer": "/manufacturers/GE",
"engine": "/engines/v12-4",
"installedOn": "12/12/2005",
"dateIso": "2005-12-12T13:15:31Z",
"hqLatLng": {
"lat": 36.739438,
"lng": -79.66268
}
},
{
"uri": "/locomotives/9",
"type": "Diesel-electric",
"model": "ES44AC",
"serial_no": "009",
"emission_tier": "0+",
"fleet": "/fleets/up-3",
"manufacturer": "/manufacturers/GE",
"engine": "/engines/v12-5",
"hqLatLng": {
"lat": 36.669408,
"lng": -115.617391
}
}
]
About Date RANGE (..) Queries
If you select a range between dates that are stored in any other format except ISO, the dates are compared as strings. Compare the following two query result sets. When a date is not in ISO format, the dates are compared as strings, and the results can return dates outside of the intended date range.
Date as String RANGE query
<asset-app-url>/locomotive?filter=installedOn=01/12/2005..10/12/2005
Returns
[
{
"uri": "/locomotives/1",
"type": "Diesel-electric",
"model": "ES44AC",
"serial_no": "001",
"emission_tier": "0+",
"fleet": "/fleets/up-1",
"manufacturer": "/manufacturers/GE",
"engine": "/engines/v12-1",
"installedOn": "01/12/2005",
"dateIso": "2005-12-01T13:15:31Z",
"hqLatLng": {
"lat": 33.914605,
"lng": -117.253374
}
},
{
"uri": "/locomotives/3",
"type": "Diesel-electric",
"model": "ES44AC",
"serial_no": "003",
"emission_tier": "0+",
"fleet": "/fleets/up-1",
"manufacturer": "/manufacturers/GE",
"engine": "/engines/v12-2",
"installedOn": "02/12/2005",
"dateIso": "2005-12-02T13:15:31Z",
"hqLatLng": {
"lat": 46.860395,
"lng": -109.473494
}
},
{
"uri": "/locomotives/5",
"type": "Diesel-electric",
"model": "ES44AC",
"serial_no": "005",
"emission_tier": "0+",
"fleet": "/fleets/up-2",
"manufacturer": "/manufacturers/GE",
"engine": "/engines/v12-3",
"installedOn": "10/12/2005",
"dateIso": "2005-12-10T13:15:31Z",
"hqLatLng": {
"lat": 35.022757,
"lng": -83.009365
}
},
{
"uri": "/locomotives/87",
"type": "Diesel-electric",
"model": "3GS21B-87",
"serial_no": "0087",
"emission_tier": "0+",
"fleet": "/fleets/cn-4",
"manufacturer": "/manufacturers/national-railway-equipment",
"engine": "/engines/QSK19-26",
"hqLatLng": {
"lat": 49.296307,
"lng": -118.827314
},
"parent": "/locomotives/86",
"installedOn": "05/12/2014",
"dateIso": "2014-12-05T13:15:31Z"
},
{
"uri": "/locomotives/89",
"type": "Diesel-electric",
"model": "3GS21B-89",
"serial_no": "0086",
"emission_tier": "0+",
"fleet": "/fleets/cn-4",
"manufacturer": "/manufacturers/national-railway-equipment",
"engine": "/engines/QSK19-28",
"hqLatLng": {
"lat": 46.244201,
"lng": -73.666786
},
"parent": "/locomotives/88",
"installedOn": "05/12/2015",
"dateIso": "2015-12-05T13:15:31Z"
}
]
Date in ISO date format RANGE Query
Use the backslash “\” to escape colons in an ISO date.<asset-app-url>locomotive?filter=dateIso=2005-12-01T13\:15\:31Z..2005-12-10T13\:15\:31Z
Returns
[
{
"uri": "/locomotives/1",
"type": "Diesel-electric",
"model": "ES44AC",
"serial_no": "001",
"emission_tier": "0+",
"fleet": "/fleets/up-1",
"manufacturer": "/manufacturers/GE",
"engine": "/engines/v12-1",
"installedOn": "01/12/2005",
"dateIso": "2005-12-01T13:15:31Z",
"hqLatLng": {
"lat": 33.914605,
"lng": -117.253374
}
},
{
"uri": "/locomotives/3",
"type": "Diesel-electric",
"model": "ES44AC",
"serial_no": "003",
"emission_tier": "0+",
"fleet": "/fleets/up-1",
"manufacturer": "/manufacturers/GE",
"engine": "/engines/v12-2",
"installedOn": "02/12/2005",
"dateIso": "2005-12-02T13:15:31Z",
"hqLatLng": {
"lat": 46.860395,
"lng": -109.473494
}
},
{
"uri": "/locomotives/5",
"type": "Diesel-electric",
"model": "ES44AC",
"serial_no": "005",
"emission_tier": "0+",
"fleet": "/fleets/up-2",
"manufacturer": "/manufacturers/GE",
"engine": "/engines/v12-3",
"installedOn": "10/12/2005",
"dateIso": "2005-12-10T13:15:31Z",
"hqLatLng": {
"lat": 35.022757,
"lng": -83.009365
}
}
]
RELATE (”>” and “<”) Operators Requests
- A forward-relate request uses the “>” operator and traverses in the direction of the relationship.
- A backward-relate request uses the “<” operator and traverses in the opposite direction of the relationship.
RELATE (>)
Retrieves all engines linked to locomotives of type Diesel-electric
.
<asset-app-url>/engines?filter=type=Diesel-electric>engine
Returns
[
{
"uri": "/engines/645",
"type": "7FDL",
"horsepower": "1500",
"stroke": "190",
"bore": "230",
"RPM": "900",
"manufacturer": "/manufacturers/electro-motive-diesel"
},
{
"uri": "/engines/QSK19-1",
"type": "Diesel",
"horsepower": "2100",
"stroke": "159",
"bore": "159",
"RPM": "800",
"manufacturer": "/manufacturers/cummins"
},
{
"uri": "/engines/QSK19-10",
"type": "Diesel",
"horsepower": "2100",
"stroke": "159",
"bore": "159",
"RPM": "800",
"manufacturer": "/manufacturers/cummins"
},
{
"uri": "/engines/QSK19-11",
"type": "Diesel",
"horsepower": "2100",
"stroke": "159",
"bore": "159",
"RPM": "800",
"manufacturer": "/manufacturers/cummins"
},
{
... SNIP
]
BACKWARDS RELATE (<)
Retrieves all locomotives with a given manufacturer.
<asset-app-url>/locomotives?filter=(name=General Electric Transportation)<manufacturers
Returns
[
{
"uri": "/locomotives/1",
"type": "Diesel-electric",
"model": "ES44AC",
"serial_no": "001",
"emission_tier": "0+",
"fleet": "/fleets/up-1",
"manufacturer": "/manufacturers/GE",
"engine": "/engines/v12-1",
"installedOn": "01/12/2005",
"dateIso": "2005-12-01T13:15:31Z",
"hqLatLng": {
"lat": 33.914605,
"lng": -117.253374
}
},
{
"uri": "/locomotives/11",
"type": "Diesel-electric",
"model": "ES44AC",
"serial_no": "0011",
"emission_tier": "0+",
"fleet": "/fleets/up-4",
"manufacturer": "/manufacturers/GE",
"engine": "/engines/v12-6",
"hqLatLng": {
"lat": 32.7086,
"lng": -108.190375
}
},
{
"uri": "/locomotives/14",
"type": "Diesel-electric",
"model": "ES44AC",
"serial_no": "0014",
"emission_tier": "0+",
"fleet": "/fleets/up-5",
"manufacturer": "/manufacturers/GE",
"engine": "/engines/v12-7",
"hqLatLng": {
"lat": 35.931077,
"lng": -79.643374
}
},
{
"uri": "/locomotives/16",
"type": "Diesel-electric",
"model": "C40-8W ",
"serial_no": "0016",
"emission_tier": "0+",
"fleet": "/fleets/bnsf-1",
"manufacturer": "/manufacturers/GE",
"engine": "/engines/v16-1",
"hqLatLng": {
"lat": 47.781463,
"lng": -116.940009
... SNIP
]
Wild Card Search with Regular Expression
This query returns any objects that have an expression matching a pattern of strings in the set.
<asset-app-url>/locomotives?filter=type=/.*ese.*/
Returns
[
{
"uri": "/locomotives/1",
"type": "Diesel-electric",
"model": "ES44AC",
"serial_no": "001",
"emission_tier": "0+",
"fleet": "/fleets/up-1",
"manufacturer": "/manufacturers/GE",
"engine": "/engines/v12-1",
"installedOn": "01/12/2005",
"dateIso": "2005-12-01T13:15:31Z",
"hqLatLng": {
"lat": 33.914605,
"lng": -117.253374
}
},
{
"uri": "/locomotives/10",
"type": "Diesel-electric",
"model": "SD70ACe",
"serial_no": "0010",
"emission_tier": "0+",
"fleet": "/fleets/up-4",
"manufacturer": "/manufacturers/electro-motive-diesel",
"engine": "/engines/v16-2-5",
"hqLatLng": {
"lat": 47.941049,
"lng": -100.126484
}
},
{
"uri": "/locomotives/11",
"type": "Diesel-electric",
"model": "ES44AC",
"serial_no": "0011",
"emission_tier": "0+",
"fleet": "/fleets/up-4",
"manufacturer": "/manufacturers/GE",
"engine": "/engines/v12-6",
"hqLatLng": {
"lat": 32.7086,
"lng": -108.190375
}
},
...SNIP