Using REST Client to validate RESTful APIs
A third-party application, such as Postman, can be used to make REST API calls. Postman is available for download at https://www.getpostman.com/ and is used in the example procedures in the following sections.
Sign On
Sign On is required to use all IBM Connect:Direct Web Service RESTful APIs.
Note: Ensure that the authorization header is included each time a RESTful API is invoked for
authentication.
Sign On procedure
- Make a POST request to the URL
https://<CDWS_IPAddress:Port>/cdwebconsole/svc/signon
. - Encode the IBM® Connect:Direct user name and password into Base64. To encode the username and
password use URL
https://<CDWS_IPAddress:Port>/cdws-doc/base64encode.html
.For example, encoded password for admin:password123 becomes YWRtaW46cGFzc3dvcmQxMjM=.
- Set the Request Header to:
Authorization Basic <Encoded_Password from step 2 e.g. YWRtaW46cGFzc3dvcmQxMjM=> Content-Type application/json; charset=iso-8859-1 X-XSRF-TOKEN Y2hlY2tpdA== (fixed for the first time)
- Set the Request body and submit the request
{ "ipAddress":"CDNODE IP", "port":1363, "protocol":"NONE || TLS1.2 || TLS1.3" }
- Complete the Request body as follows:
POST /cdwebconsole/svc/signon HTTP/1.1 Host: <CDWS_IPAddress:Port> Content-Type: application/json; charset=utf-8 X-XSRF-TOKEN: Y2hlY2tpdA== Authorization: Basic QWRtaW5pc3RyYXRvcjpNc3dAMTIzIQ== Cache-Control: no-cache { "ipAddress":"172.20.186.35", "protocol":"tcpip", "port":1363 }
- Response message received as follows:
[ { "messageCode": 200, "message": "Signon is successful", "version": "CDWS_VERSION", "nodeName": "CD_NODE_NAME" } ]
- User receives an Authorization and XSRF token in response header that can be used to execute
other RESTful APIs.
Authorization: eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJBZG1pbmlzdHJhdG9yOjE3Mi4yMC4xODYuMzU6MTM2MzplMDI 0YjAzZC03NzkwLTQxMjItOTZkOC1iZjg5MmY5NDcxM2MiLCJleHAiOjE1NTcxMjcyMTJ9.ME_mni-wgm rzVL214ijhxNzU-bgHw9bv-Ktz8WL84ljpEYtgm89jfH7ehspyk-zgS6J8JiL2GJrG3JYo1REs1w XSRF: 809ab7e8-c6be-41ac-84f1-b4f8db246d9e
Example 1: Submit a Process using REST API
Workflow
The following example describes steps to execute a Submit Process Control RESTful API using POST method.
- Call the SignOn API and get the authorization token and XSRF-TOKEN token from the header
in the response.
Authorization: eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJBZG1pbmlzdHJhdG9yOjE3Mi4yMC4xODYu MzU6MTM2MzplMDI0Y jAzZC03NzkwLTQxMjItOTZkOC1iZjg5MmY5NDcxM2MiLCJleHAiOjE1NTcxMjcyMTJ9.ME_mni-wgmrzVL 214ijhxNzU-bgHw9bv-Ktz8WL84ljpEYtgm89jfH7ehspyk-zgS6J8JiL2GJrG3JYo1REs1w XSRF: 809ab7e8-c6be-41ac-84f1-b4f8db246d9e
- Submit a POST request at the following URL:
https://<CDWS_IPAddress:Port>/cdwebconsole/svc/processcontrolcriterias
- Call the API with the Authorization header:
Authorization:<Authorization_Token_From_Step_1>
- Call the API with the XSRF header as X-XSRF-TOKEN:
X-XSRF-TOKEN : <XSRF_Token_From_Step_1>
- Set the content type to:
Content-Type: application/json; charset=utf-8
- Set the request body to:
{ "processFile": "C:\Users\Administrator\Desktop\test.cdp" }
- Complete request body as follows:
POST /cdwebconsole/svc/processcontrolcriterias HTTP/1.1 Host: <CDWS_IPAddress:Port> Content-Type: application/json X-XSRF-TOKEN: 809ab7e8-c6be-41ac-84f1-b4f8db246d9e Authorization: eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJBZG1pbmlzdHJhdG9yOjE3Mi4yMC4x ODYuMzU6MTM2MzplMDI0YjAzZC03NzkwLTQxMjItOTZkOC1iZjg5MmY5NDcxM2MiLCJleHAiOjE1 NTcxMjcyMTJ9.ME_mni-wgmrzVL214ijhxNzU-bgHw9bv-Ktz8WL84ljpEYtgm89jfH7ehspyk-z gS6J8JiL2GJrG3JYo1REs1w Cache-Control: no-cache { "processFile": "C:\\Users\\Administrator\\Desktop\\CDWS_AutoInstall\\cd_proc ess_dir \\test.cdp" }
- Response received as follows:
{ "messageCode": 201, "message": "The process has been successfully submitted with processNumber '126'" }
Example 2: Select Statistics for a Process using REST API
Workflow
The following example describes steps to execute a Select Statistics Services RESTful API using GET method.
- Call the SignOn API and get the authorization token and XSRF-TOKEN token from the header
in the response.
Authorization: eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJBZG1pbmlzdHJhdG9yOjE3Mi4yMC4xODYuMzU6MTM2MzplMD I0YjAzZC03NzkwLTQxMjItOTZkOC1iZjg5MmY5NDcxM2MiLCJleHAiOjE1NTcxMjcyMTJ9.ME_mni- wgmrzVL214ijhxNzU-bgHw9bv-Ktz8WL84ljpEYtgm89jfH7ehspyk-zgS6J8JiL2GJrG3JYo1REs1w XSRF: 809ab7e8-c6be-41ac-84f1-b4f8db246d9e
- Submit a GET request at the following URL with process number generated in Example 1: Submit a Process using REST API:
https://<CDWS_IPAddress:Port>/cdwebconsole/svc/selectstatistics? processNumber= 126
- Call the API with the Authorization header:
Authorization: <Authorization _Token_From_Step_1>
- Call the API with the XSRF header as X-XSRF-TOKEN:
X-XSRF-TOKEN : <XSRF_Token_From_Step_1>
- Set the content type to:
Content-Type: application/json; charset=utf-8
- Complete the request body as follows:
Get /cdwebconsole/svc/selectstatistics?processNumber=126 HTTP/1.1 Host: <CDWS_IPAddress:Port> Content-Type: application/json X-XSRF-TOKEN: 809ab7e8-c6be-41ac-84f1-b4f8db246d9e Authorization: eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJBZG1pbmlzdHJhdG9yOjE3Mi4yMC4 xODYuMzU6MTM2MzplMDI0YjAzZC03NzkwLTQxMjItOTZkOC1iZjg5MmY5NDcxM2MiLCJleHAiOj E1NTcxMjcyMTJ9.ME_mni-wgmrzVL214ijhxNzU-bgHw9bv-Ktz8WL84ljpEYtgm89jfH7ehspyk -zgS6J8JiL2GJrG3JYo1REs1w Cache-Control: no-cache
- Response received as follows:
{ "stopTime": "Mon May 06 12:41:32 IST 2019", "submitNode": "CDWLT-025", "msgShortText": "The submit of the process succeeded.", "recordCategory": "CAPR", "startTime": "Mon May 06 12:41:32 IST 2019", "recordId": "SUBP", "conditionCode": 0, "submitter": "Administrator", "messageId": "LCCA013I", "logDateTime": "Mon May 06 12:41:32 IST 2019", "processName": "PP", "processNumber": 127, "secondaryNode": "CDWLT-025" }
Sign Out
Workflow
Sign Out is required to close an active session.
- Call the SignOn API and get the authorization token and XSRF-TOKEN token from the header
in the response.
Authorization: eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJBZG1pbmlzdHJhdG9yOjE3Mi4yMC4xODYuMzU6MTM2MzplMDI0Y jAzZC03NzkwLTQxMjItOTZkOC1iZjg5MmY5NDcxM2MiLCJleHAiOjE1NTcxMjcyMTJ9.ME_mni-wgmrzVL 214ijhxNzU-bgHw9bv-Ktz8WL84ljpEYtgm89jfH7ehspyk-zgS6J8JiL2GJrG3JYo1REs1w XSRF: 809ab7e8-c6be-41ac-84f1-b4f8db246d9e
- Submit a DELETE request at the following:
URL https://<CDWS_IPAddress:Port>/cdwebconsole/svc/SignOut
- Call the API with the Authorization header:
Authorization: <Authorization Token_From_Step_1>
- Call the API with the XSRF header as X-XSRF-TOKEN:
X-XSRF-TOKEN : <XSRF_Token_From_Step_1>
- Set the content type to:
Content-Type: application/json; charset=utf-8
- Set the request body as follows:
{ "userAccessToken": "<Access_Token_From_Step_1>" }
- Complete the request body as follows:
Delete /cdwebconsole/svc/signout HTTP/1.1 Host: 172.20.186.34:9443 Content-Type: application/json Authorization: eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJBZG1pbmlzdHJhdG9yOjE3Mi4yMC4xODYuMz U6MTM2MzplMDI0YjAzZC03NzkwLTQxMjItOTZkOC1iZjg5MmY5NDcxM2MiLCJleHAiOjE1NTcxMjcyMTJ9. ME_mni-wgmrzVL214ijhxNzU-bgHw9bv-Ktz8WL84ljpEYtgm89jfH7ehspyk-zgS6J8JiL2GJrG3JYo1R Es1w X-XSRF-TOKEN: 809ab7e8-c6be-41ac-84f1-b4f8db246d9e Cache-Control: no-cache {"userAccessToken": "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJBZG1pbmlzdHJhdG9yOjE3Mi4yMC4xO DYuMzU6MTM2MzplMDI0YjAzZC03NzkwLTQxMjItOTZkOC1iZjg5MmY5NDcxM2MiLCJleHAiOjE1NTcxMjcy MTJ9.ME_mni-wgmrzVL214ijhxNzU-bgHw9bv-Ktz8WL84ljpEYtgm89jfH7ehspyk-zgS6J8JiL2GJrG3J Yo1REs1w"}
- Response received as follows:
{ "signOut": true, "userId": "Administrator" }