# NELM Bulk Update API

**URL:** <https://developer.sailpoint.com/discuss/t/nelm-bulk-update-api/495>\
**Category:** SHF Discussion and Questions\
**Created:** [May 5, 2021, 3:12pm UTC](https://developer.sailpoint.com/discuss/t/nelm-bulk-update-api/495 "2021-05-05T15:12:03Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![justinrhaines](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/justinrhaines/32/16564_2.png) [@justinrhaines](https://developer.sailpoint.com/discuss/u/justinrhaines)\
**Post date:** [May 5, 2021, 3:12pm UTC](https://developer.sailpoint.com/discuss/t/nelm-bulk-update-api/495/1 "2021-05-05T15:12:03Z")

</div>

I noticed that the NELM Bulk Update API uses a content-type of multipart/form-data in the body. Has anyone developed a script to automate the upload of NELM data? Our client will be using a SharePoint front-end to input NELM data, export that data to a CSV, and would like to then import the data using a scheduled job but I am not seeing an easy way to accomplish that with a multipart/form-data content type. Any guidance here would be helpful!

---

<div class="post-metadata">

**Author:** ![colin\_mckibben](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/colin_mckibben/32/37182_2.png) [@colin\_mckibben](https://developer.sailpoint.com/discuss/u/colin_mckibben)\
**Post date:** [May 5, 2021, 4:13pm UTC](https://developer.sailpoint.com/discuss/t/nelm-bulk-update-api/495/2 "2021-05-05T16:13:26Z")

</div>

Hey @justinrhaines,

Thanks for posting! Let us do some poking around and get back to you shortly.

---

<div class="post-metadata">

**Author:** ![colin\_mckibben](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/colin_mckibben/32/37182_2.png) [@colin\_mckibben](https://developer.sailpoint.com/discuss/u/colin_mckibben)\
**Post date:** [May 5, 2021, 5:22pm UTC](https://developer.sailpoint.com/discuss/t/nelm-bulk-update-api/495/3 "2021-05-05T17:22:59Z")

</div>

Hello @justinrhaines,

Is this the endpoint you are referring to?

[https://developer.sailpoint.com/idn/api/beta/non-employee-records-bulk-upload](https://developer.sailpoint.com/idn/api/beta/non-employee-records-bulk-upload)

Do you know what programming language you will use for the script?

Here are some examples using cURL and Python:

cURL

```nohighlight
curl --location --request POST 'https://{tenant}.api.identitynow.com/beta/non-employee-sources/2c9180887933afa701793d96d9cb5e6d/non-employee-bulk-upload' \
--header 'Authorization: Bearer {access_token}' \
--form 'data=@"/Users/my_user/Documents/non_employees_for_source_Contractors.csv"'

```

Python using [requests](https://pypi.org/project/requests/) library

```python
import requests

url = "https://{tenant}.api.identitynow.com/beta/non-employee-sources/2c9180887933afa701793d96d9cb5e6d/non-employee-bulk-upload"

payload={}
files=[
  ('data',('non_employees_for_source_Contractors.csv',open('/Users/my_user/Documents/non_employees_for_source_Contractors.csv','rb'),'text/csv'))
]
headers = {
  'Authorization': 'Bearer {access_token}'
}

response = requests.request("POST", url, headers=headers, data=payload, files=files)

print(response.text)

```

To get the source ID, you can use the following endpoint:

```nohighlight
curl --location --request GET 'https://{tenant}.api.identitynow.com/beta/non-employee-sources' \
--header 'Authorization: Bearer {access_token}'

```

Look for the `sourceId` of the source you want to update in the response:

```json
[
    {
        "id": "ac110004-793d-14e4-8179-3d96e5300000",
        "sourceId": "2c9180887933afa701793d96d9cb5e6d",
        "name": "Contractors",
        "description": "Non-employee contractors",
        "approvers": [],
        "accountManagers": [],
        "created": "2021-05-05T17:32:49.989Z",
        "modified": "2021-05-05T17:32:49.989Z",
        "nonEmployeeCount": null
    }
]

```

---

<div class="post-metadata">

**Author:** ![justinrhaines](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/justinrhaines/32/16564_2.png) [@justinrhaines](https://developer.sailpoint.com/discuss/u/justinrhaines)\
**Post date:** [May 5, 2021, 5:53pm UTC](https://developer.sailpoint.com/discuss/t/nelm-bulk-update-api/495/4 "2021-05-05T17:53:55Z")

</div>

Yes, that is the API I am referring to. I would prefer to use Powershell as that is the client’s standard and can be run using the Windows task scheduler, but I am open to other options as well.

---

<div class="post-metadata">

**Author:** ![colin\_mckibben](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/colin_mckibben/32/37182_2.png) [@colin\_mckibben](https://developer.sailpoint.com/discuss/u/colin_mckibben)\
**Post date:** [May 5, 2021, 5:55pm UTC](https://developer.sailpoint.com/discuss/t/nelm-bulk-update-api/495/5 "2021-05-05T17:55:42Z")

</div>

Here is a PowerShell example using RestMethod

```powershell
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "Bearer {access_token}")

$multipartContent = [System.Net.Http.MultipartFormDataContent]::new()
$multipartFile = '/Users/my_user/Documents/non_employees_for_source_Contractors.csv'
$FileStream = [System.IO.FileStream]::new($multipartFile, [System.IO.FileMode]::Open)
$fileHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new("form-data")
$fileHeader.Name = "data"
$fileHeader.FileName = "non_employees_for_source_Contractors.csv"
$fileContent = [System.Net.Http.StreamContent]::new($FileStream)
$fileContent.Headers.ContentDisposition = $fileHeader
$multipartContent.Add($fileContent)

$body = $multipartContent

$response = Invoke-RestMethod 'https://{tenant}.api.identitynow.com/beta/non-employee-sources/2c9180887933afa701793d96d9cb5e6d/non-employee-bulk-upload' -ContentType 'multipart/form-data' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json

```

---

<div class="post-metadata">

**Author:** ![justinrhaines](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/justinrhaines/32/16564_2.png) [@justinrhaines](https://developer.sailpoint.com/discuss/u/justinrhaines)\
**Post date:** [May 5, 2021, 7:38pm UTC](https://developer.sailpoint.com/discuss/t/nelm-bulk-update-api/495/6 "2021-05-05T19:38:12Z")

</div>

Thanks, this is a great start but I am receiving the following response:

Invoke-RestMethod : {“messages”:[{“localeOrigin”:“DEFAULT”,“locale”:“en-US”,“text”:“Content type ‘application/x-www-form-urlencoded;charset=UTF-8’ not supported”}],“detailCode”:"400.0 Bad request

syntax",“trackingId”:“f7de0c8cc9da420e97a8feec9b341cd7”}

At line:27 char:13

- $response = Invoke-RestMethod '[https://amfidelity-sb.api.identitynow](https://amfidelity-sb.api.identitynow). …

- 

```auto

```

- CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException

- FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Shouldn’t this be a different content-type than x-www-form-urlencoded?

---

<div class="post-metadata">

**Author:** ![colin\_mckibben](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/colin_mckibben/32/37182_2.png) [@colin\_mckibben](https://developer.sailpoint.com/discuss/u/colin_mckibben)\
**Post date:** [May 5, 2021, 7:52pm UTC](https://developer.sailpoint.com/discuss/t/nelm-bulk-update-api/495/7 "2021-05-05T19:52:26Z")

</div>

This should have a content-type of multipart/form-data. I haven’t tested this myself as I’m using OS X, but maybe you can try explicitly setting the content-type header by adding the following line in your headers section:

```powershell
$headers.Add("Content-Type", "multipart/form-data")

```

If that doesn’t work, then I found this [Stack Overflow](https://stackoverflow.com/questions/36268925/powershell-invoke-restmethod-multipart-form-data) article that suggests adding an additional flag to the Invoke-RestMethod command:

```powershell
$response = Invoke-RestMethod 'https://{tenant}.api.identitynow.com/beta/non-employee-sources/2c9180887933afa701793d96d9cb5e6d/non-employee-bulk-upload' -ContentType 'multipart/form-data' -Method 'POST' -Headers $headers -Body $body

```

---

<div class="post-metadata">

**Author:** ![justinrhaines](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/justinrhaines/32/16564_2.png) [@justinrhaines](https://developer.sailpoint.com/discuss/u/justinrhaines)\
**Post date:** [May 5, 2021, 8:07pm UTC](https://developer.sailpoint.com/discuss/t/nelm-bulk-update-api/495/8 "2021-05-05T20:07:42Z")

</div>

Hi Collin–

Yes I tried both of those methods and received a 500 Internal Server Error on both. Any other ideas?

---

<div class="post-metadata">

**Author:** ![colin\_mckibben](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/colin_mckibben/32/37182_2.png) [@colin\_mckibben](https://developer.sailpoint.com/discuss/u/colin_mckibben)\
**Post date:** [May 5, 2021, 8:18pm UTC](https://developer.sailpoint.com/discuss/t/nelm-bulk-update-api/495/9 "2021-05-05T20:18:55Z")

</div>

Let me install a Windows VM and play around with this. I’ll see if I can figure out what’s wrong and get back to you.

---

<div class="post-metadata">

**Author:** ![justinrhaines](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/justinrhaines/32/16564_2.png) [@justinrhaines](https://developer.sailpoint.com/discuss/u/justinrhaines)\
**Post date:** [May 6, 2021, 7:44pm UTC](https://developer.sailpoint.com/discuss/t/nelm-bulk-update-api/495/10 "2021-05-06T19:44:13Z")

</div>

Hi Colin–

Did you have a chance to test this with your Windows VM?

---

<div class="post-metadata">

**Author:** ![darrenjrobinson](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/darrenjrobinson/32/2854_2.png) [@darrenjrobinson](https://developer.sailpoint.com/discuss/u/darrenjrobinson)\
**Post date:** [May 6, 2021, 9:08pm UTC](https://developer.sailpoint.com/discuss/t/nelm-bulk-update-api/495/11 "2021-05-06T21:08:04Z")

</div>

> [@colin\_mckibben](#):
>
> `multipart/form-data`

With the [IdentityNow PowerShell Module](https://github.com/darrenjrobinson/powershell_module_identitynow) we use multipart/form-data for the Join-IdentityNowAccount cmdlet.  
We needed to convert the payload to UTF8 and add formatting to the CSV to get it to play nicely.  
Here is an example where the payload is in CSV stringdata in the $csv variable.

```auto
$result = Invoke-restmethod -Uri "https://$($IdentityNowConfiguration.orgName).api.identitynow.com/cc/api/source/loadUncorrelatedAccounts/$source" `
                -Method "POST" `
                -Headers @{Authorization = "$($v3Token.token_type) $($v3Token.access_token)"; "Accept-Encoding" = "gzip, deflate, br"} `
                -ContentType "multipart/form-data; boundary=----WebKitFormBoundaryU1hSZTy7cff3WW27" `
                -Body ([System.Text.Encoding]::UTF8.GetBytes("------WebKitFormBoundaryU1hSZTy7cff3WW27$([char]13)$([char]10)Content-Disposition: form-data; name=`"file`"; filename=`"temp.csv`"$([char]13)$([char]10)Content-Type: application/vnd.ms-excel$([char]13)$([char]10)$([char]13)$([char]10)$($csv | out-string)$([char]13)$([char]10)------WebKitFormBoundaryU1hSZTy7cff3WW27--$([char]13)$([char]10)")) `
                -UseBasicParsing

```

Cheers,  
DR

---

<div class="post-metadata">

**Author:** ![colin\_mckibben](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/colin_mckibben/32/37182_2.png) [@colin\_mckibben](https://developer.sailpoint.com/discuss/u/colin_mckibben)\
**Post date:** [May 7, 2021, 1:26pm UTC](https://developer.sailpoint.com/discuss/t/nelm-bulk-update-api/495/12 "2021-05-07T13:26:11Z")

</div>

Thank you @darrenjrobinson. Based on your code I was able to put together the following PowerShell code that will work.

```powershell
$uri = 'https://{tenant}.api.identitynow.com/beta/non-employee-sources/{sourceId}/non-employee-bulk-upload'
$accessToken = '{accessToken}'

$inFile = 'C:\users\my_user\Documents\contractors.csv'
$fileName = 'contractors.csv'
$csvBytes = [System.IO.File]::ReadAllBytes($inFile)
$csvText = [System.Text.Encoding]::ASCII.GetString($csvBytes)

$result = Invoke-restmethod -Uri $uri `
                -Method "POST" `
                -Headers @{Authorization = "Bearer $accessToken"} `
                -ContentType "multipart/form-data; boundary=----WebKitFormBoundaryU1hSZTy7cff3WW27" `
                -Body ([System.Text.Encoding]::UTF8.GetBytes("------WebKitFormBoundaryU1hSZTy7cff3WW27$([char]13)$([char]10)Content-Disposition: form-data; name=`"data`"; filename=`"$fileName`"$([char]13)$([char]10)Content-Type: text/csv$([char]13)$([char]10)$([char]13)$([char]10)$($csvText)$([char]13)$([char]10)------WebKitFormBoundaryU1hSZTy7cff3WW27--$([char]13)$([char]10)")) `
                -UseBasicParsing

$result

```

---

<div class="post-metadata">

**Author:** ![darrenjrobinson](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/darrenjrobinson/32/2854_2.png) [@darrenjrobinson](https://developer.sailpoint.com/discuss/u/darrenjrobinson)\
**Post date:** [May 7, 2021, 2:04pm UTC](https://developer.sailpoint.com/discuss/t/nelm-bulk-update-api/495/13 "2021-05-07T14:04:39Z")

</div>

Brilliant. Great to see you got it working 👍🏻

---

<div class="post-metadata">

**Author:** ![justinrhaines](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/justinrhaines/32/16564_2.png) [@justinrhaines](https://developer.sailpoint.com/discuss/u/justinrhaines)\
**Post date:** [May 7, 2021, 2:08pm UTC](https://developer.sailpoint.com/discuss/t/nelm-bulk-update-api/495/14 "2021-05-07T14:08:48Z")

</div>

Excellent, this is working as expected. Thanks everyone for your input!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/sailpoint/original/2X/f/f2136700ed5e3703e0b85e02f6be799dacca7735.png) [@system](https://developer.sailpoint.com/discuss/u/system)\
**Post date:** [July 19, 2023, 2:21pm UTC](https://developer.sailpoint.com/discuss/t/nelm-bulk-update-api/495/15 "2023-07-19T14:21:50Z")

</div>

Closed on July 19, 2023, 2:21pm UTC


