i would like to extract 2 variables from the response using extract variables and set the content of the payload using javascript callout.
I need name and client id in my payload. @Anil Sagar @ Google
my response payload is
{ "appId":"f9ea6c2d-019f-4478-xxxx-b80852844c4c", "attributes":[], "createdAt":1543446822040, "createdBy":"xxxxx@outlook.com", "credentials":[ { "apiProducts":[ { "apiproduct":"xxx", "status":"approved" } ], "attributes":[ ], "consumerKey":"xxxxxxxiqfU79At9U6AlVePlvyM9pzG", "consumerSecret":"SxxxxxxUItjr", "expiresAt":1546038822130, "issuedAt":1543446822130, "scopes":[ ], "status":"approved"
Your ExtractVariables step above, is setting 2 variables with your content:
The relevant information regarding the Javascript Object model is here. However, this is one way you could do it:
var client_id = context.getVariable('clientID') || ''; var name = context.getVariable('appName') || ''; var message_str = context.getVariable('message.content'); // This will return the message content regardless of context var message_obj = {}; try { message_obj = JSON.parse(message_str); } catch (_er) { print('Could not parse message to an object!'); } if (message_obj) { message_obj.client_id = client_id; message_obj.name = name; context.setVariable('message.content', JSON.stringify(message_obj)); }
User | Count |
---|---|
1 | |
1 | |
1 | |
1 | |
1 |