I am retrieving data from an external system: ```...
# suitescript
m
I am retrieving data from an external system:
Copy code
var response = https.get({
                        url: data_url,
                        headers: headers
                    });
                    log.debug('HTTP Response :', response);
The response object contains all the data, for example: {"type":"http.ClientResponse","code":200,"headers":{"Content-Length":"4710","Date":"Wed, 23 Sep 2020 000614 GMT","Content-Type":"application/json","Via":"1.1 mono006"},"body":"{\"*startedOn*\": \"2020-01-14T212659+00:00\" How may I get the startedOn value?
b
your body is a string in json format
use JSON.parse on the body to turn it into an object
m
I tried this but the email which does exists in the reponse is empty:
Copy code
var response_data = JSON.parse(response.body);
                    log.debug('JSON.parse :' + response_data)

                    var email_add = response_data.emailAddress;
                    log.debug("Email Address: " + email_add);
b
which string is in response.body
m
actually I have nothing in the body. I first tried var response_data = JSON.parse(response); which threw an error. As I can see 'body' in the response I tried var response_data = JSON.parse(response.body);
b
log response.body, tell me what string is in it
m
I get a massive string like this - ex: {"startedOn": "2020-01-14T212659+00:00", "tasks": [{"attachments": [], "assignee": {"emailAddress": "test@test.com", "uuid": "d4654dd182b84d9f969669595bf9f179"}, "done": false, "unitPrice": 0.00000, "task":....
b
your task is inside a key
specifically an array
each individual task in the array has an assignee key, which has a value of an object
that object is what has the email address
m
so i would need to create and array and loop through the assingee keys and get the object value?
b
you probably want to understand the structure of your response body
if you understand how javascript objects work, you basically understand json
💯 1
m
alright, thanks - will have a try