Retrieve

Syntax 1

Description

Retrieves data to the DataWindow or DataStore with GET method. The JSON string returned from the RESTFul Web Service APIs must be in this format.

Applies to

RestClient object

Syntax

objectname.Retrieve ( dwControl, urlName )
objectname.Retrieve ( dsObject, urlName )

Argument

Description

objectname

A reference to the RestClient object

dwControl

A reference to a DataWindow.

dsObject

A reference to a DataStore.

urlName

A string whose value is the URL.


Return value

Long.

Returns values as follows. If any argument's value is null, the method returns null.

>=0 -- Returns the number of rows if it succeeds

-1 -- General error

-2 -- Invalid URL

-3 -- Cannot connect to the Internet

-4 -- Timed out

Example 1

This example retrieves data to a DataWindow:

RestClient lnv_RestClient
lnv_RestClient = Create RestClient

// Set DataObject
dw_1.DataObject = "d_employee"

// Send request using GET
ll_rc = lnv_RestClient.Retrieve(dw_1, "http://demo.appeon.com/PB/webapi_client/employee/102")

// Check the return value
if ll_rc >= 0 then
	MessageBox("Success", "Rows = " + String(ll_rc))
else
	MessageBox("Error", "Failed to retrieve data.")
end if

Example 2

This example retrieves data to a DataStore:

RestClient lnv_RestClient
lnv_RestClient = Create RestClient

// Set DataObject
ds_1.DataObject = "d_employee"

// Send request using GET
ll_rc = lnv_RestClient.Retrieve(ds_1, "http://demo.appeon.com/PB/webapi_client/employee/102")

// Check the return value
if ll_rc >= 0 then
	MessageBox("Success", "Rows = ” + String(ll_rc))
else
	MessageBox("Error", "Failed to retrieve data.")
end if

Syntax 2

Description

Retrieves data to the DataWindow or DataStore with POST method that passes the string or blob data. The JSON string returned from the RESTFul Web Service APIs must be in this format.

Applies to

RestClient object

Syntax

objectname.Retrieve ( dwControl, urlName, data )
objectname.Retrieve ( dsObject, urlName, data )

Argument

Description

objectname

A reference to the RestClient object

dwControl

A reference to a DataWindow.

dsObject

A reference to a DataStore.

urlName

A string whose value is the URL.

data

A string or blob data.


Return value

Long.

Returns values as follows. If any argument's value is null, the method returns null.

>=0 -- Returns the number of rows if it succeeds

-1 -- General error

-2 -- Invalid URL

-3 -- Cannot connect to the Internet

-4 -- Timed out

Example 1

This example retrieves data to a DataWindow with POST method that passes the string data.

RestClient lnv_RestClient
lnv_RestClient = Create RestClient

String ls_json = '{"empId":100, "fname":" John", "lname": "Guevara"}'

// Construct a POST request (supports all headers)
lnv_RestClient.SetRequestHeader("Content-Type", "application/json;charset=UTF-8")
// Content-Length is set by Retrieve automatically
...
// Send the POST request (add data to the body and automatically set Content-Length header)
ll_rc = lnv_RestClient.Retrieve(dw_1, "http://demo.appeon.com/PB/webapi_client/employee", ls_Json)

// Check the return value
if ll_rc >= 0 then
	MessageBox("Success", "Rows = " + String(ll_rc))
else
	MessageBox("Error", "Failed to retrieve data.")
end if

Example 2

This example retrieves data to a DataWindow with POST method that passes the blob data.

RestClient lnv_RestClient
lnv_RestClient = Create RestClient

// Construct a POST request (supports all headers)
lnv_RestClient.SetRequestHeader("Content-Type", "application/json;charset=UTF-8")
// Content-Length is set by Retrieve automatically
...
// Send the POST request (add data to the body and automatically set Content-Length header)
ll_rc = lnv_RestClient.Retrieve(dw_1, "http://demo.appeon.com/PB/webapi_client/employee", lblb_data)

// Check the return value
if ll_rc >= 0 then
	MessageBox("Success", "Rows = " + String(ll_rc))
else
	MessageBox("Error", "Failed to retrieve data.")
end if

Example 3

This example retrieves data to a DataStore with POST method that passes the string data.

RestClient lnv_RestClient
lnv_RestClient = Create RestClient

String ls_json = '{"empId":102, "fname":" John", "lname": "Guevara"}'

// Construct a POST request (supports all headers)
lnv_RestClient.SetRequestHeader("Content-Type", "application/json;charset=UTF-8")
// Content-Length is set by Retrieve automatically
...
// Send the POST request (add data to the body and automatically set Content-Length header)
ll_rc = lnv_RestClient.Retrieve(ds_1, "http://demo.appeon.com/PB/webapi_client/employee", ls_Json)

// Check the return value
if ll_rc >= 0 then
	MessageBox("Success", "Rows = " + String(ll_rc))
else
	MessageBox("Error", "Failed to retrieve data.")
end if

Example 4

This example retrieves data to a DataStore with POST method that passes the blob data.

RestClient lnv_RestClient
lnv_RestClient = Create RestClient

// Construct a POST request (supports all headers)
lnv_RestClient.SetRequestHeader("Content-Type", "application/json;charset=UTF-8")
// Content-Length is set by Retrieve automatically
...
// Send the POST request (add data to the body and automatically set Content-Length header)
ll_rc = lnv_RestClient.Retrieve(ds_1, "http://demo.appeon.com/PB/webapi_client/employee", lblb_data)

// Check the return value
if ll_rc >= 0 then
	MessageBox("Success", "Rows = " + String(ll_rc))
else
	MessageBox("Error", "Failed to retrieve data.")
end if

Format of JSON string

The JSON string returned from the RESTFul Web Service APIs must have no more than 2 levels, and the top-level must be arrays, the second-level must be objects.

For example, the following JSON string is supported:

[
    {
       "empid":148,
       "fname":"julie",
       "lname":"jordan"
    },
    {
       "empId":184,
       "fname":"Melissa",
       "lname":"Espinoza"
    },
    {
       "empId":191,
       "fname":"Jeannette",
       "lname":"bertrand"
    }
]

The following JSON string is unsupported:

{
        "empId":191,
        "fname":"Jeannette",
        "lname":"bertrand",
         "manager":
                  {
                           "managerid":703,
                           "fname":"David",
                           "lname":"Scott"
                   },
         "department":
                   {
                           "deptid":200,
                           "name":"Sales"
                   }
}