Share via

MIM CM API Data Collection problems

ScottyDoo 111 Reputation points
2023-04-04T14:16:11.57+00:00

Hi All,   I am using PowerShell to connect to a legacy version of MIM CA, trying to enroll for a certificate using the API   I start by using the following to get the certificate profiles:

$Creds = Get-Credential

$URI = “Https://MIMServer/CertificateManagement/api/v1.0/profiletemplates”

$Results = Invoke-WebRequest -URI $URI -Method GET -Credential $Creds

$Results.content | ConvertFrom-JSON


This gives me my list of certificate templates where I use the following to get the enrolment policy:

$URI =“Https://MIMServer/CertificateManagement/api/v1.0/profiletemplates/<CertificateProgfileGUID>/policies/enroll”
$Results = Invoke-WebRequest -URI $URI -Method GET -Credential $Creds
$Results.content | ConvertFrom-JSON

This tells me I have a single required data collection item of “Email” so I then use the following to try and enroll for the certificate:


$Request = @’{
	“dataCollection” : [{“Email” : “******@my.domain.com”}],
	“profiletemplateuuid” : “<CertificateProgfileGUID>”,
	“Type” : “Enroll”,
	“comment” : “API wont work”
}
‘@
$reqLength = [System.Text.Encoding]::ASCII.GetBytesCount($Request)
$Headers = @{
	“Content-Type”=”application/json”
	“Content-Length”=”$reqLength” 
}
$URI = “Https://MIMServer/CertificateManagement/api/v1.0/requests
$Results = Invoke-WebRequest -URI $URI -Method POST -Body $Request -Headers $Headers -Credential $Creds

This throws a data validation error, when I look at the server the error “Data item ‘Email’ is required. An empty value is not permitted.”   No matter what I do I cannot get the API to accept a data collection… If I request a certificate that does not require a data item it works fine.   Has anybody got this to work in the past? Am I doing something wrong or is this an API issue?   Thanks.

Windows for business | Windows Server | User experience | PowerShell
Microsoft Security | Microsoft Identity Manager
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. ScottyDoo 111 Reputation points
    2023-05-24T08:52:21.17+00:00

    For completeness, and for anyone who ever comes across this issue... Thanks to a helpful friend who decompiled the API we were able to find that the datacollection handler function was expecting the data in a format totally different to that which is documented. So we reconstructed the JSON in the following format and no more errors:

    $Request = @’
    {
    	“profiletemplateuuid” : “<ProfileUUID>”,
        "datacollection":[
        {
          "Name": "Email",
          "Value": "******@address.com"
        }
      ],
        “Type” : “Enroll”,
    	“comment” : “API Now Works!”
    }
    ‘@
    
    1 person found this answer helpful.
    0 comments No comments

  2. ScottyDoo 111 Reputation points
    2023-04-04T14:23:25.29+00:00

    Can't seen to get the final code snippet to save ? Here it is in plain: $Request = @’ { “dataCollection” : [“Email” : “******@my.domain.com”}], “profiletemplateuuid” : “/<CertificateProgfileGUID>”, “Type” : “Enroll”, “comment” : “API wont work” } ‘@ $reqLength = [System.Text.Encoding]::ASCII.GetBytesCount($Request) $Headers = @{ “Content-Type”=”application/json” “Content-Length”=”$reqLength” } $URI = “Https://MIMServer/CertificateManagement/api/v1.0/requests $Results = Invoke-WebRequest -URI = $URI -Method POST -Body $Request -Headers $Headers -Credential $Creds

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.