RPA Community Forum

TagUI + OneMap Api

#1

Hi

I am new to TagUI and would like help in how to use it to extract return json array from OneMap API

I want to pass a Postal Code to the OneMap Rest API

API syntax:

https://developers.onemap.sg/commonapi/search?searchVal=revenue&returnGeom=Y&getAddrDetails=Y&pageNum=1

I have a csv file containing Postal Code.
I want to read the Postal Code and pass it to the OneMap API (e.g. Postal Code = 560604)

https://developers.onemap.sg/commonapi/search?searchVal=560604&returnGeom=Y&getAddrDetails=Y&pageNum=1

The return result is:

{“found”:1,“totalNumPages”:1,“pageNum”:1,“results”:[{“SEARCHVAL”:“YIO CHU KANG GREEN”,“BLK_NO”:“604”,“ROAD_NAME”:“ANG MO KIO AVENUE 5”,“BUILDING”:“YIO CHU KANG GREEN”,“ADDRESS”:“604 ANG MO KIO AVENUE 5 YIO CHU KANG GREEN SINGAPORE 560604”,“POSTAL”:“560604”,“X”:“28295.8099781042”,“Y”:“40204.1514989082”,“LATITUDE”:“1.37986658053966”,“LONGITUDE”:“103.835976650638”,“LONGTITUDE”:“103.835976650638”}]}

How do I then extract the json record into their respective fields and update a excel file?

My attempt but not sure if this code correct or not

array_items = []
array_results = []
csv_file = ‘postal_data.csv’
load ‘+csv_file+’ to lines

array_lines = lines.split(’\n’)

for (n=0; n<array_lines.length; n++)
{
array_items[n] = array_lines[n].trim()
}

for (n=0; n<array_lines.length; n++)
{
arrary_results[n] = https://developers.onemap.sg/commonapi/search?searchVal=array_items[n]&returnGeom=Y&getAddrDetails=Y&pageNum=1
}