Example 1: Read an MVS data set sequentially

In the following example, Z Data Tools Service Provider REST API calls are issued to start a persistent session to read records in an MVS™ data set, using a template to map fields in each record.

Initial request

An initial API call to read data from a data resource requires an HTTP Basic Authorization header so that the caller can be authenticated for subsequent access to z/OS® data resources. For example:

Authorization : Basic dXNlcmlkOnBhc3N3b3Jk

where the string after the Basic keyword represents a Base64 encoding of userid:password.

All requests with a JSON payload also require a Content-Type header with a value of application/json.

The initial request also requires the name of the data resource and optionally the name of a Z Data Tools template or copybook to map the data:

{
    "resource" : 
    {
        "resourceName" : "MY.MVS.DATASET"
    },
    "template" :
    {
        "templateName" : "MY.TEMPLATE(MVSDS)"
    },
    "operation" :
    {
        "numRecords" : 1,
        "session" : true,
        "timeout" : 1800
    }
}

This request reads one record from the beginning of data set MY.MVS.DATASET and uses a template found in MY.TEMPLATE(MVSDS) to map out the record fields in the response.

The service provider will persist a Z Data Tools session because session is set to true. The session will remain active until a subsequent request is made with session set to false, or a timeout period of 1800 seconds (30 minutes) elapses with no activity on the session.

The caller can expect a token to be returned on an initial request when session is set to true, and can use the token on subsequent calls without the need to pass resource or template parameters or a Basic Authorization header.

Successful response

A successful response (HTTP Status Code 200) will be similar to the following:

{
    "records" : 
    [
        {
            "layouts" : 
            [
                {
                    "layout" : "CUSTOMER-ADDRESS",
                    "fields" : 
                    [
                        {
                            "field" : "CUSTOMER-NO",
                            "type" : "PD",
                            "value" : 5788
                        },
                        {
                            "field" : "CUSTOMER-STREET",
                            "type" : "AN",
                            "value" : "177A BLEEKER STREET"
                        },
                        {
                            "field" : "CUSTOMER-CITY",
                            "type" : "AN",
                            "value" : "NEW YORK"
                        },
                        {
                            "field" : "CUSTOMER-COUNTRY",
                            "type" : "AN",
                            "value" : "USA"
                        }
                    ]
                }
            ]
        }
    ] ,
    "token" : ""+WCCd/9g8fXy8PT58vfz9mD39fL48fU="
}

Subsequent read requests

The API caller can now make subsequent requests using the response token and reuse the Z Data Tools session maintained by the service provider. For example:

{
    "operation" :
    {
        "numRecords" : 1,
        "session" : true,
        "token" : "+WCCd/9g8fXy8PT58vfz9mD39fL48fU="
    }
}

When passing a token, the caller does not need to pass resource or template parameters as these are already known by the session associated with the token. The API caller can continue to read one or more records at a time until a response record object has last set to true, indicating that the last record has been read. For example:

{
    "records" : 
    [
        {
            "last" : true, 
            other response fields
        }
    ]
}

Ending the session

At this point, the API caller sends a request to terminate the active Z Data Tools session.

{
    "operation" :
    {
        "numRecords" : 0,
        "session" : false,
        "token" : "+WCCd/9g8fXy8PT58vfz9mD39fL48fU="
    }
}

Sending a request with session set to false will always terminate the Z Data Tools session, providing the token is valid. Since the caller has already read the last record, setting "numRecords" : 0 tells the service provider not to attempt to read any more records.