0

This Api on this URL can be helpfull ? https://learn.microsoft.com/en-us/rest/api/dtl/virtualmachineschedules/get

Please Help !

Mengdi Liang
  • 17,577
  • 2
  • 28
  • 35
Soumya Mishra
  • 39
  • 1
  • 8

1 Answers1

2

No, the API you provided is for the VM in Azure DevTest Labs, if you want to change the auto shut downtime for a normal azure VM, use the one below.

To acquire an access token, see this link.

Request URL:

PUT https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/microsoft.devtestlab/schedules/shutdown-computevm-<VMname>?api-version=2018-09-15

Request header:

Content-Type: application/json; charset=utf-8
Authorization: Bearer eyJ0exxxxx6dyJ9

Request body(1900 means 19:00 i.e. 7:00:00 PM):

{
  "properties": {
    "taskType": "ComputeVmShutdownTask",
    "timeZoneId": "China Standard Time",
    "dailyRecurrence": {
      "time": "1900"
    },
    "targetResourceId": "/subscriptions/<subscription-id>/resourceGroups/<resource-group-name>/providers/Microsoft.Compute/virtualMachines/<VMname>",
    "status": "Enabled",
    "notificationSettings": {
      "timeInMinutes": 30,
      "status": "Disabled"
    }
  },
  "location": "eastus"
}

enter image description here

enter image description here

Joy Wang
  • 39,905
  • 3
  • 30
  • 54
  • Thank you very much Joy ! This Works for my compute Vms – Soumya Mishra Nov 29 '19 at 05:06
  • Hi Joy I have one more question, before your response I also tried to schedule auto shutdown on vm using runbooks under automation account where I can also have auto start feature but I stuck in one thing that is if I have runbook under Automation Account and in that runbook I want to use link to schedule settings using any Rest Api (Automation Account => runbbooks => link to schedule) ? Currently azure have Any rest api to use link to schedule settings under runbbooks ? – Soumya Mishra Nov 29 '19 at 06:06
  • @SoumyaMishra If I understand you correctly, you want to add a schedule to the runbook, if so, you could use this api:https://learn.microsoft.com/en-us/rest/api/automation/jobschedule/create – Joy Wang Nov 29 '19 at 06:18
  • I already tried for this api but how to get jobScheduleId for this api ? and jobSchduleId also can get from this api try to put but getting error { "code": "NotFound", "message": "Job Schedule not found." } https://management.azure.com/subscriptions/xxxxx-xxx-xx-xxx-xxxx/resourceGroups/xxx/providers/Microsoft.Automation/automationAccounts/xxx/jobs?api-version=2015-10-31 – Soumya Mishra Nov 29 '19 at 08:18
  • Now I am getting - { "code": "NotFound", "message": "Runbook not found." } – Soumya Mishra Nov 29 '19 at 08:32
  • @SoumyaMishra `Job Schedule` is not `Job`, just try the body `{ "properties": { "schedule": { "name": "" }, "runbook": { "name": "" }, "parameters": {} } }` in this api https://learn.microsoft.com/en-us/rest/api/automation/jobschedule/create , just generate a GUID for `jobScheduleId`. – Joy Wang Nov 29 '19 at 08:36
  • management.azure.com/subscriptions/xxx/resourceGroups/xxxx/providers/Microsoft.Automation/automationAccounts/TestRunbook2/jobSchedules/4fb4db16-4aa7-4cbf-be40-2030faaab78b?api-version=2015-10-31 Json Body :- { "properties": { "schedule": { "name": "ForStartVM11" }, "runbook": { "name": "TestRunbook2" }, "parameters": {} } } getting same error as above Runbook not found. – Soumya Mishra Nov 29 '19 at 08:49
  • GUID - 4fb4db16-4aa7-4cbf-be40-2030faaab78b which is mentioned generated online – Soumya Mishra Nov 29 '19 at 08:51
  • @SoumyaMishra The `automationAccountName` is not the `runbook-name`, I notice you use the same value for them. – Joy Wang Nov 29 '19 at 08:55
  • @SoumyaMishra check this screenshot https://i.stack.imgur.com/G6aoi.png – Joy Wang Nov 29 '19 at 08:59
  • Thank You so much Joy !!! yes it was my mistake,I passed wrong parameters in json, now it's working – Soumya Mishra Nov 29 '19 at 09:02