After analyzing the JSON response from the Postman app, it appears as follows:
var zohoipekuetview65 = {"Leads":[{"Yearly_Sales":"$ 1,000.00","Email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0f7b6a7c7b4f75606760216c6062">[email protected]</a>","Phone":"123-032-03323","Potentially":50,"State":"NY","ZipCode":"10036","Street":"1515 Broadway","Country":"USA","ID":"2198633000000063029","City":"New York","Name":"Arfater Rahman"}]};
Upon attempting to use this response directly, an error is encountered:
function JsonResponse(){
var json ='var zohoipekuetview65 = {"Leads":[{"Yearly_Sales":"$ 1,000.00","Email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="780c1d0b0c3802171017561b1715">[email protected]</a>","Phone":"123-032-03323","Potentially":50,"State":"NY","ZipCode":"10036","Street":"1515 Broadway","Country":"USA","ID":"2198633000000063029","City":"New York","Name":"Arfater Rahman"}]} '
var data = JSON.parse(json);
Logger.log(data);
}
The error message received is:
SyntaxError: Unexpected token: v
This suggests that the API response includes the term var zohoipekuetview65
, which seems to be causing the issue (likely a bug).
To extract just the JSON response from the string, you can utilize the following code snippet:
function trialParse(){
var json ='var zohoipekuetview65 = {"Leads":[{"Yearly_Sales":"$ 1,000.00","Email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0470617770447e6b6c6b2a676b69">[email protected]</a>","Phone":"123-032-03323","Potentially":50,"State":"NY","ZipCode":"10036","Street":"1515 Broadway","Country":"USA","ID":"2198633000000063029","City":"New York","Name":"Arfater Rahman"}]} '
Logger.log(JsonResponse(json))
}
function JsonResponse(response){
Logger.log(response)
var json = response.split("=")[1]
var data = JSON.parse(json);
Logger.log(data);
return data
}
You can then simply call the function in your code using var data = JsonResponse(json)
.
Lastly, consider utilizing Logger.log(json)
as suggested by Jordan Rhea to output the API response to your logs. You can view these logs under Views > Logs.