Skip to page content
Secretary of Labor Hilda L. Solis

PHP DOL Data SDK Sample

Overview

This sample will provide the steps to create a simple PHP application that can consume DOL Data. Following these steps in order will allow your application to operate correctly. Download this project.


Create a New Project

For this sample we are going to create a web site that will consume and list Agency data.
Create a project folder for this sample.
Create a new text document using any text editor and save it as Sample.php in the project folder.

Requirements

The DOL Data SDK has some library dependencies. Ensure that your version of PHP was compiled with support for cURL functions.

Add SDK to Project

Add the SDK to your project. Extract the zip file (which can be downloaded here) and copy DOLDataSDK.php into your project folder.

Locate Dataset Path

EEach Dataset has a Dataset Location path that gives the URL that will be needed to reach the Dataset on the API. For the standard DOL Agency dataset sample please use http://api.dol.gov/V1/DOLAgency

Add Service Reference

For the DOL Service Operation sample please use http://api.dol.gov/V1/SummerJobs

Add Service Reference

Define the User Interface/h2>

Create the function resultsTable(); which will take the results returned by the data request and display them in a simple table.

resultsTable

For DOL Service Operation (Beta Version).

  • Include a JavaScript file in page , this javascript file has required jquery function to parse the json response.
  • resultsTable

  • Create the function resultsTable() for DOL Service Operation (Beta Version).
  • resultsTable

Implementing the DOL Data Request

The DOLDataSDK.php file handles everything required for submitting data requests to the DOL API, so we need to add them to Sample.php with an include statement.

Include DOLDataSDK

In order to submit data requests, we will need to create two objects; an instance of DOLDataContext, to hold various information about our data request, and an instance of DOLDataRequest, to handle the submission of the request.

Instantiate Data Classes

Next, we need to call callAPI() on our DOLDataRequest. This method takes two arguments: the Dataset Location path to the table we are requesting data from, and an Array of arguments to pass to the data request.

For Standard DOL API datasets :

call callAPI method

For DOL Service Operation for Summer Jobs Plus:

call callAPI method


If callAPI() returns a string, an error occurred while sending the request. Otherwise, callAPI() returns an Array of stdClass instances. In this sample, we will handle an error by echoing it to the screen. Otherwise, we will pass the results to our resultsTable() function.

Handle Results

The finished code should look like this:

Full Code

Implementing the DOL Service Operation Request (Beta Version)

Please follow all above steps from Implementing the DOL Data Request section for DOL Service Operation Request and also add following javascript code to parse the json response using Jquery.

Full Code

The finished code should look like this:

Full Code


Configure Security

Secure logins are provided using the following code; we will need to insure that the DOLDataContext instance is initialized with both an ApiKey and a SharedSecret. Replace "your-token" and "your-shared-secret" in new DOLDataContext() with your Token and SharedSecret.

  • The ApiKey corresponds to the Token identifier in your token list.
  • The SharedSecret that is associated with that token.

Configure Security


View DOL Data

Build and run the application, and you should see something like the following:

Data

Result of DOL Service Operation Request (Beta Version):

Data