POST
Use the HTTP POST method with this resource to submit administrative commands directly to a queue manager.
We can use this REST API command with HTTP to run any MQSC command that is not part of the administrative REST API.
On UNIX, Linux , and Windows, this REST API command is similar to the Escape PCF command.
On z/OSĀ®, this REST API command is similar to submitting commands directly to the command server:
- Messages are put to a request queue. These messages have:
- MsgType set to MQMT_REQUEST.
- Format set to MQFMT_STRING or MQFMT_NONE.
- Payload set to the text of an MQSC command.
- The command server running in the queue manager:
- Reads the messages.
- Validates them.
- Passes valid commands to the command processor.
- The command processor:
- Executes the commands.
- Puts replies to the commands as messages on the reply-to queues specified in the incoming messages.
This REST API is deliberately lightweight in approach. Commands are submitted to the specified queue manager and the results are returned in an unprocessed format. For examples of this format, see the Example - z/OS section.
- Resource URL
- Request headers
- Request body format
- Security requirements
- Response status codes
- Response headers
- Response body format
- Example - z/OS
Resource URL
Version 9.0.4 and later:
https://host:port/ibmmq/rest/v1/admin/action/qmgr/qmgrName/mqsc
- qmgrName
- Specifies the name of the queue manager on which to execute the command.
We can use HTTP instead of HTTPS if you enable HTTP connections. For more information about enabling HTTP, see Configure HTTP and HTTPS ports.
Request headers
The following headers must be sent with the request:
- Content-Type
- This header must be sent with a value of application/json;charset=utf-8.
- ibm-mq-rest-csrf-token
- This header must be sent with a value that is the content of the csrfToken cookie. The content of the csrfToken cookie is used to confirm that the credentials that are being used to authenticate the request are being used by the owner of the credentials. That is, the token is used to prevent cross-site request forgery attacks.
- Authorization
- This header must be sent if you are using basic authentication. For more information, see Use HTTP basic authentication with the REST API.
Request body format
The request body must be in JSON format in UTF-8 encoding. Within the request body attributes are defined, and named JSON objects are created to specify extra attributes. Any attributes that are not specified use the default value.
The following attributes can be included in the request body:
- type
- Required.
- parameters
- Required.
Security requirements
The caller must be authenticated to the mqweb server and must be a member of one or more of the MQWebAdmin, MQWebAdminRO, or MQWebUser roles. For more information about security for the administrative REST API, see IBM MQ Console and REST API security.
The security principal of the caller must be granted the ability to issue such MQSC commands against the specified queue manager as they specify.
On UNIX, Linux, and Windows, we can grant authority to security principals to use IBM MQ resources by using the mqsetaut command. For more information, see mqsetaut.
On z/OS, see Set up security on z/OS.
Response status codes
- 200
- The specified command was executed successfully.
- 400
- Invalid data provided.
- 401
- Not authenticated.
- 403
- Not authorized.
- 500
- Server issue or error code from IBM MQ.
- 503
- Queue manager not running.
Response headers
None.
Response body format
If an error occurs, the response body contains an error message. For more information, see REST API error handling.
The format of the response body is standardized, with a consistent JSON schema. However, the content is platform-dependent, reflecting the underlying mechanism for executing MQSC commands.
The response body has the following JSON structure:{ "commandResponse" : [ { "completionCode" : number, "reasonCode" : number, "text" : [ "string", ... ] }, ... ] "overallCompletionCode" : number, "overAllReasonCode" : number }The fields in the response have the following meanings:
- commandResponse
- A JSON array of JSON objects that represent individual responses from the execution of the command.
- overallCompletionCode
- The completion code that is associated with the operation as a whole.
- overallReasonCode
- The reason code that is associated with the operation for this instance.
Example - z/OS
The following sequence shows how to create a new server-connection channel that is called NEWSVRCONN on a z/OS queue manager - our example queue manager is called QM21.
- First check that the channel does not exist. The following URL is used with the HTTP POST method: Version 9.0.4 and later:
https://localhost:9443/ibmmq/rest/v1/admin/action/qmgr/QM21/mqscThe following JSON payload is sent:{ "type": "runCommand", "parameters": { "command": "DISPLAY CHANNEL(NEWSVRCONN)" } }A response code of 200 is returned, as the REST command succeeded. The response body that is returned contains the following JSON.{ "commandResponse": [ { "completionCode": 0, "reasonCode": 0, "text": [ "CSQN205I COUNT= 3, RETURN=00000000, REASON=00000000", "CSQM297I ]MQ21 CSQMDRTS NO CHANNEL FOUND MATCHING REQUEST CRITERIA ", "CSQ9022I ]MQ21 CSQMDRTS ' DISPLAY CHANNEL' NORMAL COMPLETION " ] } ], "overallCompletionCode": 0, "overallReasonCode": 0 }The completion and reason codes here are zero, as on z/OS the command is regarded as succeeding, although no matching channel was.- Now create the channel. The same URL is used with the HTTP POST method: Version 9.0.4 and later:
https://localhost:9443/ibmmq/rest/v1/admin/action/qmgr/QM21/mqscThe following JSON payload is sent:{ "type": "runCommand", "parameters": { "command": "DEFINE CHANNEL(NEWSVRCONN) CHLTYPE(SVRCONN)" }A response code of 200 is returned, as the REST command succeeded. The response body that is returned contains the following JSON.{ "commandResponse": [ { "completionCode": 0, "reasonCode": 0, "text": [ "CSQN205I COUNT= 2, RETURN=00000000, REASON=00000000", "CSQ9022I ]MQ21 CSQMACHL ' DEFINE CHANNEL' NORMAL COMPLETION" ] } ], "overallCompletionCode": 0, "overallReasonCode": 0 }- Finally, check that the channel does exist. Again the same URL is used with the HTTP POST method: Version 9.0.4 and later:
https://localhost:9443/ibmmq/rest/v1/admin/action/qmgr/QM21/mqscThe following JSON payload is sent:{ "type": "runCommand", "parameters": { "command": "DISPLAY CHANNEL(NEWSVRCONN) ALL" } }A response code of 200 is returned, as the REST command succeeded. The response body that is returned contains the following JSON. The response body is edited for brevity after the TRPTYPE attribute.{ "commandResponse": [ { "completionCode": 0, "reasonCode": 0, "text": [ "CSQN205I COUNT= 3, RETURN=00000000, REASON=00000000", "CSQM415I ]MQ21 CHANNEL(NEWSVRCONN ) CHLTYPE(SVRCONN ) QSGDISP(QMGR ) DEFCDISP(PRIVATE ) TRPTYPE(LU62 )", "CSQ9022I ]MQ21 CSQMDRTS ' DISPLAY CHANNEL' NORMAL COMPLETION " ] } ], "overallCompletionCode": 0, "overallReasonCode": 0 }
Example - UNIX, Linux, and Windows
The following sequence shows how to create a new server-connection channel that is called NEWSVRCONN on UNIX, Linux, and Windows queue managers - our example queue manager is called QM_T1.
- First check that the channel does not exist. The following URL is used with the HTTP POST method: Version 9.0.4 and later:
https://localhost:9443/ibmmq/rest/v1/admin/action/qmgr/QM_T1/mqscThe following JSON payload is sent:{ "type": "runCommand", "parameters": { "command": "DISPLAY CHANNEL(NEWSVRCONN)" } }A response code of 200 is returned, as the REST command succeeded. The response body that is returned contains the following JSON.{ "commandResponse": [ { "completionCode": 2, "reasonCode": 2085, "text": [ "AMQ8147: IBM MQ object NEWSVRCONN not found." ] } ], "overallCompletionCode": 2, "overallReasonCode": 3008 }The individual response shows a reason code of 2085 (MQRC_UNKNOWN_OBJECT_NAME) and the MQSC command has an overall reason code of 3008 (MQRCCF_COMMAND_FAILED) as it failed to display the requested channel's details.- Now create the channel. The same URL is used with the HTTP POST method: Version 9.0.4 and later:
https://localhost:9443/ibmmq/rest/v1/admin/action/qmgr/QM_T1/mqscThe following JSON payload is sent:{ "type": "runCommand", "parameters": { "command": "DEFINE CHANNEL(NEWSVRCONN) CHLTYPE(SVRCONN)" }A response code of 200 is returned, as the REST command succeeded. The response body that is returned contains the following JSON.{ "commandResponse": [ { "completionCode": 0, "reasonCode": 0, "text": [ "AMQ8014: IBM MQ channel created." ] } ], "overallCompletionCode": 0, "overallReasonCode": 0 }- Finally, check that the channel does exist. Again the same URL is used with the HTTP POST method: Version 9.0.4 and later:
https://localhost:9443/ibmmq/rest/v1/admin/action/qmgr/QM_T1/mqscThe following JSON payload is sent:{ "type": "runCommand", "parameters": { "command": "DISPLAY CHANNEL(NEWSVRCONN) ALL" } }A response code of 200 is returned, as the REST command succeeded. The response body that is returned contains the following JSON. The response body is edited for brevity after the CHLTYPE attribute.{ "commandResponse": [ { "completionCode": 0, "reasonCode": 0, "text": [ "AMQ8414: Display Channel details. CHANNEL(NEWSVRCONN) CHLTYPE(SVRCONN)" ] } ], "overallCompletionCode": 0, "overallReasonCode": 0 }