APIs with their service type

Viewed 22

Please how do I use this kind of APIs. I am totally new to this.

{ "data": "{"servicetype":"ADMIN_CREATE_VIRTUAL_ACCOUNT", "requestref":"2211233211231", "phoneNumber":"08011111111", "lastName":"zie", "firstName":"mie", "middleName":"" "businessName":"zie inc", "trackingReference":"151251211425591977" } }" }the API doc image for fintech

1 Answers

Welcome!

Firstly, the API response you with the JSON data. But your application gets it as string when you request. You need to parse the JSON data with JSON.parse(data); command. To use it you need to declare a variable. So code turns into var parsed_data = JSON.parse(data);.

Now you can access the data by using parsed_data['data'] or more as parsed_data['data']['servicetype'].

data = """{ "data": "{"servicetype":"ADMIN_CREATE_VIRTUAL_ACCOUNT", "requestref":"2211233211231", "phoneNumber":"08011111111", "lastName":"zie", "firstName":"mie", "middleName":"" "businessName":"zie inc", "trackingReference":"151251211425591977" } }"""

var parsed_data = JSON.parse(data);
console.log(parsed_data['data']['servicetype']);
Related