500 Internal error when importing SP config

Hello Experts,

We are trying to use the SP config API methods to export/import objects to new IdentityNow environments. We are able to do it using postman but when we use a python script it doesn’t matter how we send the json file we always get a

{
  "messages": [
    {
      "locale": "en-US",
      "text": "An internal fault occurred.",
      "localeOrigin": "REQUEST"
    },
    {
      "locale": "en-US",
      "text": "An internal fault occurred.",
      "localeOrigin": "DEFAULT"
    }
  ],
  "detailCode": "500.0 Internal fault",
  "trackingId": "23f069582f30483b9d4f61887a88bbdf"
}

The request we are doing is:


headers = {
  'Content-Type': 'multipart/form-data',
  'Accept': 'application/json',
  'Authorization': 'Bearer ' + tokenSB['access_token']
}
payload={'data': ('exportimportResult.json',open('exportimportResult.json'))}
response2 = requests.request("POST", importConfigURL, headers=headers, verify=False, files=payload)

Based on the documentation, we are sending the json file as expected (sp-config-import | SailPoint Developer Community).

Please, have anyone face the same issue? any idea about what’s the root of the error?

Regards,
Beatriz.

1 Like

The example python code given in the API spec doesn’t appear to be correct for a multipart/form-data upload. Here is the code I generated from Postman.

import requests

url = "https://<tenant>.api.identitynow.com/beta/sp-config/import"

payload={}
files=[
  ('data',('export.json',open('export.json','rb'),'application/json'))
]
headers = {
  'Authorization': 'Bearer <token>'
}

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

print(response.text)

I have submitted an issue to fix the spec example.

We are trying to do that now and experiencing the same error. Is there a work around for this at this time?

Yes, try this:

importConfigURL = baseUrl+“/beta/sp-config/import?preview=false”

with open(‘exportimportResult.json’, ‘w’, encoding=‘utf-8’) as my_file:
my_file.write(json.dumps(exportimportResult))

files=[
(‘data’,(‘export.json’,open(‘exportimportResult.json’,‘rb’),‘application/json’))
]

headers = {
‘Authorization’: 'Bearer ’ + token[‘access_token’]
}

response = requests.request(“POST”, importConfigURL, headers=headers, verify=False, files=files)

Cheers!

1 Like