I am trying to take advantage of the SP-Config API that is currently in beta to export and import Source objects using PowerShell. I have the export side working just fine. The import side is not working. IdentityNow consistently returns 400 Bad Request when I try to start an import job. How do I need to format the contents of the request? Are there particular difficulties with PowerShell here? Why is the code below not working? What are good strategies for debugging it?
The Source file that I am using as a guinea pig was created as a result of using SP-Config to export its definition from a first tenant. I am trying to import it for the first time into a second tenant. The PowerShell code below captures the essence of what is happening for this test case.
# already verified preconditions:
# the routine to retrieve an $accessToken works and supplies a valid token consistently
# $tenant and $importFileName have valid values
# file referenced by $importFileName contains valid JSON for a Source object
[Hashtable]$bulkFileContents = @{
version = 1
timestamp = Get-Date -Format "o"
options = @{
includeTypes = @("SOURCE")
}
objects = @(
@{
version = 1
self = @{
type = "SOURCE"
name = "AD - Contoso"
}
object = Get-Content -Path $importFileName -Raw | ConvertFrom-Json -AsHashtable
}
)
}
[FileInfo]$tempFile = New-TemporaryFile
Set-Content -Path $tempFile -Value ($bulkFileContents | ConvertTo-Json -Depth 100)
[Hashtable]$formContents = @{
data = $tempFile
options = @{
includeTypes = @("SOURCE")
objectOptions = @{
"SOURCE" = @{
includedNames = @("AD - Contoso")
}
}
}
}
[Hashtable]$requestParameters = @{
Method = [WebRequestMethod]::Post
Uri = "https://$tenant.api.identitynow.com/beta/sp-config/import"
Authentication = [WebAuthenticationType]::Bearer
Token = $accessToken
Form = $formContents
}
[BasicHtmlWebResponseObject]$htmlResponse = Invoke-WebRequest @requestParameters
The response from IdentityNow is a simple HTML 400, with no further diagnostic information about why the request was bad. I have tried using the preview switch, but it had no effect.