Creating Profiles via API through PowerShell

Hello!


I have been trying to create a profile through PowerShell and the MobiControl API.

The end goal is to have a package assigned to it as well.

Have been trying the following:

Using Content-Type text/xml


$xmltest = '<?xml version="1.0" encoding="UTF-8"?>
<Profile>
    <Name>APITest_NewProfile</Name>
    <Description>Test</Description>
    <DeviceFamily>AndroidPlus</DeviceFamily>
    <DeviceFamilyQualification>AndroidWork</DeviceFamilyQualification>
</Profile>'

$response = Invoke-RestMethod -Uri "https://$MCFQDN/mobicontrol/api/profiles" -ContentType "text/xml" -Method POST -Headers $Header -Body $xmltest -Verbose


I have also tried with a hashtable too, but either way I get the same error:
"profileRequest: Error parsing value Contract validation failed"

I have looked at the api list, and it appears to me that these is the minimal required fields when not attaching a package.

Thanks in advance

Mikael

a year ago
Android
ANSWERS
ZC
Zafer Cigdem
a year ago

Hello Mikael,

Are you familiar how to use PowerShell for any API calls (even for MobiControl or others). Did you also write the authentication part, as it is a must to have to do any API call.

If you are not so much familiar on PowerShell side, you may use Postman or similar 3rd party API tool first and then confirm whether everything is well (if you haven't tried yet). And even from Postman you can export the API call to different programming languages such as export as an powerhshell etc.

I hope this helps. 

Zafer

MA
Mikael Aspehed
a year ago

Hi Zafer,

Yes, I have the authentication part too, just not added it here.

I am able to query for packages and upload a new package for example.

Just not create a profile..

//Mikael

ZC
Zafer Cigdem
a year ago

Hi Mikael,

That's great then. When you try to this specific API call from MobiControl Swagger page, can you get success message?
I'm wondering you may have an permission issue to create a profile maybe

Zafer

ZC
Zafer Cigdem
a year ago

I just tested this out from my swagger page, and it works well, you may test this out just to test out permission related control. 

Here how I test in a very basic way. to verify

{
  "Name": "ZaferprofileviaAPI",
  "Description": "zafer desc",
  "ReferenceId": "string",
  "DeviceFamily": "AndroidPlus",
  "DeviceFamilyQualification": "Regular"
}

MA
Mikael Aspehed
a year ago

Yeah, I managed to get it to work now using the api page.

So in PowerShell i'm now using ContentType Text/json and supplying a string.

So now it works and I can continue with the work.

Thank you for the help.

Not really sure what was the cause, might have been permissions or something, I "re-applied" the permissions to view/manage profiles.

ZC
Zafer Cigdem
a year ago

That's great! Happy to hear. 

Have a great weekend.

Zafer

T
TLMOD@SOTI
a year ago

Hi Mikael,

Thanks for posting on SOTI pulse. Thanks Zafer for responding to the post, your expertise and willingness to help are greatly appreciated!

Has your query been resolved? If not, or if you have any additional concerns, please don't hesitate to reach out. We are dedicated to providing assistance and support.

Also, if this post has helped you in solving your query, I would request you to mark the particular comment as "is solution", so that others may benefit from this information.

Kind Regards,