+ Start a Discussion
Steve Harris 9Steve Harris 9 

APEX Rest API to connect to external website

I am trying to retrive data from an external website into a custom object (EZE) in our SF org.  There are multiple fields on the oject that need to be poulated twice a day.  The sample code code from the external site is:

{"id":"AAF-116","name":"LAKE PUMP DEMO","location":"","time":"2018-04-04T00:27:14Z","system":{"fwver":"17071520","lastreset":"2018-04-04 00:05:47","lastcomm":"2018-04-04 00:26:50","lastendpoint":"207.189.176.133:46111","serviceexpiration":"2019-03-01 12:00:00","remainingapi":"1996","remainingalarms":"50","timezone":"US\/Eastern","gmtoffset":"-14400"},"status":"OK","inputs":{"1":{"name":"Supply voltage","raw":12763,"real":12.8,"unit":"V","count":0,"maxval":30,"minval":7,"decimals":"1","alarm":"----"},"2":{"name":"Engine RPM","raw":-1,"real":-1,"unit":"RPM","count":1300,"maxval":2500,"minval":0,"decimals":"0","alarm":"----"},"3":{"name":"Percent of Load","raw":0,"real":0,"unit":"Percent","count":0,"maxval":100,"minval":0,"decimals":"0","alarm":"----"},"4":{"name":"Oil Pressure","raw":-1,"real":-1,"unit":"PSI","count":0,"maxval":105,"minval":0,"decimals":"0","alarm":"----"},"5":{"name":"Coolant Temp","raw":-1,"real":-1,"unit":"F","count":0,"maxval":250,"minval":0,"decimals":"0","alarm":"----"},"6":{"name":"Fuel Level","raw":85,"real":85,"unit":"Percent","count":0,"maxval":100,"minval":0,"decimals":"0","alarm":"----"},"7":{"name":"Fuel Used","raw":7900,"real":790,"unit":"Gal","count":0,"maxval":100,"minval":0,"decimals":"1","alarm":"----"},"8":{"name":"Engine Hours","raw":-1,"real":-0.1,"unit":"Hrs","count":0,"maxval":100,"minval":0,"decimals":"1","alarm":"----"},"9":{"name":"Sump Level","raw":-1,"real":-0,"unit":"Inches","count":0,"maxval":100,"minval":0,"decimals":"0","alarm":"----"},"10":{"name":"Pump Discharge Pressure","raw":-1,"real":-1,"unit":"PSI","count":0,"maxval":400,"minval":0,"decimals":"0","alarm":"----"},"11":{"name":"Amber Warning Lamp","raw":0,"real":0,"unit":"","count":0,"maxval":1,"minval":0,"decimals":"0","alarm":"----"},"12":{"name":"Red Stop Lamp","raw":0,"real":0,"unit":"","count":0,"maxval":1,"minval":0,"decimals":"0","alarm":"----"},"13":{"name":"Active SPN 1","raw":-1,"real":-1,"unit":"","count":0,"maxval":10000,"minval":0,"decimals":"0","alarm":"----"},"14":{"name":"Active FMI 1","raw":-1,"real":-1,"unit":"","count":0,"maxval":1,"minval":0,"decimals":"0","alarm":"----"},"15":{"name":"Key Position","raw":1,"real":1,"unit":"","count":0,"maxval":2,"minval":0,"decimals":"0","alarm":"----"},"16":{"name":"DEF Tank level","raw":-1,"real":-1,"unit":"percent","count":0,"maxval":100,"minval":0,"decimals":"0","alarm":"----"},"17":{"name":"DPF Soot Load","raw":-1,"real":-1,"unit":"percent","count":0,"maxval":200,"minval":0,"decimals":"0","alarm":"----"},"18":{"name":"DPF Ash Load","raw":-1,"real":-1,"unit":"percent","count":0,"maxval":100,"minval":0,"decimals":"0","alarm":"----"},"19":{"name":"High Float","raw":0,"real":0,"unit":"","count":0,"maxval":1,"minval":0,"decimals":"0","alarm":"----"},"20":{"name":"Low Float","raw":0,"real":0,"unit":"","count":0,"maxval":1,"minval":0,"decimals":"0","alarm":"----"},"21":{"name":"Latitude","raw":29129520,"real":29129520,"unit":"degree","count":0,"maxval":10000,"minval":0,"decimals":"0","alarm":"----"},"22":{"name":"Longitude","raw":-81022471,"real":-81022471,"unit":"degree","count":0,"maxval":10000,"minval":0,"decimals":"0","alarm":"----"}},"outputs":{"1":{"name":"Relay 1","state":0},"2":{"name":"Relay 2","state":0},"4":{"name":"Auto Start CI","state":0}},"thermostats":[]}

I am not a developer so I am not sure what the code would be for the Apex clss setup to retrive the data.
Amit Singh 1Amit Singh 1
You can use online tool JSON2APEX to generate the apex class. And then Deserialize the same.