APIGEE

Javascript in Apigee

// get the response from BigQuery
var bqResponse = context.getVariable("bqResponse.content");
if (bqResponse !== null) {
    var bqResponseJson = JSON.parse(bqResponse);
    var result = [];
    for (var row in bqResponseJson.rows) {
        if (bqResponseJson.rows.hasOwnProperty(row)) {
            var fields = bqResponseJson.rows[row].f;
            result.push({"product": fields[0].v, "qty": fields[1].v});
        }
    }
    context.setVariable("response.content", JSON.stringify(result));
    //set the content-type
    context.setVariable("response.header.Content-Type", "application/json");
}

Tracing session in progress

labs

Last updated

Was this helpful?