Skip to main content
Santosh Reddy Chintagari
Participating Frequently
Jan 6, 2023 3:46 PM UTC

Calling an Apigee endpoint URL from a JCL using CURL

Hi,

I've been working to call an API via JCL using CURL by passing public & private keys of the certificate. I was able to successfully make a call to the PCF endpoint URL using below JCL where I got the request as expected by the API developer, however, due to security reasons now I need to make a call to an Apigee endpoint instead of PCF cloud directly. But for that I've been asked by our API team to pass below 3 parameters while making a CURL call. 

1.) Client-meta data
2.) API-key
3.) requestUniqueID

Below is the JCL.

//ABCJ4API JOB (XXXX,P),'CURL',MSGCLASS=T,SCHENV=SYSPLEX,USER=XXX 
//*
//S5QCUR1 EXEC PGM=BPXBATCH,
// REGION=0M
//STDPARM DD *
SH cd /appshare/XXXX/road4z/bin;
curl --get -v URL
https://apigw-int.devxx.xxx.com/xxxx/pdg/v1
--key '/appshare/API/key.pem'
--cacert '/appshare/API/ca.pem'
/*
//STDOUT DD SYSOUT=*
//STDERR DD SYSOUT=*

Please let me know how to pass the above 3 parameters using CURL and if this is not the correct forum, please let me know where I can post and get some help.

Thanks in advance.

------------------------------
Santosh Reddy Chintagari
Technical Systems Analyst
Rocket Forum Shared Account
------------------------------

    13 replies

    Alexander Klochkov
    Rocketeer
    Mar 13, 2023 8:44 AM UTC

    Hi Tatiana,

    I've already asked our Mainframe team open a support case as we developers are not allowed to do so. It's been close to 2 months and I don't see any reply yet.

    Coming to the question you have asked.

    I don't see any output when I run the JCL so I'm unable to figure out what's the issue. 

    Yesterday when I tried with a different script and I got the below response. The JCL took sometime to complete.

    000003 //S5QCUR1  EXEC PGM=BPXBATCH,                                            
    000004 //             REGION=0M                                                 
    000005 //STDPARM  DD  *                                                         
    000006 SH cd /appshare/4j00/road4z/bin;                                         
    000007 curl --get -v URL                                                        
    000008   https://apigw-int.dev.com/XB80/audit/v1/ca/auditChanges      
    000009   -H "Content-Type:application/json"                                     
    000010   -H "client-metadata:{"appOrg": "com.xxx.fg", "appCode": "XXXX",        
    000011     "appVersion": "v1.2.3", "locationId": "04538", "assetId": "PROD", 
    000012     "operatorId": "999996541", "legacyId": "234123411",                 
    000013     "ipAddress": "127.0.0.1"}"                                           
    000014   -H "Content-Length: 411"                                               
    000015   -H "apigw-int.devfg.rbc.com"                                           
    000016   -H "apikey: xWcFqByCZvFv1uFYoNuCqLmrQy9JdXdO"                          
    000017   -H "requestUniqueId: 24345678941"                                
    000018  --key '/dev/API/key.pem'                                  
    000019  --cacert '/dev/API/ca.pem'                                
    000020 /*                                                                       
    000021 //*STDOUT   DD  SYSOUT=*                                                 
    000022 //STDOUT   DD  DSN=BB0024.PDGAUDIT.RESP.LOGS,                            
    000023 //             DISP=OLD                                                  
    000024 //STDERR   DD  SYSOUT=*                                                  

     

    Output:

    curl: (52) Empty reply from server

    I tried another way as below and I got the error, somehow the client meta data is not getting accepted. Without the clientmetadata, Apikey & RequestUniqueId the call is going perfect, however for security reasons we need to pass these parameters for a secure call.

    HTTP-CODE: 400 BAD_REQUEST _error_info_catched.","additionalStatus":Ý{"statusCode":"XB80-10001","severity":"Error","statusDesc":"client-metadata error: field: appOrg can't be empty. field: appCode can't be empty. field: appVersion can't be empty. field: operatorId can't be empty. "}¨}}<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">

    //S5QCUR1  EXEC PGM=BPXBATCH,                                                   
    //             REGION=0M                                                        
    //STDPARM  DD  *                                                                
    SH cd /appshare/4j00/road4z/bin;                                                
    curl --get -v https://apigw-int.devfg.rbc.com/XB80/pdg-audit/v1/ca/auditChanges 
    -H "Accept: application/json"                                                   
    -H "client-metadata" : {                                                        
          "appOrg : com.xxx.fg"                                                     
          "appCode : XXXX"                                                          
          "appVersion : v1.2.3"                                                     
          "operatorId : 999996541"                                                 
      -H "apikey: xWcFqByCZvFv1uFYoNuCqLmrQy9JdXdO"                                 
      -H "requestUniqueId: 24345678941"                                       
     --key '/dev/API/key.pem'                                         
     --cacert '/dev/API/ca.pem'                                       
    /*                                                                              
    //*STDOUT   DD  SYSOUT=*                                                        
    //STDOUT   DD  DSN=BB0024.PDGAUDIT.RESP.LOGS,                                   
    //             DISP=OLD                                                         
    //STDERR   DD  SYSOUT=*                                                         

    Thanks,

    Santosh.



    ------------------------------
    Santosh Reddy Chintagari
    Technical Systems Analyst
    Rocket Forum Shared Account
    ------------------------------

    Hi Santosh,

    If your line with clientmetadata is too long for JCL you can also use file with headers:

    e.g.:
    curl -H @/path/to/file/with/headers.txt https://postman-echo.com/headers
    content of headers.txt should be like:
    client-metadata: {"appOrg":"com.xxx.fg","appCode":"XXXX","appVersion":"v1.2.3", "operatorId":"123454321"}
    test: 123
    make sure headers.txt is readable (cat headers.txt is ok) and has the correct tag.

    Thanks,
    Alexander



    ------------------------------
    Alexander Klochkov
    QA
    Rocket Internal - All Brands
    Vilnius LT
    ------------------------------
    Santosh Reddy Chintagari
    Participating Frequently
    Mar 21, 2023 12:16 PM UTC

    Hi Santosh,

    If your line with clientmetadata is too long for JCL you can also use file with headers:

    e.g.:
    curl -H @/path/to/file/with/headers.txt https://postman-echo.com/headers
    content of headers.txt should be like:
    client-metadata: {"appOrg":"com.xxx.fg","appCode":"XXXX","appVersion":"v1.2.3", "operatorId":"123454321"}
    test: 123
    make sure headers.txt is readable (cat headers.txt is ok) and has the correct tag.

    Thanks,
    Alexander



    ------------------------------
    Alexander Klochkov
    QA
    Rocket Internal - All Brands
    Vilnius LT
    ------------------------------

    Hi Alexander,

    Sorry for the late reply as I'm back to work this week. 

    I'll try it out by creating headers.txt and test the JCL and get back to you. Thank you.

    Regards,

    Santosh.



    ------------------------------
    Santosh Reddy Chintagari
    Technical Systems Analyst
    Rocket Forum Shared Account
    ------------------------------
    Santosh Reddy Chintagari
    Participating Frequently
    Mar 21, 2023 12:47 PM UTC

    SH is the IBM unix shell which has a very different syntax than the windows platform, see https://www.ibm.com/docs/en/zos/2.5.0?topic=descriptions-sh-invoke-shell

    Try

    export clientmetadata="{\\"appOrg\\":\\"com.xxx.fg\\",\\"appCode\\":\\"XXXX\\",            \\"appVersion\\":\\"v1.2.3\\", \\"operatorId\\":\\"123454321\\"}"

    and

    echo $clientmetadata

    and

    -H "client-metadata: $clientmetadata" 

    As mentioned earlier in this thread, I strongly recommend debugging the curl command in the USS shell before you try to wrestle with BPXBATCH 

    ssh into your mainframe, test the curl commands, and then try to create a BPXBATCH job afterwards. 



    ------------------------------
    Jorn Thyssen
    Solutions Advisor
    Rocket Internal - All Brands
    Waltham MA US
    ------------------------------

    Hi Jorn,

    Sorry for the late reply as I'm back to work this week. 

    Thanks for your feedback. I tried testing the JCL using the "export" variable before clientmetadata but it's causing further issues in recognizing the CURL call command as part of the JCL.

    export: FSUM7354 "--get" is not an identifier

    export: FSUM7354 "-v" is not an identifier

    FSUM7354   "string" is not an identifier                                                 
                                                                                             
     Explanation                                                                             
     You attempted to use an nonalphanumeric name as an identifier.                          
                                                                                             
     User response                                                                           
     Use only alphanumeric names for identifiers.

    I'm trying to understand how can I debug using the USS shell, could you please add more details as how can test this. Thank you.

    Regards,

    Santosh.



    ------------------------------
    Santosh Reddy Chintagari
    Technical Systems Analyst
    Rocket Forum Shared Account
    ------------------------------