Sample code for 30+ languages & platforms
Dart

MYOB: Get List of Company Files

See more MYOB Examples

Gets a list of company files.

Chilkat Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

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

  final http = CkHttp();

  http.authToken = 'ACCESS_TOKEN';

  http.accept = 'application/json';

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

  final String strResp;
  try {
    strResp = http.quickGetStr('https://ar1.api.myob.com/accountright');
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  print('Response Status Code: ${http.lastStatus}');

  final jsonResponse = CkJsonObject();
  jsonResponse.load(strResp);
  jsonResponse.emitCompact = false;
  print(jsonResponse.emit());

  if (http.lastStatus != 200) {
    print('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"
  // }
  // 

  final id = jsonResponse.stringOf('Id');
  final name = jsonResponse.stringOf('Name');
  final libraryPath = jsonResponse.stringOf('LibraryPath');
  final productVersion = jsonResponse.stringOf('ProductVersion');
  final productLevelCode = jsonResponse.intOf('ProductLevel.Code');
  final productLevelName = jsonResponse.stringOf('ProductLevel.Name');
  final checkedOutDate = jsonResponse.stringOf('CheckedOutDate');
  final checkedOutBy = jsonResponse.stringOf('CheckedOutBy');
  final uri = jsonResponse.stringOf('Uri');
  final country = jsonResponse.stringOf('Country');
}