Mainframe Path Start learning free
Applied8 min readLesson 4 of 5

Calling external APIs from COBOL

APIs work in both directions. A COBOL program can call a service elsewhere — a fraud check, an address lookup, a cloud service — by building JSON, sending an HTTP request, and reading the reply.

Three common ways

Building a JSON request in COBOL
      * WS-FRAUD-REQ holds account id and amount
           JSON GENERATE WS-JSON-OUT FROM WS-FRAUD-REQ
               COUNT IN WS-JSON-LEN
               NAME OF ACCT-ID IS 'accountId'
               NAME OF TXN-AMOUNT IS 'amount'
               ON EXCEPTION
                   PERFORM 9000-JSON-ERROR
           END-JSON

Plan for the other side failing

The external service is outside your control. It will sometimes be slow or unavailable, and your transaction must still behave well.

Common mistakes

No timeout

One slow external service can tie up CICS tasks until the region struggles. Always set a timeout and handle it.

Ignoring the status code

Parsing the body without checking for 200 first leads to garbage data being processed as if it were valid.

Retrying non-idempotent calls

A retried payment or order can happen twice. Use a unique request ID so the other side can detect duplicates.

What you will see at work

Key terms

Check your understanding.
Take this lesson's quiz and save your progress. Free.

Take the lesson quiz
← Exposing CICS and IMS programs as APIsSecuring and running mainframe APIs →