none
Trigger API using Powershell code RRS feed

  • Question

  • Hi, I want to just trigger a API (URL) every 6 hours to refresh. The thing is only until I refresh the URL in browser then only service is becoming active.

    So what is the easiest way to achieve this to trgigger the API every 6 hour period ?

    If there is any ssimple code, please provide it ?


    RH

    Friday, June 14, 2019 12:09 PM

All replies

  • What API are you using.  Please post your code.

    We do not supply code on request.  The forum is for questions about a script that you have written.


    \_(ツ)_/

    Friday, June 14, 2019 12:21 PM
    Moderator
  • Hi, I want to just trigger a API (URL) every 6 hours to refresh. The thing is only until I refresh the URL in browser then only service is becoming active.

    So what is the easiest way to achieve this to trgigger the API every 6 hour period ?

    If there is any ssimple code, please provide it ?


    RH

    Hi,

    I need to do some guessing here, but let's try it...

    When you say "API (URL)" I suppose you mean a REST API. There are two PowerShell cmdlets that can help in this case:

    Invoke-RestMethod

    and

    Invoke-WebRequest

    You can take a look at the examples here:

    Invoke-RestMethod

    and here:

    Invoke-WebRequest

    If you only need to "wake up" your web service then the following should be sufficient (execute it every 5 hours for example):

    $endpointUri = "'https://yourpage.com'"
    Invoke-restmethod -Uri $endpointUri

    or 

    $endpointUri = "'https://yourpage.com'"
    Invoke-WebRequest -Uri $endpointUri

    You can check on the example and the explaination here:

    How To Query and Parse a REST API with PowerShell

    This should do the job. Regards,


    (Please take a moment to "Vote as Helpful" and/or "Mark as Answer" where applicable. This helps the community, keeps the forums tidy, and recognizes useful contributions. Thanks!) Blog: https://blog.pohn.ch/ Twitter: @StoyanChalakov

    Saturday, June 15, 2019 7:37 PM
  • what about Triggering (invoking) a web service through Powershell script and schedule this every 6 hour period ?

    Any Powershell script for this please ?


    RH

    Saturday, June 15, 2019 9:16 PM
  • and schedule this every 6 hour period ?


    Use the Windows task scheduler to run your script.

    https://sharepointeducation.wordpress.com/2019/01/19/scheduling-powershell-script-in-windows-task-scheduler/


    Any Powershell script for this please ?

    You have to write your own script because only you know the specifics of your environment. Url's, data, accounts, etc.

    Refer to the links provided by Stoyan for examples. 

    Sunday, June 16, 2019 2:35 PM