Using command line (cURL) to validate RESTful APIs

cURL is a command-line tool for getting or sending files using URL syntax. The following procedure describes the format and syntax used when making Web Services REST API requests with cURL.

Listed below are scripts validated on the following cURL executable versions by OS:
Table 1. Supported cURL executable versions
OS cURL executable version

Windows

v7.64.1

Linux

v7.29.0

Solaris

v7.59.0

zLinux

v7.29.0
AIX v7.64.1

SignOn

About this task

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.

Procedure

  1. Encode the IBM® Connect:Direct user name and password into Base64. To encode the username and password use URL in the following format:
    https://<CDWS_IPAddress:Port>/cdws-doc/base64encode.html
  2. Set the Request Header to:
    Authorization
    Basic <Encoded_Password>' -H '
    
    Content-Type
    application/json" -X POST -d
    '{"ipAddress":"CDNodeIp","protocol":"NONE || TLS1.2 ||
    TLS1.3","port":'1363'}'-k
    
    X-XSRF-TOKEN
    <Y2hlY2tpdA== (fixed for signon request )>'-H
  3. Complete the Request body as follows:
    curl -s -i -H ' Authorization: Basic <Encoded_Password>' -H 
    'X-XSRF-TOKEN:<Y2hlY2tpdA== (fixed for signon request )>' -H 
    "Content-Type: application/json"-X POST -d '{"ipAddress":"CDNodeIp",
    "protocol":"NONE || TLS1.2 || TLS1.3","port":'1363'}'-k
    https://<CDWS_IPAddress:Port>/cdwebconsole/svc/signon 
  4. Response message received as follows:
    HTTP/1.1 200 OK
    Date: Tue, 14 May 2019 07:46:03 GMT
    
    Set-Cookie:
    XSRF-TOKEN=1086bae5-3073-4a8f-afbe-b3d3199d6812;Path=/;Secure;
    
    HttpOnly _csrf:
    1086bae5-3073-4a8f-afbe-b3d3199d681
    
    osType: WINDOWS
    
    Content-Type:application/json;charset=iso-8859-1
    
    Authorization:
    eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbmlzdHJhdG9yOjE3Mi4yMC4xODYuNz
    Q6MTM2Mzo1NmIwNDFkZS0yYmI1LTQyMTUtOGI4OC02ZjMwYzU1NmE2NTUiLCJleHAiOjE1
    NTc4MjIzNjN9.z2la7UyfICFWkMtaO8xJ6kv2Llth-u8kRLXH8tIOTsKm_82jeNE-Rdl2q
    fQGUlRdl2qifQGUlT4gOs9BhyWAN4JGPde5Fo5g
    
    Expires: Thu, 01 Jan 1970 00:00:00 GMT
    
    Cache-Control: no-cache, no-store,must-revalidate,max-age=0
    
    Pragma: no-cache
    
    Strict-Transport-Security: max-age=31536000 ;includeSubDomains
    
    X-XSS-Protection: 1; mode=block
    
    X-Content-Type-Options: nosniff Content-Security-Policy: default-src 'self'
    
    X-Content-Type-Options:nosniff
    
    X-Frame-Options: DENY
    
    Set-Cookie:JSESSIONID=node01jk2nfvlk2nyjq4ubgnot3j7r4.node0;Path=/;Secure;HttpOnly
    
    Content-Length:70
    [
        {
            "messageCode": 200,
            "message": "Signon is successful",
            "version": "CDWS_VERSION_NO",
            "nodeName": "CD_NODE_NAME"
        }
    ]
  5. User receives an Authorization. jsessionid, and XSRF token in response header that can be used to execute other RESTful APIs.
    XSRF-TOKEN=1086bae5-3073-4a8f-afbe-b3d3199d6812;Path=/;Secure;
    HttpOnly _csrf:1086bae5-3073-4a8f-afbe-b3d3199d6812
    
    Authorization:
    eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbmlzdHJhdG9yOjE3Mi4yMC4xODYuNz
    Q6MTM2Mzo1NmIwNDFkZS0yYmI1LTQyMTUtOGI4OC02ZjMwYzU1NmE2NTUiLCJleHAiOjE1
    NTc4MjIzNjN9.z2la7UyfICFWkMtaO8xJ6kv2Llth-u8kRLXH8tIOTsKm_82jeNE-Rdl2
    qifQGUlRdl2qifQGUlT4gOs9BhyWAN4JGPde5Fo5g
    
    JSESSIONID=node01jk2nfvlk2nyjq4ubgnot3j7r4.node0;Path=/;Secure;HttpOnly

Example 1: Submit a Process using cURL

About this task

The following example describes steps to execute a Submit Process Control RESTful API using cURL.

Procedure

  1. Call the SignOn API and get the authorization token, jsessionID, and XSRF-TOKEN token from the header in the response.
    Authorization:
    eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJBZG1pbmlzdHJhdG9yOjE3Mi4yMC4xODYuMzU6
    MTM2MzplMDI0YjAzZC03NzkwLTQxMjItOTZkOC1iZjg5MmY5NDcxM2MiLCJleHA
    iOjE1NTcxMjcyMTJ9.ME_mniwgmrzVL214ijhxNzU-bgHw9bv-Ktz8WL84ljpEYtgm89jf
    H7ehspyk-zgS6J8JiL2GJrG3JYo1REs1w
    
    XSRF:
    809ab7e8-c6be-41ac-84f1-b4f8db246d9e
    
    JSessionID:
    node04p0v71bx6q46u2qthvr32htv3.node0 
  2. Submit a cURL request at the following URL
    https://<CDWS_IPAddress:Port>/cdwebconsole /svc/processcontrolcriterias
  3. Call the API with the XSRF header as X-XSRF-TOKEN:
    X-XSRF-TOKEN: <XSRF_Token_From_Step_1>
  4. Set the content type to:
    Content-Type: application/json
  5. Set the request body to:
    "processFile":"<processFilePathWithName>"
  6. Complete request body as follows:
    curl -s -i --cookie' 
    XSRFTOKEN=<XSRF_TOKEN_FROM_RESPONSE_HEADER>;
    JSESSIONID=<JSESSIONID_FROM_RESPONSE_HEADER>;' -H ' 
    Authorization:<AUTHORIZATION_TOKEN_ FROM_RESPONSE_HEADER> ' -H '
    Content-Type: application/json' -H
    'X-XSRF-TOKEN: <XSRF_TOKEN_FROM_RESPONSE_HEADER>' -X 
    POST -d'{"processFile":"<processFilePathWithName>"}' -k
  7. Response received as follows:
    [
    {
     "messageCode" : 201,
     "message" : "The process has been
    successfully submitted with processNumber '10'" 
    }
    ] 

Example 2: Select Statistics for a Process using cURL

About this task

The following example describes steps to execute a Submit Select Statistics RESTful API using cURL.

Procedure

  1. Call the SignOn API and get the authorization token, jsessionID, and XSRF-TOKEN token from the header in the response
    Authorization:
    eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJBZG1pbmlzdHJhdG9yOjE3Mi4yMC4x
    ODYuMzU6MTM2MzplMDI0YjAzZC03NzkwLTQxMjItOTZkOC1iZjg5Mm
    Y5NDcxM2MiLCJleHAiOjE1NTcxMjcyMTJ9.ME_mni-wgmrzVL214ijhxNz
    U-bgHw9bv-Ktz8WL84ljpEYtgm89jfH7ehspyk-zgS6J8JiL2GJrG3JYo1REs1w
    
    XSRF:
    809ab7e8-c6be-41ac-84f1-b4f8db246d9e 
    
    JSessionID:
    node04p0v71bx6q46u2qthvr32htv3.node0
  2. Submit a cURL request at the following URL
    https://<CDWS_IPAddress:Port>/cdwebconsole/svc/processcontrolcriterias
  3. Call the API with the XSRF header as X-XSRF-TOKEN:
    X-XSRF-TOKEN : <XSRF_Token_From_Step_1>
  4. Set the content type to:
    Content-Type: application/json
  5. Set the request body to:
    "processFile":"<processFilePathWithName>"
  6. Complete request body as follows:
    curl -s -i --cookie ''XSRF-TOKEN=<XSRF_TOKEN_FROM_RESPONSE_HEADER>;
    JSESSIONID=<JSESSIONID_FROM_RESPONSE_HEADER>; ' -H '
    Authorization:<AUTHORIZATION_TOKEN_ FROM_RESPONSE_HEADER> ' -H '
    Content-Type: application/json' -H 'X-XSRF-TOKEN: <XSRF_TOKEN_FROM_RESPONSE_HEADER>' 
    GET -k https://<CDWS_IPAddress:Port>/cdwebconsole/svc/selectstatistics?processNumber=10
  7. 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": 10,
     "secondaryNode": "CDWLT-025"
     }
    ]

Sign Out

About this task

This procedure describes process to Sign Out.

Procedure

  1. Call the SignOn API and get the authorization token, XSRF-TOKEN token, and JSESSION ID from the header in the response
    .
    Authorization:
    eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJBZG1pbmlzdHJhdG9yOjE3Mi4yMC4xODYuMzU6MTM2MzplMDI0YjAzZC
    03NzkwLTQxMjItOTZkOC1iZjg5MmY5NDcxM2MiLCJleHAiOjE1NTcxMjcyMTJ9.ME_mni-wgmrzVL214ijhxNzU-
    bgHw9bv-Ktz8WL84ljpEYtgm89jfH7ehspyk-zgS6J8JiL2GJrG3JYo1REs1w
    XSRF:
    809ab7e8-c6be-41ac-84f1-b4f8db246d9e
    JSessionID:
    node04p0v71bx6q46u2qthvr32htv3.node0
  2. Submit a DELETE request at the following:
     https://<CDWS_IPAddress:Port>/cdwebconsole/svc/signout 
  3. Call the API with the Authorization header:
    Authorization: <Authorization Token_From_Step_1>
  4. Call the API with the XSRF header as X-XSRF-TOKEN:
    X-XSRF-TOKEN : <XSRF_Token_From_Step_1>
  5. Call the API with the JSESSEION ID:
    JSESSION ID : <JESSIONID_From_Step_1>
  6. Set the content type to:
    Content-Type: application/json
  7. Set the request body as follows:
    {
    "userAccessToken": "<Access_Token_From_Step_1>"
    }
  8. Complete the request body as follows:
    curl -s -i --cookie 'XSRF-TOKEN=<XSRF_TOKEN_FROM_RESPONSE_HEADER>;
    JSESSIONID=<JSESSIONID_FROM_RESPONSE_HEADER>; ' -H '
    Authorization:<AUTHORIZATION_TOKEN_ FROM_RESPONSE_HEADER> ' -H '
    Content-Type: application/json' -H 'X-XSRF-TOKEN: <XSRF_TOKEN_FROM_RESPONSE_HEADER>'
    -X DELETE -d '{"userAccessToken":"<AUTHORIZATION_TOKEN_ FROM_RESPONSE_HEADER> "}' 
    -k 
  9. Response received as follows:
    {
     "signOut" : true,
     "userId" : "administrator"
    }