Hello All,
The API Proxy we have is receiving a JSON body in the request. One component in the JSON body is a string.
{
"event_id": 1234
"event": "H4sIAAAAAAAAA8pIzcnJVyjPL8pJAQAAAP//AwCFEUoNCwAAAA=="
}
We need to decode the "event" string to a text to be able to parse and process it.
How can we do that in Apigee?
Solved! Go to Solution.
Two things
What are you really trying to do? What is the "requestXML" thing? Are you trying to decode a gzipped-then-base64-encoded SAML Assertion? If so, this pre-built Java callout may help you: Apigee Java SAML Decoder. It does the base64-decode-then-gunzip thing. In the case of a data stream like PFJlc3BvbnNlIERlc3Rp.... It produces an XML assertion.
To decode the "event" field which is in base64 format in Apigee, you can follow these steps:
Extract Base64 Content: First, extract the base64 string value of the "event" field from the JSON request body.
Decode the Base64: Use a JavaScript policy in Apigee to decode the base64 content. You can do this using the atob() function in JavaScript.
Handle the Decoded Result: After decoding the base64 string, you will get the original text. Now, you can manipulate or process this text as needed.
Thank you for responding I tried the following code
var base64Data = context.getVariable("request.content['event']");
var compressData = atob(base64Data);
context.setVariable("requestXML", compressData);
and got the following error. Not sure what i am missing
Execution of JavaScript-2 failed with error: Javascript runtime error: "ReferenceError: "atob" is not defined. (JavaScript-2.js:4)"
Two things
What are you really trying to do? What is the "requestXML" thing? Are you trying to decode a gzipped-then-base64-encoded SAML Assertion? If so, this pre-built Java callout may help you: Apigee Java SAML Decoder. It does the base64-decode-then-gunzip thing. In the case of a data stream like PFJlc3BvbnNlIERlc3Rp.... It produces an XML assertion.
Thank you Dino for confirming. I was hoping we could gunzip in Apigee via a Javascript maybe. I will checkout the Java callout.