azureschedulerazure-scheduler

How to invoke Azure Scheduled Job by a webrequest


How do i invoke a Microsoft Azure Scheduled Job from my serverside code?

I have a running Scheduled Job, that calls an endpoint, to send out some emails and sync some data. I have a system, where users can send emails out to lists of emails. So instead of the user waiting xx minutes for a response from the web server, after it is done sending out emails, I would like to just call my Scheduled Job, so that the user can initiate the email sendout, but doesnt have to wait for it to finish. Sort of "Fire and forget" for the user.

How do i go around to do this? I haven't been able to find any info on how to achieve it.

Thanks in advance.

Update:

I found this documentation right after posting:

https://learn.microsoft.com/en-us/rest/api/scheduler/jobs/run

POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Scheduler/jobCollections/{jobCollectionName}/jobs/{jobName}/run?api-version=2016-03-01

I am however not able to find info on how to authenticate against this endpoint. But it seems like its definetly possible to do.


Solution

  • I'll leave the question/answer be, in case it can help anyone.

    It turned out that using the azure endpoint for a Post call to invoke the scheduled job, was a good solution.

    After setting the resource group and jobcollection up correctly, I got it working. https://learn.microsoft.com/en-us/rest/api/scheduler/jobs/run

    POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Scheduler/jobCollections/{jobCollectionName}/jobs/{jobName}/run?api-version=2016-03-01