0

I have an automation account in Azure and I have a runbook in it. What I'm trying to do is to make an API call from this runbook. I'll need to login to some web service, get a session token and then use this session token to call some controller's methods.

So far I have only found some ways to call Azure runbooks through API (let's say from some backend c# code), but not vica versa. What I need to do is to call some c# methods FROM Azure runbook.

Is there a way to do it? If there is, how do I pass queries within my call? What I'm expecting to see is something like:

$response = MakeApiCall -Url "www.someurl.com" -Body "some json for example"
Sofia Bo
  • 679
  • 1
  • 10
  • 20
  • Powershell runbook? Is [`Invoke-RestMethod`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-restmethod?view=powershell-6) you are looking for? – Joy Wang Aug 28 '19 at 08:08

1 Answers1

4

Yes you can.

It's either

$Url = "https://my-url"
$Body = @{
    field = "value"
}
Invoke-RestMethod -Method POST -Uri $url -Body $body -UseBasicParsing

or

Invoke-WebRequest

Invoke-RestMethod by default parses output, Invoke-WebRequest donesn't.

Adam Marczak
  • 2,257
  • 9
  • 20
  • Thank you for the answer! I'll try this one and let you know right away. – Sofia Bo Aug 28 '19 at 13:46
  • unfortunately, this does not work for Azure runbooks. It works locally but when I try it in Azure I get: No connection could be made because the target machine actively refused it – Sofia Bo Aug 28 '19 at 14:19
  • Sorry, my mistake. They do not work for localhost but they do for normal urls. – Sofia Bo Aug 28 '19 at 14:50