You need to sign in to do that
Don't have an account?
Kiran Chodavadiya
Update Field After verify with API Callout Response
Hello,
I have this Requirement
Make Call-out to SmartyStreets API –
SmartyStreets API is used to verify the address. In this milestone you need to consume https://smartystreets.com/products/apis/us-street-api
Requirement – The business ask is to verify the address of the event. Use the above API to verify the address & update “Location Verified” field on Event.
Must Have – Use of Error Handling and code re-usability
I tried with following code< but it showing 404 Error.
Could you please help how to come out from this Error And How i Upadate Field.
I have this Requirement
Make Call-out to SmartyStreets API –
SmartyStreets API is used to verify the address. In this milestone you need to consume https://smartystreets.com/products/apis/us-street-api
Requirement – The business ask is to verify the address of the event. Use the above API to verify the address & update “Location Verified” field on Event.
Must Have – Use of Error Handling and code re-usability
I tried with following code< but it showing 404 Error.
Could you please help how to come out from this Error And How i Upadate Field.
public class ApexHourIntigration { public static void verifyAddress(String Address){ Http Http = new Http(); HttpRequest Request = new HttpRequest(); Request.setEndpoint('https://us-street.api.smartystreets.com/street-address?auth-id=6baff965-c2ed-eb53-7f43-e615db469a24&auth-token=pq7dRFqRoxtHiXKtCsOt'+ Address); Request.setMethod('GET'); //Request.setHeader('contentType', 'application-json;charset=UTF-8'); //Request.setBody('[{"candidates":10,"match":"invalid","street":"3901 SW 154th Ave","street2":"","city":"Davie","state":"FL","zipcode":"33331"}]'); HttpResponse Response = Http.send(Request); if(Response.getStatusCode()!=200){ system.debug(Response.getBody()); } if(Response.getStatusCode()==200){ Map<string,object> Results = (Map<string,object>) JSON.deserializeUntyped(Response.getBody()); List<object> items = (List<object>) Results.get('items'); for(object item :items){ Map<string,object> components = (Map<string,object>)item; system.debug(components.get('components')); } try{ Event e = new Event(); e.Location = 'Verified'; update e; } catch(Exception e){ system.debug('Error is :'+e.getMessage()); } } } }
Can you provide me the complete endpoint that includes a sample address? Thanks
Thanks for Responsing.
I ran your same code, with Address argument as - '&candidates=10&match=invalid&street=3901%20SW%20154th%20Ave&street2=&city=Davie&state=FL&zipcode=33331'
It is not giving 404 Error. Check if you are passing the argument correctly.
Also, in rest of the code, you are receiving Response.getBody() as Map<string,object>, but it is List<Object>
Please refer blow snippet- Let me know if this helps.
I have run narrowed snippet in anonymous block to see if its an issue with end point The endpoint works fine.
Running your class gave
"EXCEPTION: System.TypeException: Invalid conversion from runtime type List<ANY> to Map<String,ANY>
STACKTRACE: Class.ApexHourIntigration.verifyAddress: line 17, column 1"
To fix the error, please try the approach suggested in the above comment. Thanks
Footprints on the Moon ,
Swetha,
Thanks for Help.
Your Solution work for me.
I have Developed following code with suggested solution and it works fine.