Sample code for 30+ languages & platforms
Java

MYOB: Get List of Company Files

See more MYOB Examples

Gets a list of company files.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Http;
import com.chilkatsoft.chilkat2.JsonObject;

public class ChilkatExample {

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

        Http http = new Http();

        http.setAuthToken("ACCESS_TOKEN");

        http.setAccept("application/json");

        http.setRequestHeader("x-myobapi-key", "MYOB_API_KEY");
        http.setRequestHeader("x-myobapi-version", "v2");

        String strResp;
        try {
            strResp = http.quickGetStr("https://ar1.api.myob.com/accountright");
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        System.out.println("Response Status Code: " + http.getLastStatus());

        JsonObject jsonResponse = new JsonObject();
        jsonResponse.load(strResp);
        jsonResponse.setEmitCompact(false);
        System.out.println(jsonResponse.emit());

        if (http.getLastStatus() != 200) {
            System.out.println("Failed.");
            return;
        }

        // Sample output...
        // (See the parsing code below..)
        //
        // Use the this online tool to generate parsing code from sample JSON:
        // Generate Parsing Code from JSON

        // {
        //   "Id": "d2014f64-ffdf-487b-8d12-67a20976aca6",
        //   "Name": "Internal Sandbox API",
        //   "LibraryPath": "Internal Sandbox API",
        //   "ProductVersion": "2013.0",
        //   "ProductLevel": {
        //     "Code": 20,
        //     "Name": "Standard"
        //   },
        //   "CheckedOutDate": "2013-06-11T01:47:47.0065514",
        //   "CheckedOutBy": "developers@myob.com",
        //   "Uri": "{cf_uri}",
        //   "Country": "AU"
        // }
        //

        String Id = jsonResponse.stringOf("Id");
        String Name = jsonResponse.stringOf("Name");
        String LibraryPath = jsonResponse.stringOf("LibraryPath");
        String ProductVersion = jsonResponse.stringOf("ProductVersion");
        int ProductLevelCode = jsonResponse.intOf("ProductLevel.Code");
        String ProductLevelName = jsonResponse.stringOf("ProductLevel.Name");
        String CheckedOutDate = jsonResponse.stringOf("CheckedOutDate");
        String CheckedOutBy = jsonResponse.stringOf("CheckedOutBy");
        String Uri = jsonResponse.stringOf("Uri");
        String Country = jsonResponse.stringOf("Country");
    }
}