Skip to content

Command

George E Fouche edited this page Sep 12, 2017 · 9 revisions

Description: Command

The Command service is used for creating commands and interacting with them. Commands are specific instructions sent to the Predix Mobile service where they are picked up by the Command Processor for processing. See Mobile Service Overview for more information on Commands, the Command Processor, and the CQRS pattern.

Commands contain three main elements:

body : A free-form dictionary of name/value pairs to be interpreted by the Predix Mobile Service Command Processor
targetDocuments : An optional array of document Ids associated with this Command
tag : an optional string that can be used to group or identify commands.

When returned, the command dictionary will also contain:

commandId : A unique identifier for this command
type : The string "command", which is the document type associated with Commands.

Example Response:

{
   "command":{
      "body":{
         "someKey":"someValue"
      },
      "targetedDocuments":[
         "document1",
         "document2"
      ],
      "tag":"someTag",
      "commandId":"command1234",
      "type":"command"
   },
   "targetDocumentData":[
      {
         "_id":"document1",
         "document1Keys":"document1Values"
      },
      {
         "_id":"document2",
         "document2Keys":"document2Values"
      }
   ]
}
	

Creating a Command

Method: POST

URL: http://pmapi/command

Input: JSON dictionary consisting of:

body : Dictionary of name/value pairs encompassing the command for the Command Processor.
targetDocuments : Optional array of document Ids associated with this Command.
tag : an optional string that can be used to group or identify commands.

Output:

If successful, a JSON dictionary containing two top-level elements:

command : The contents of the created Command.
targetDocumentData : An array of dictionaries, each dictionary being the contents of one of the targetDocuments of the Command.

Standard HTTP status codes, including:

  • 201 - The Command document was created successfully
  • 400 - The input JSON was incorrect
  • 500 - An error occurred creating the command

Example:

POST http://pmapi/command

{
  "body": {
    "someKey": "someValue"
  },
  "targetedDocuments": [
    "document1",
    "document2"
  ],
  "tag": "someTag"
}
	

Updating a Command

Method: PUT

URL: http://pmapi/command/{commandId}

Input: Same as POST, JSON dictionary consisting of:

body : Dictionary of name/value pairs encompassing the command for the Command Processor. targetDocuments : Optional array of document Ids associated with this Command.
tag : an optional string that can be used to group or identify commands.

Output:

If successful, a JSON dictionary containing two top-level elements:

command : The contents of the created Command.
targetDocumentData : An array of dictionaries, each dictionary being the contents of one of the targetDocuments of the Command.

Standard HTTP status codes, including:

  • 200 - The Command document was updated successfully
  • 400 - The input JSON was incorrect
  • 500 - An error occurred updating the command

Example:

POST http://pmapi/command

{
  "body": {
    "someKey": "someValue"
  },
  "targetedDocuments": [
    "document1",
    "document2"
  ],
  "tag": "someTag"
}
	

Retrieving a Command

Method: GET

URL: http://pmapi/command/{commandId}

Output:

If successful, a JSON dictionary containing two top-level elements:

command : The contents of the Command targetDocumentData : An array of dictionaries, each dictionary being the contents of one of the targetDocuments of the Command.

Standard HTTP status codes, including:

  • 200 - The document was found and returned
  • 404 - {commandId} was not found
  • 500 - An error occurred retrieving the command

Retrieving all Commands

Method: GET

URL: http://pmapi/command

Output:

A JSON array of all Commands on the local system. Only the Commands themselves are returned, not related Target Documents.

Example Response:

[
  {
    "body": {
      "someCommand1Key": "someCommand1Value"
    },
    "targetedDocuments": [
      "document1",
      "document2"
    ],
    "tag": "someTag",
    "commandId": "command1",
    "type": "command"
  },
  {
    "body": {
      "someCommand2Key": "someCommand2Value"
    },
    "commandId": "command2",
    "type": "command"
  },
  {
    "body": {
      "someCommand3Key": "someCommand3Value"
    },
    "targetedDocuments": [
      "document2"
    ],
    "commandId": "command3",
    "type": "command"
  }
]
Clone this wiki locally