How to make an API call from Power Automate

Solved
M
Mitchell
schusterco

I am trying to connect the API to Power Automate but I cannot seem to figure out the authentication. 

Has anyone else tried this before?

2 years ago
SOTI MobiControl
ANSWERS
AW
Adam Williams
2 years ago
HI Mitchell,
 
There's a few things to setup to get running calling the REST APIs (powerautomate or others).
 
Most of the info you need can be found at the following url, replacing out server ID (assuming a cloud instance) 
https://<SERVERID>.mobicontrolcloud.com/mobicontrol/api/docs/index/index.html?url=/mobicontrol/api/swagger/v2/swagger.json
 
I won't repeat what is in the document, but the points for Mobicontrol REST API summarised as
 
 
For Rest API calls in automate you can use the HTTP action (I think this is a premium action)
 
Get an access token
Method: Post
URI: https://<SERVERID>.mobicontrolcloud.com/mobicontrol/api/token
Headers: Authorization: Basic MyAuthorisation 
       - Where MyAuthorisation is a Base64 Encoded string for colon separated ClientID and Client Secret
       - Get need a Client ID & Client Secret by raising a SOTI support ticket if cloud instance.
Body: grant_type=password&username=MyUsername&password=MyPassword
      - Where MyUserName and MyPassword is a local user within Mobicontrol with the permissions required to access the desired APIs e.g. Configure Devices/Devicew Groups (Role Mobicontrol Administrator might be suitable just to get up and running)
 
 
Use the Parse Json operator to parse the returned body.
    - Instead of defining the schema you can click "Generate from sample" and copy the response body.
 
Then call the desire API e.g. Get Device Details (assuming your MyUserName has to correct permissions)
Method: Get
URI: https://<ServerID>.mobicontrolcloud.com/mobicontrol/api/devices/search
Header: Bearer MyAccessToken
             MyAccessToken being the access_token element of the parse json response
 
And finally json parse the returned response.
 
 
Testing in powerautomate is a bit of a pain, I prefer doing all of my API testing in Postman.
Any questions, let me know
Adam
 
 
 
Solution
M
Mitchell
2 years ago

This worked perfectly for me. I just can't figure out how SendMessage is formatted now

AW
Adam Williams
2 years ago

Hi Mitchell,

Great to hear. The below should work for you.

Method:POST 

URI: https://<SERVERID>.mobicontrolcloud.com/mobicontrol/api/devices/<DEVICEID>/actions

Authorization: Bearer Token

Body:

{
  "Action": "SendMessage",
  "Message": "Test",
  "SendBy": "MobiControl",
  "QueueForOfflineDelivery": "true",
  "DisplayDuration": "UntilPressOk",
  "MessageType": "Information"
}

I imagine only action and message are required in the body, but worth knowing the other parmeters too.

FYI:

If you need to get DeviceID, then get all devices and DeviceID is listed as one of the returned value pairs

In my above image I get Device ID based on a search for Hardware Serial (Note these need to be URL encoded (twice is think)

FYI:

The documentation is fairly limited on APIs, one of the most helpful pieces of advice I had when using the APIs was the following. In Mobicontrol, select your device and choose your action e.g. SendMessage. Before pressing send, press F12, network and expand the action. This (in come cases) give you an idea of what the Method/URI/Body etc are for the actions. They wont always give you the exact answer youre looking for but are usually more helpful than the documentation.

G
GPMOD@SOTI
2 years ago

Hi Mitchell

Thanks for posting on SOTI Pulse and thanks Adam for responding to the post. 

I am glad to see that you found the resolution to Adam's suggestions. 

Feel free to reach out to Technical support if you have any other queries. 

Thank you. 

Kind regards,

Technical Support | SOTI Inc. |1.905.624.9828 | support@soti.net | www.soti.net |