API Enablement

  • 1.  Strange message from the stock query service

    IBM Champion
    Posted Sun September 20, 2020 02:02 PM
    Im using curl --insecure -X post -H Content-Type: application/json -H "Content-Type:application/json" -i --cacert cacert.pem --cert adcdd.pem:password --key adcdd.key.pem --data '{"STOCKQRYOperation": {"sqreq" : { "item_id": 2033}}}'  https://10.1.3.10:9443/zosConnect/services/stockQuery?action=invoke

    and getting back
    {"SQRESP":{"ITEM_ID":104523,"ITEM_DESC":"ription. 00050000000","ITEM_COST":null,"ITEM_COUNT":45}}

    which
    a) does not match the 2033 ..  it comes back 104523
    b) there is a strand ription.005.... with a new line in the middle and I was expecting a cost

    regards

    Colin


  • 2.  RE: Strange message from the stock query service

    Posted Tue September 22, 2020 05:39 AM

    Hi Colin,

    This problem is caused by the request payload being sent to the service not matching the JSON schema that the service expects.

    If you are using the MQ service provider sample stockQuery.sar file shipped with the sample server template sampleMqStockManager, change the payload you send on the --data argument to be:

    "{\"SQREQ\": {\"ITEM_ID\": 2033 }}"

    This should receive the response:

    {"SQRESP":{"ITEM_ID":2033,"ITEM_DESC":"A description.","ITEM_COST":4,"ITEM_COUNT":500}}

    The API Toolkit supports the creation of services (.sar files) which use the MQ service provider. This is the typical approach to create these services, and is how the sample stockQuery.sar file was created. Instructions for using the API Toolkit to create services for the MQ service provider is described in the Quick Start scenario instructions Create a two-way IBM MQ service and more generally in Creating a CICS, IMS or IBM MQ service.

    For compatibility with earlier releases, MQ service provider services can also be created using the command line build toolkit, but these do not benefit from the additional functionality provided by the API Toolkit. It looks like you may have been using request payload from "Test the stock query service",  which is only applicable to its preceding Knowledge Center pages for creating the stock query service using the build toolkit and a properties file. 

    Regards, Sue



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



  • 3.  RE: Strange message from the stock query service

    IBM Champion
    Posted Wed September 23, 2020 03:01 AM
    Sue,

    Are you saying

    replace
    --data '{"STOCKQRYOperation": {"sqreq" : { "item_id": 2033}}}'
    with

    --data '{"sqreq" : { "item_id": 2033}}'

    By putting the request inside single quotes I do not need to escape the double quote within the payload.

    Or do I need to escape the double quotes anyway... for the z/OS connect processing?

    regards

    Colin







  • 4.  RE: Strange message from the stock query service

    Posted Wed September 23, 2020 03:27 AM
    Edited by Sue BAYLISS Wed September 23, 2020 03:40 AM

    Hi Colin,

    --data '{ "SQREQ": { "ITEM_ID": 2033 }}' will work.
    But the case of the JSON field names is significant, in this example, uppercase. The request data must match what is expected by the service request schema.
    You can view the request schema for a service using the URI: /zosConnect/services/{serviceName}/schema/request as documented in Get the request schema of a service.

    I agree that surrounding the data string with single quotes and avoiding the need to escape double quotes is neater, (personally I had enclosed the data string value in double quotes and so had to escape the double quotes within the string). 

    Regards, Sue

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



  • 5.  RE: Strange message from the stock query service

    IBM Champion
    Posted Thu October 01, 2020 10:45 AM
    The documentation
    https://www.ibm.com/support/knowledgecenter/SS4SVW_beta/reference/mq_test_service.html

    says

    curl -i -k -X POST http://host:port/zosConnect/services/stockQuery?action=invoke --data "{\"STOCKQRYOperation\": { \"sqreq\": { \"item_id\": 2033 }}}" -H "Content-Type:application/json"

    which is different to what you suggest - should the doc be updated?

    ------------------------------
    Colin Paice
    ------------------------------



  • 6.  RE: Strange message from the stock query service

    Posted Thu October 01, 2020 11:56 AM

    Hi Colin,

    That documentation is correct, but as mentioned above, it is in the section of the Knowledge Center related to building a MQ service provider service using the command line build toolkit, which produces different request and response schemas.

    "For compatibility with earlier releases, MQ service provider services can also be created using the command line build toolkit, but these do not benefit from the additional functionality provided by the API Toolkit. It looks like you may have been using request payload from "Test the stock query service",  which is only applicable to its preceding Knowledge Center pages for creating the stock query service using the build toolkit and a properties file."

    However, I believe you are using a service built using the API Toolkit, either from the sample server template sampleMqStockManager or by following the Quick Start scenario Quick Start scenario instructions Create a two-way IBM MQ service. Which uses the JSON syntax, I provided above.

    Regards, Sue



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



  • 7.  RE: Strange message from the stock query service

    IBM Champion
    Posted Thu October 01, 2020 10:51 AM

    Sue,

    Even with
    --data {"sqreq" : { "item_id": 2033}}} https://10.1.3.10:9443/zosConnect/services/stockQuery?action=invoke

    I get
    {"SQRESP":{"ITEM_ID":104523,"ITEM_DESC":"ription. 00050000000","ITEM_COST":null,"ITEM_COUNT":45}}
    The TwoWayBackend.java has a

    //a 6 digit integer item cost.
    //Return a hard coded response body, with the itemID inserted.
    String responseMessagePayload = String.format("%sA description. 0005000000045", itemID);

    Message responseMessage = ctx.createTextMessage(responseMessagePayload);
    //Response messages have the correlation id set to the message id of the


    could there be a bug in the  parsing code in the sample service?



    ------------------------------
    Colin Paice
    ------------------------------



  • 8.  RE: Strange message from the stock query service

    Posted Thu October 01, 2020 11:59 AM

    Hi Colin,

    Please see my post number 4 above. The JSON is case sensitive.

    Please try using: --data '{ "SQREQ": { "ITEM_ID": 2033 }}'

    Regards, Sue



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