R

Monday, August 28th, 2023 5:38 PM

Import API

We are on:
Build Number: 20230817133319
Product Version: 2023.08.1-53

The data I am trying to import is updated in a periodical basis. So, I thought this would be a great opportunity to utilize the import API. I wrote a powershell script to automate this process and make API calls. My script is able to send the POST request and return a 200 response code. However, I am getting error on the activities tab in Collibra. The error is shown in the screenshot below:

image

I tried to find information regarding this error but couldn’t find anything related to it. My powershell script is shown below:

  $headers = @{
    'accept' = 'application/json'
    'Authorization' = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes('user:password'))
}

$body = @{
    strictQuotes = 'false'
    escape = '\'
    continueOnError = 'false'
    separator = ','
    deleteFile = 'false'
    simulation = 'false'
    fileName = 'TestAPI'
    headerRow = 'false'
    ignoreLeadingWhitespace = 'false'
    sendNotification = 'false'
    fileId = ''
    template = '[   {     "resourceType": "Asset",     "identifier": {       "name": "${1}",       "domain": {         "name": "Name",         "community": {           "name": "Name"         }       }     },"type": {         "name": "Name"       },     "attributes" : {       "c82e8f17-6b3a-4c98-9c6e-faebad2456d2" : [ {         "value" : "${2}"        } ],       "7f5d6a92-1a88-47b6-8f31-e6a9c824d753" : [ {         "value" : "${3}"       } ],       "9d4f1a25-82c3-4e5e-a3b9-6d08f567218f" : [ {         "value" : "${4}"       } ],       "e79b027f-d6ea-4372-bb68-092e3d8a6a29" : [ {         "value" : "${5}"       } ],       "a1cf08e8-3496-4f85-ae16-7f1047d3b6e7" : [ {         "value" : "${6}"       } ],       "3f8b9d71-65c2-4bf1-8e0a-524f9768576d" : [ {         "value" : "${7}"       } ]     }   } ]'
    saveResult = 'false'
    batchSize = '1000'
}

# Convert the body to JSON format
$jsonBody = $body | ConvertTo-Json

# Provide the full path to the CSV file
$csvFilePath = 'C:\Users\user1\Documents\TestAPI.csv'

# Create a boundary string for the multipart/form-data
$boundary = [System.Guid]::NewGuid().ToString()

# Construct the multipart/form-data content
$multipartContent = [System.Text.Encoding]::UTF8.GetBytes( 
    ("--$boundary`r`n" + 
    "Content-Disposition: form-data; name=`"json`"`r`n`r`n$jsonBody`r`n" + 
    "--$boundary`r`n" + 
    "Content-Disposition: form-data; name=`"file`"; filename=`"$(Split-Path $csvFilePath -Leaf)`"`r`n" + 
    "Content-Type: text/csv`r`n`r`n" + 
    (Get-Content -Path $csvFilePath -Raw) + "`r`n" + 
    "--$boundary--")
)

$headers['Content-Type'] = "multipart/form-data; boundary=$boundary"

$response = Invoke-RestMethod -Uri 'https://my-org.collibra.com/rest/2.0/import/csv-job' -Method 'POST' -Headers $headers -Body $multipartContent

$response

I am using Basic Auth for authorization with my username and password. I was able to do the import using the import API available on the site ‘my-org/collibra.com/docs/index.html’. However when I try to execute using powershell or python, I get an error saying ‘argument “content” is null’. I am trying to figure out what is causing this error.

Any help is appreciated, thank you in advance. :slight_smile:

62 Messages

 • 

755 Points

5 months ago

Since the import job started - but resulted in an error - then I would look into the json template provided.  - in the JSON Template, you have the following for the identifier:
    "identifier": {
      "name": "${1}",
      "domain": {
        "name": "Name",
        "community": {"name": "Name"}
      }
    },

In this json template - the name is mapped to the First Column of the import file, and the Domain and Community are set to 'Name' - which means the import is trying to Create an asset in the Community Named 'Name' inside a domain named 'Name' - if these hard coded domain name/community name combinations does not exist - then the import would run into an error.

Loading...