Skip to main content
Inspiring
Feb 14, 2024 6:01 AM UTC
Solved

Different way to expire Web API

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?

    harshitb6843
    Brainy
    Feb 14, 2024 6:26 AM UTC

    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
    Brainy
    Feb 14, 2024 6:26 AM UTC

    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"
      )
    )