dynamically set policy attribute - populateCache

Hi,

Is it possible to set the cacheResource dynamically from for instance a Javascript policy?

I'm affraid the chance is pretty low this is possible since the value is checked when deploying the API. A workaround would be to use the Apigee-access node module, but I'm asking to be sure 🙂

thanks,

Guy

Solved Solved
2 3 152
1 ACCEPTED SOLUTION

Not applicable

Hi @GuyH . Correct, from plain JS Policy is not possible. However, I'm trying to understand the use case here. There are ways to modify Policy attributes in runtime without having to redeploy the API proxy. For instance, you could leverage an API call to this one, except that yours would be for PopulateCache Policy updating CacheResource attribute with another value:

curl https://api.enterprise.apigee.com/v1/o/testmyapi/apis/forecastweatherapi/revisions/1/policies/xmltoj... -u $ae_username:$ae_password -v -X PUT -d '{
  "policyType" : "XMLToJSON",
  "async" : "false",
  "continueOnError" : "false",
  "displayName" : "XMLtoJSON-1",
  "enabled" : "false",
  "faultRules" : [ ],
  "format" : "yahoo",
  "name" : "xmltojson-1",
  "outputVariable" : "response",
  "source" : "response"}' -H 'Content-Type:application/json'

View solution in original post

3 REPLIES 3

Not applicable

Hi @GuyH . Correct, from plain JS Policy is not possible. However, I'm trying to understand the use case here. There are ways to modify Policy attributes in runtime without having to redeploy the API proxy. For instance, you could leverage an API call to this one, except that yours would be for PopulateCache Policy updating CacheResource attribute with another value:

curl https://api.enterprise.apigee.com/v1/o/testmyapi/apis/forecastweatherapi/revisions/1/policies/xmltoj... -u $ae_username:$ae_password -v -X PUT -d '{
  "policyType" : "XMLToJSON",
  "async" : "false",
  "continueOnError" : "false",
  "displayName" : "XMLtoJSON-1",
  "enabled" : "false",
  "faultRules" : [ ],
  "format" : "yahoo",
  "name" : "xmltojson-1",
  "outputVariable" : "response",
  "source" : "response"}' -H 'Content-Type:application/json'

Thanks. That's very interesting indeed. The use case I have is actually that the policy will have to be adjusted for about every API call so I think doing this by a apigee-access-node module is easier. But still I'm storing this post for future purposes as it's very useful!

That makes sense. Yeah, I'd stick to Apigee-Access too.