Sample code for 30+ languages & platforms
Java

GeoOp - Get all Jobs

See more GeoOp Examples

Gets all information about all jobs.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.DateTime;
import com.chilkatsoft.chilkat2.DtObj;
import com.chilkatsoft.chilkat2.JsonObject;
import com.chilkatsoft.chilkat2.OAuth2;
import com.chilkatsoft.chilkat2.Rest;

public class ChilkatExample {

    public static void main(String[] args) {
        // This example assumes the Chilkat API to have been previously unlocked.
        // See Global Unlock Sample for sample code.

        // This example also assumes an OAuth2 access token was previously fetched.
        // and saved in a JSON file.

        // First get our previously obtained access token.
        // {"access_token":"e6dqdG....mzjpT04w==","token_type":"Bearer","expires_in":2592000,"owner_id":999236}
        JsonObject jsonToken = new JsonObject();
        jsonToken.loadFile("qa_data/tokens/geoop.json");

        // This example assumes we previously obtained an access token
        OAuth2 oauth2 = new OAuth2();
        oauth2.setAccessToken(jsonToken.stringOf("access_token"));

        Rest rest = new Rest();

        // Connect to GeoOp and send the following GET request:

        // GET /users HTTP/1.1
        // Host: api.geoop.com
        boolean bAutoReconnect = true;
        String responseBody;
        try {
            rest.connect("api.geoop.com", 443, true, bAutoReconnect);

            // Provide the authentication credentials (i.e. the access token)
            rest.setAuthOAuth2(oauth2);

            // Set the X-Version header.
            rest.addHeader("X-Version", "1.0");

            responseBody = rest.fullRequestNoBody("GET", "/jobs");
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        JsonObject json = new JsonObject();
        json.setEmitCompact(false);

        // If the response status code did not indicate success, then see what happened..
        if (rest.getResponseStatusCode() != 200) {
            System.out.println("Request Header: ");
            System.out.println(rest.getLastRequestHeader());
            System.out.println("----");
            System.out.println("Response StatusCode = " + rest.getResponseStatusCode());
            System.out.println("Response StatusLine: " + rest.getResponseStatusText());
            System.out.println("Response Header:");
            System.out.println(rest.getResponseHeader());
            json.load(responseBody);
            System.out.println(json.emit());
            return;
        }

        json.load(responseBody);
        // Show the full JSON response.. (see below)
        System.out.println(json.emit());

        // These will be used for parsing date/time strings..
        DateTime dtime = new DateTime();
        boolean bLocalTime = true;
        DtObj dt = new DtObj();

        // Iterate over each job and get information..
        int numRecords = json.sizeOfArray("jobs");
        int i = 0;
        while (i < numRecords) {
            json.setI(i);
            System.out.println("job id: " + json.stringOf("jobs[i].id"));
            System.out.println("client id: " + json.stringOf("jobs[i].client.id"));
            System.out.println("account id: " + json.stringOf("jobs[i].account.id"));
            System.out.println("address line1: " + json.stringOf("jobs[i].address.line1"));

            dtime.setFromTimestamp(json.stringOf("jobs[i].startTime"));
            dtime.toDtObj(bLocalTime, dt);

            System.out.println("created: " + dt.getMonth() + "/" + dt.getDay() + "/" + dt.getYear() + "  " + dt.getHour() + ":" + dt.getMinute());

            System.out.println("----");
            i = i + 1;
        }

        // A sample jobs listing response:
        //
        //     {
        //       "result": "success",
        //       "jobs": [
        //         {
        //           "id": 17580761,
        //           "reference": "1000",
        //           "startTime": "2016-10-26T02:10:00+00:00",
        //           "endTime": "2016-10-28T02:40:00+00:00",
        //           "priority": 2,
        //           "title": "[ Demo Job ]",
        //           "description": "",
        //           "jobNumber": null,
        //           "deleted": false,
        //           "type": "demo",
        //           "created": "2015-09-03T02:11:32+00:00",
        //           "modified": "2016-10-26T12:05:09+00:00",
        //           "client": {
        //             "id": 9555868
        //           },
        //           "billingClient": null,
        //           "status": {
        //             "id": 675900
        //           },
        //           "account": {
        //             "id": 39409
        //           },
        //           "address": {
        //             "line1": "21462 New York Avenue NW",
        //             "line2": null,
        //             "city": "Washington",
        //             "postcode": "20005",
        //             "latitude": 38.903959,
        //             "longitude": -77.02137
        //           },
        //           "metadata": {
        //             "visitsCount": 3,
        //             "assignedVisitsCount": 3,
        //             "unassignedVisitsCount": 0,
        //             "partsCount": 1,
        //             "chargesCount": 1,
        //             "timersCount": 0,
        //             "notesCount": 0,
        //             "parcelsCount": 0,
        //             "paymentsCount": 0,
        //             "documentsCount": 1
        //           }
        //         },
        //         {
        //           "id": 17639295,
        //           "reference": "1000",
        //           "startTime": "2016-10-31T12:00:00+00:00",
        //           "endTime": "2016-10-31T12:30:00+00:00",
        //           "priority": 2,
        //           "title": "Deliver Donuts",
        //           "description": "Deliver donuts to the cafe.",
        //           "jobNumber": "21122",
        //           "deleted": false,
        //           "type": "normal",
        //           "created": "2016-10-31T12:07:14+00:00",
        //           "modified": "2016-10-31T12:07:14+00:00",
        //           "client": {
        //             "id": 9555868
        //           },
        //           "billingClient": null,
        //           "status": {
        //             "id": 675900
        //           },
        //           "account": {
        //             "id": 39409
        //           },
        //           "address": {
        //             "line1": "1732 Pennsylvania Avenue NW",
        //             "line2": null,
        //             "city": "Washington",
        //             "postcode": "20006",
        //             "latitude": 38.8990534,
        //             "longitude": -77.0401866
        //           },
        //           "metadata": {
        //             "visitsCount": 1,
        //             "assignedVisitsCount": 0,
        //             "unassignedVisitsCount": 1,
        //             "partsCount": 0,
        //             "chargesCount": 0,
        //             "timersCount": 0,
        //             "notesCount": 0,
        //             "parcelsCount": 0,
        //             "paymentsCount": 0,
        //             "documentsCount": 0
        //           }
        //         }
        //       ],
        //       "metadata": {
        //         "page": 1,
        //         "pagesCount": 1,
        //         "recordsPerPage": 20,
        //         "recordsCount": 2
        //       }
        //     }
        //
    }
}