Added support for APIv3 and replaced string builder with json.