Skip to main content
February 14, 2024
Solved

Different way to expire Web API

  • February 14, 2024
  • 1 reply
  • 0 views

Hi Team,

I'm using API Key approach to access web api, is there a automated way to disable the web API to show error between 4pm to 8pm. Is there a approach to do that?

    Best answer by harshitb6843

    You can add this logic in the API to only execute the action between the time you want it. 

    if(
      and(
        now() > time(16, 00, 00, 00),
        now() < time(18, 00, 00, 00)
      ),
      a!httpResponse(
        statusCode: 200,
        headers: {},
        body: "Hello World"
      ),
      a!httpResponse(
        statusCode: 503,
        headers: {},
        body: "Please try between 4:00 PM and 8:00 PM"
      )
    )

    1 reply

    harshitb6843
    February 14, 2024

    You can add this logic in the API to only execute the action between the time you want it. 

    if(
      and(
        now() > time(16, 00, 00, 00),
        now() < time(18, 00, 00, 00)
      ),
      a!httpResponse(
        statusCode: 200,
        headers: {},
        body: "Hello World"
      ),
      a!httpResponse(
        statusCode: 503,
        headers: {},
        body: "Please try between 4:00 PM and 8:00 PM"
      )
    )