I am querying a graphQL endpoint through http request and I am getting a successful response with the data that I need to collect, however, I can’t seem to navigate through the data to pull the fields I require.
const query = JSON.stringify({query:
'{' +
' all_insight_article('+
' locale: "en-gb"'+
' where: {business_unit: {business_unit: {title: "xxx"}, MATCH: ALL}, audience: {MATCH: ALL, audiences: {title: "xxx"}}publish_date_gt: "2023-02-01"}'+
' ) {'+
' items {'+
' audienceConnection {'+
' edges {'+
' node {'+
' ... on Audiences {'+
' title'+
' system {'+
' uid'+
' }'+
' }'+
' }'+
' }'+
' }'+
' system {'+
' uid'+
' publish_details {'+
' time'+
' }'+
' updated_at'+
' }'+
' absolute_url'+
' title'+
' subtitle'+
' main_image'+
' topicsConnection {'+
' edges {'+
' node {'+
' ... on Topics {'+
' title'+
' display_name'+
' system {'+
' uid'+
' }'+
' }'+
' }'+
' }'+
' }'+
' },'+
' total'+
' }'+
' }'
});
var req = new HttpClientRequest("https://eu-graphql.contentstack.com/stacks/bltcxxx?environment=xxx&access_token=xxx")
req.header["Content-Type"] = "application/json"
req.method = "POST"
req.body = query
req.execute()
var response = req.response;
var posts = JSON.parse(response.body);
var articleList_json = [];
var i
for ( i = 0; i < 15; i++) {
articleList_json.push({
"title": posts[i].title,
});
}
logInfo(articleList_json);
Here is the evidence of my response if I log logInfo(response.body);
Here is the JSON structure https://www.codedump.xyz/json/Y_V2SI6W4xxLXX1y
The error I get is posts is undefined.