z/OS Connect Enterprise Edition

z/OS Connect

z/OS Connect

Truly RESTful APIs to and from your IBM Z mainframe

 View Only
  • 1.  Need to invoke Api which has FREE FROM REQUEST BODY.

    Posted Thu October 21, 2021 01:44 PM
    Trying to invoke an Api from Zos connect. Request and RESPONSE for the Api is Free form shown below in postman.
    REQUEST BODY. Please understand this is freeform meaning ARRAY or objects can be one or more in this case i am only trying with one.

    [ { "FinBankAcctNum""1234567890"}]  OR

    [ { "FinBankAcctNum": "1234567890"},{ "FinBankAcctNum": "1234567890"}
    ]

    Created Swagger with Body as below.
    - name: requestBody
          in: body
         description: request body with all the data elements that needs to be protected
    schema:
         type: array
         items:
         type: string.

    Copybook created as below.

    05 ReqBody-num            PIC S9999 COMP-5 SYNC.
    06 ReqBody OCCURS 255.
          09 ReqBody2-length PIC S9999 COMP-5 SYNC.
          09 ReqBody2                PIC X(255).
    Cobol program i moved the following into the this.

    MOVE '[ { "FinBankAcctNum": "1234567890"}]'   TO ReqBody2

    Api Received the following payload.
    ["[ { \"FinBankAcctNum\": \"1234567890\"}]"].  extra " and [] added by zosconnect tool created ara file .... .

    How can i send the PAYLOAD. Please remember the PAYLOAD is an ARRAY with freeform and i need to send that exact payload using the Zos connect end how can i do it. 




    ------------------------------
    Varma Nadimpally
    ------------------------------


  • 2.  RE: Need to invoke Api which has FREE FROM REQUEST BODY.

    Posted Fri October 22, 2021 04:29 AM
    Hello Varma @Varma Nadimpally

    You do not need to set the array brackets [ ] because z/OS Connect EE knows the data is an array so will add those for you as you saw.

    Please can you try:

               MOVE 2 TO ReqBody-num.

               MOVE '{"FinBankAcctNum":"1234567890"}' TO ReqBody2(1).

               MOVE 31 TO ReqBody2-length(1).

               MOVE '{"FinBankAcctNum":"1234567891"}' TO ReqBody2(2).

               MOVE 31 TO ReqBody2-length(2).

    Regards



    ------------------------------
    Sue Bayliss
    IBM z/OS Connect EE
    ------------------------------



  • 3.  RE: Need to invoke Api which has FREE FROM REQUEST BODY.

    Posted Fri October 22, 2021 01:38 PM
    Edited by Eric Phan Fri October 22, 2021 01:41 PM
    Hi @Varma Nadimpally

    If you want the body of your request to contain:
    • [{"FinBankAcctNum": "1234567890"}]
    • OR [{ "FinBankAcctNum": "1234567890"},{ "FinBankAcctNum": "1234567891"}]
    • OR any number of {"FinBankAcctNum": ""} in the array

    you would need to use the following definition in your swagger:

            - name: requestBody
    in: body
    description: request body with all the data elements that needs to be protected
    required: true
    schema:
    type: array
    items:
    type: object
    required:
    - FinBankAcctNum
    properties:
    FinBankAcctNum:
    type: string

    which would generate the following fields

                 06 ReqBody2-num                  PIC S9(9) COMP-5 SYNC.
    
                 06 ReqBody OCCURS 255.
                   09 FinBankAcctNum-length         PIC S9999 COMP-5 SYNC.
                   09 FinBankAcctNum                PIC X(255).
                   09 filler                        PIC X(1).
    

    where ReqBody2-num indicates the number of occurrences of ReqBody, which represents a JSON object with a single mandatory field named FinBankAcctNum. And FinBankAcctNum-length represents the length of FinBankAcctNum as Sue has illustrated in her example.


    I am not sure how much freedom the API's freeform format allows, but in order to build the JSON object in z/OS Connect the properties of "object" data types need to be known. Specifying the following structure:

    schema:
      type: array
      items:
        type: string.

    would not help as it defines an array of strings which [{"FinBankAcctNum": "1234567890"}] isn't.

    If the format allows you to have, for instance,  [{"FinBankAcctNum": "1234567890"},{"FinBankAcctNum": "1234567890","FinBankAcctType": "savings"},{"FinBankAcctType": "checking"}], then I would imagine that the following definition may work with z/OS Connect:

            - name: requestBody
    in: body
    description: request body with all the data elements that needs to be protected
    required: true
    schema:
    type: array
    items:
    type: object
    properties:
    FinBankAcctNum:
    type: string
    FinBankAcctType:
    type: string

    note that the properties are no longer required, and thus for each occurrence of the item you need to indicate if the optional fields are present. This is done by setting 1 or 0 to the *-num fields.

    Regards,



    ------------------------------
    Eric Phan
    ------------------------------