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

How to retrieve the content of resource files defined at env level ( JavaScript )

Hi, 

I have a resource file of type Javascript, defined at the environment level. I want to create a shared flow which will be capable of reading this resource file (which contains a configuration) and process it using some javascript code. How can I do that?

My shared flow contains a javascript policy with the logic of how to read an interpret the data from that resource file. But how I can "include" that in the shared flow?

The final aim is to have that shared flow deployed on various Apigee environments, and depending on the resource file, the behaviour of shared flow to be different. 

Thank you.

Solved Solved
0 3 1,306
1 ACCEPTED SOLUTION

I think you can do something like this: 

<AssignMessage name='AM-get-resource'>
  <AssignVariable>
    <Name>assigned-variable</Name>
    <ResourceURL>jsc://resourcename.json</ResourceURL>
  </AssignVariable>
</AssignMessage>

This will embed the content of the resource into the assigned-variable variable. And the resource can be resolved from environment scope. I believe the format of the resource file can be anything. Text, json, whatever you like. 

Try it and see. 

If that does not work, you can also do this in JS: 

<Javascript name='JS-read-settings' timeLimit='200' >
  <IncludeURL>jsc://settings.js</IncludeURL>
  <ResourceURL>jsc://readSettings.js</ResourceURL>
</Javascript>

But in this case the "settings.js" file must be valid JavaScript.  So you'd have to encode your settings as JavaScript (not json!)

View solution in original post

3 REPLIES 3