Getting Started: Sending Commands
The API used to communication with Spectre Dimensioners on the same network uses HTTP REST/SOAP. It is not encrypted, and should only be used in local networks if message privacy is important. The default port used is 7100, although it is configurable in the config.xml. Requests are made as either a POST or GET request to the serverβs IP address on the specified port. The server responds with either XML or binary data in the case of a file request.
Formatting a Single Commandβ
A majority of API commands can be issued as either GET or POST requests. If a particular request type is unavailable for the command, it will not be shown.
Below is a sample of how each request looks based on content type (JSON or XML), and request type (POST or GET).
Requestβ
- GET
- POST
Endpointβ
Cargo Spectre GET requests do not expect a body. A sample request looks like:
Case sensitivity
ApiName
is not case-sensitive and can be either capitalized or lower case. For instance, this is an equally valid GET request:Capital Api Names
Although ApiNames can be lowercased, capital is recommended because Parameters cannot be capitalized.
Headerβ
- XML
- JSON
Desired response format:
Accept: application/xml
(DEFAULT)Desired response format:
Accept: application/json
Endpointβ
A Cargo Spectre POST request is sent to the machine without any API in the endpoint, as below:
Headerβ
- XML
- JSON
Desired response format:
Accept: application/xml
(DEFAULT)Desired response format:
Accept: application/json
Bodyβ
- XML
- JSON
<Requests>
<ApiName1>
<ApiInputTree>
</ApiName1>
</Requests>
{
"Requests":{
"ApiName1":{
"ApiInputTree":{}
}
}
}
Responseβ
Responses are returned in either XML or JSON depending on the accept header provided.
Small changes to outputs may occur
Cargo Spectre reserves the right to append additional nodes to the paths. Cargo Spectre will not remove or rearrange paths (e.g. /Responses/Dimension/Info/Dimensions/
will not disappear, nor will it become /Responses/Dimension/Output/Dimensions/
) but some paths may be 'tacked on' (e.g. /Responses/Dimension/Info/AdditionalData/
)
Such 'tacking on' may result in your code receiving unexpectedly longer outputs; if you are searching for keywords on specific line-numbers, your code may break.
Use a JSON/XML parser with the full path to make your code as resilient as possible.
Node names not guaranteed to be unique, but full paths are
Cargo Spectre highly recommends parsing the full XML or JSON tree instead of looking for a setting at a specific line number or by a specific keyword. Cargo Spectre promises that paths will be unique, but specific node names may not. E.g. 'Dimension' might be repeated, but /Responses/Dimension/Output/Dimensions/
will not.
Use a JSON/XML parser with the full path to make your code as resilient as possible.
- XML
- JSON
<Responses>
<ApiName1 code="0">
<ApiOutputTree/>
</ApiName1>
</Responses>
Or, for simple requests:
<Responses>
<ApiName1 code="0"/>
</Responses>
{
"Responses":{
"ApiName1":{
"code":"0",
"ApiOutputTree":{}
}
}
}
Or, for simple requests:
{
"Responses":{
"ApiName1":{
"code":"0"
}
}
}
Example: <Ping\> a Machineβ
The Ping
command is useful on app startup to ensure that a machine is still active. It can also be used to check machine state intermittently throught operation.
Requestβ
Request a ping from a machine with local IP address 10.1.1.2
set to port 7100
to check that the machine is active.
- GET
- POST
Endpointβ
Headerβ
- XML
- JSON
Desired response format:
Accept: application/xml
(DEFAULT)Desired response format:
Accept: application/json
Endpointβ
A Cargo Spectre POST request is sent to the machine without any API in the endpoint, as below:
Headerβ
- XML
- JSON
Desired response format:
Accept: application/xml
(DEFAULT)Desired response format:
Accept: application/json
Bodyβ
- XML
- JSON
<Requests>
<Ping/>
</Requests>
{
"Requests":{
"Ping":{}
}
}
Responseβ
Ping
, like all Dimensioner APIs, returns a status code of 0 if the command executed successfully. Checking for code 0 before continuing ensures successful operation of your integrated app.- XML
- JSON
<Responses>
<Ping code="0"/>
</Responses>
{
"Responses": {
"Ping": {
"code": "0",
"value": ""
}
}
}
Sending Multiple Commands in a Requestβ
Multiple commands can be sent in one request with either request type. Cargo Spectre expects all API commands to be sent within a single Requests
tag
- GET
- POST
Endpointβ
A sample request for ApiName1
and ApiName2
is concatenated with a +
between the two commands.
Capital ApiNames
Although ApiNames can be lower case, it is recommended to capitalize them to avoid confusion given that parameters are currently case-sensitive.
Headerβ
- XML
- JSON
Desired response format:
Accept: application/xml
(DEFAULT)Desired response format:
Accept: application/json
Endpointβ
For POST requests, all that is needed is to include the second command at the same level of the XML or JSON as the first command.
Headerβ
- XML
- JSON
Desired response format:
Accept: application/xml
(DEFAULT)Desired response format:
Accept: application/json
Bodyβ
- XML
- JSON
<Requests>
<ApiName1>
<ApiInputTree>
</ApiName1>
<ApiName2/>
</Requests>
{
"Requests":{
"ApiName1":{
"ApiInputTree":{}
},
"ApiName2":{}
}
}
Sending Parameters in Requestsβ
Commands can accept certain parameters.
- GET
- POST
Endpointβ
The request for two API commands is modified below for the instance where two commands can accept certain parameters; in this case, the sample inputs Value
and Return
.
However, as an unfortunate exception to the capitalization rule above, the parameter name must be capitalized.
Or
For this reason, it is recommended to simply use capital first letters for API names to avoid confusion.
Headerβ
- XML
- JSON
Desired response format:
Accept: application/xml
(DEFAULT)Desired response format:
Accept: application/json
Endpointβ
For POST requests, parameters need to be beneath their respective commands in the tree. As in /Requests/Command/Parameter. They cannot be at the same level or they will be treated as commands themselves (and usually not be recognized).
Headerβ
- XML
- JSON
Desired response format:
Accept: application/xml
(DEFAULT)Desired response format:
Accept: application/json
Bodyβ
- XML
- JSON
<Requests>
<ApiName1>
<Value>somevalue</Value>
</ApiName1>
<ApiName2/>
<ApiName3>
<Return>3</Return>
</ApiName3>
</Requests>
{
"Requests":{
"ApiName1":{
"Value":"somevalue"
},
"ApiName2":{},
"ApiName3":{
"Return":3
}
}
}
Requesting Multiple Parameters Per Commandβ
Some commands can accept multiple parameters.
- GET
- POST
Endpointβ
The &
operator is used to indicate to the machine the presence of a second parameter. The below request sends a command with no parameters, then one parameter, then two.
info
In the example below, the ApiName3
command receives two parameters called Param
and SecondParam
, as in:
ApiName3?Param=value&SecondParam=value
.Headerβ
- XML
- JSON
Desired response format:
Accept: application/xml
(DEFAULT)Desired response format:
Accept: application/json
Endpointβ
For POST requests, all that is needed is to include the second parameter at the same level as the first parameter.
Headerβ
- XML
- JSON
Desired response format:
Accept: application/xml
(DEFAULT)Desired response format:
Accept: application/json
Bodyβ
- XML
- JSON
<Requests>
<ApiName1/>
<ApiName2>
<Value>somevalue</Value>
</ApiName2>
<ApiName3>
<Param>false</Param>
<SecondParam>4</SecondParam>
</ApiName3>
</Requests>
{
"Requests":{
"ApiName1":{},
"ApiName2":{
"Value":"somevalue"
},
"ApiName3":{
"Param":false,
"SecondParam":4
}
}
}
Escaped Values in GET Requestsβ
Certain values need to be encoded in GET requests to be properly parsed.
Similar to how some code requires one to escape special characters with backslashes, e.g. \"
instead of simply a "
, Cargo Spectre requires users of GET requests to escape certain characters with a delimiter. This delimiter signifies that the next characters after it should be converted into a special character instead of parsed as a basic string or as an API command.
The %5C
delimiter is used to specify that. You might recognize it as the URL-safe encoding for a backslash.
Examplesβ
For instance, if a SetSetting
API command is used to set the name of a machine to Test Machine
, the following will not work:
- Incorrect Machine Name Request
- Incorrect Machine Name Result
Test
Similarly, simply setting the HTTP-appropriate encoding of the space character will not work as Cargo Spectre reserves %20
to delimit commands in the Proxy API.
- Incorrect Machine Name Request
- Incorrect Machine Name Result
Test%20Machine
Only escaping the URL-safe encoding of the space character will cause it to be properly parsed. This is because Cargo Spectre reserves the URL-safe encoding of the backslash as a way to escape such characters.
- Correct Machine Name Request
- Correct Machine Name Result
Test Machine
Table of All Special Charactersβ
All of the characters in the right column must be written as %5C___
in order to be properly read.
Example: A "+" is represented as %5C%2B
.
Encoded Character | Character |
---|---|
%20 | (space) |
%5C | \ |
%2B | + |
%25 | % |
%26 | & |
%3D | = |