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

Limit calls to only working days and specific hours in day

Not applicable

Hey! Is it possible to setup policy to restrict calls only to specific days of a week? And the same with specific hours. For example: Five days per week (not Saturday and Sunday) from 7 a.m. to 7 p.m. Cheers, Tomas

Solved Solved
1 8 599
2 ACCEPTED SOLUTIONS

Dear @Tomasz Korecki ,

Welcome to Apigee Community 🙂

Yes, It's possible. You can able to achieve same using Apigee Javascript Policy with minimal code.

  • Read present date & time using javascript
var d = new Date();

var n = d.getDay();

var n = d.getHours();
  • Compare with your conditions, set a variable based on result
  • Use raise fault policy to restrict to API based on above result to avoid hitting to backend api.

Cheers,

Anil Sagar

View solution in original post

Not applicable

I am really amazed by trace and Api console tools.

I've made few changes:

  1. Remove fault rules from proxy endpoint configuration.
  2. Moved condition checking to preflow of proxy endpoint configuration, so it looks like this:
<PreFlow name="PreFlow">
        <Request>
            <Step>
                <Name>JavascriptDatetimeParametersPolicy</Name>
            </Step>
            <Step>
                <Name>WorkingDaysAndHoursRaiseFault</Name>
                <Condition>(requestReject is true)</Condition>
            </Step>
        </Request>
        <Response/>
</PreFlow>

And it works as I want to. Thank you guys!

View solution in original post

8 REPLIES 8