function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Edward BerwickEdward Berwick 

Retrieve Account details from an external API

Hi,

I'm new to this API calling etc. I want to retrieve Address and other company information based upon the Salesforce Account Name. The External API I'm using is Duedil which holds mainly UK Company information. Based upon simply the name of a company e.g.  where Account Name =  'Arjo Fine Paper'

for a URL button

http://api.duedil.com/open/search?q={!Account.Name}&api_key=MY_API_KEY (they're free upon request at the website)

the response is 

{"response":{"pagination":"http:\/\/api.duedil.com\/open\/search?query=Arjo+Fine+Paper&total_results=3&limit=5&last_result=1","data":[{"company_number":"00961440","locale":"United Kingdom","name":"Arjo Wiggins Fine Papers Limited","uri":"http:\/\/api.duedil.com\/open\/uk\/company\/00961440.json"},{"company_number":"01870033","locale":"United Kingdom","name":"Arjo Wiggins Fine Papers Export Limited","uri":"http:\/\/api.duedil.com\/open\/uk\/company\/01870033.json"},{"company_number":"00683415","locale":"United Kingdom","name":"Arjo Wiggins Fine Papers Holdings Limited","uri":"http:\/\/api.duedil.com\/open\/uk\/company\/00683415.json"}]}}

I would like to simply parse the results in this output in Bold to 

https://www.duedil.com/company/00961440

then the user can potentially determine is the name they entered a known UK company (according to Duedil at least).

BTW Duedil intend to cover other countries in future.






Best Answer chosen by Edward Berwick
Satish_SFDCSatish_SFDC
Seems like this is a JSON Response.
You can parse this JSON response using the various json classes available in the salesforce api.

Check this link:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_json_jsonparser.htm

Regards,
Satish Kumar

All Answers

Satish_SFDCSatish_SFDC
Seems like this is a JSON Response.
You can parse this JSON response using the various json classes available in the salesforce api.

Check this link:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_json_jsonparser.htm

Regards,
Satish Kumar
This was selected as the best answer
Edward BerwickEdward Berwick
Great Thanks Satish, you've defintely set me on the right path. I read through the example you referenced and am now testing that snippet of code.

Do you think the "String endpoint" would accept the URL as I had it when defining the button as simply a URL?
  'http://api.duedil.com/open/search?q={!Account.Name}&api_key=gwmswhs3sndu428utbhac8hk';

Other than that I'll amend the "String s=" value to mirror the above response.

Then in the parser section I just want to Parse out the company Number/Numbers
(parser.getText() == 'company_number'))

Finally could I potentially output the results as a URL?
e.g.
https://www.duedil.com/company/00961440

I'm not sure if the "system.debug('Grand total=' + grandTotal);" in the example would provide this same output.

Any further pointers, much obliged. 

Cheers, Ed