Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

How do I send JSON body to my POST request in Javascript and same way do do I get JSON response in my APIGEE api proxy program

Not applicable

Hello,

I am creating api proxy program where I can send bunch of POST request and GET request. With those request I have to send JSON body with bunch of key-values pairs and in return I get JSON response where also key-values pair comes .

Please guide me If there is and build in policy is there or how do I do in JavaScript policy.

Please share sample code or example for understand format.

Thank you.

Solved Solved
0 6 46.9K
1 ACCEPTED SOLUTION

Not applicable

Here is a sample that posts an entry to Splunk using an async POST method.

var splunkLoggingServerURL = context.getVariable("logConfig.splunkLoggingServerURL");
var splunkLoggingServerBasicAuth = context.getVariable("logConfig.splunkLoggingServerBasicAuth");

var logJsonObj = JSON.parse(context.getVariable("log"));
logJsonObj.foo = "bar";

var headers = {
    'Content-Type': 'application/json',
    'Authorization': splunkLoggingServerBasicAuth
};

var myRequest = new Request(splunkLoggingServerURL, "POST", headers, JSON.stringify(logJsonObj));

// asynchronous POST for performance reasons
httpClient.send(myRequest);

The sample gets a log message from context, parses it out, adds additional attributes, stringifies the modified object, then performs the POST.

View solution in original post

6 REPLIES 6