# Disable optimize aggregation from a source

**URL:** <https://developer.sailpoint.com/discuss/t/disable-optimize-aggregation-from-a-source/76794>\
**Category:** SHF Discussion and Questions\
**Tags:** apis, sailpoint-identity-security\
**Created:** [August 14, 2024, 4:49pm UTC](https://developer.sailpoint.com/discuss/t/disable-optimize-aggregation-from-a-source/76794 "2024-08-14T16:49:02Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![ts\_fpatterson](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/ts_fpatterson/32/26704_2.png) [@ts\_fpatterson](https://developer.sailpoint.com/discuss/u/ts_fpatterson)\
**Post date:** [August 14, 2024, 4:49pm UTC](https://developer.sailpoint.com/discuss/t/disable-optimize-aggregation-from-a-source/76794/1 "2024-08-14T16:49:03Z")

</div>

It appears that the cc api to disable the optimization on an aggregation has been removed. I believe I received a 401 error.

I tried updating my logic to use the v2024 api, but it is failing with a 500 error.

Any ideas on what is wrong with my python script?

```auto
import requests
import getpass

# Prompt the user to enter the necessary variables
print("Trigger an aggregation for a source with optimization disabled.")
client_id = input("Please enter your client ID: ")
client_secret = getpass.getpass("Please enter your client secret: ")
client = input("Please enter your tenant name (example: acme-sb is what you would enter if the full URL is https://acme-sb.identitynow.com): ")
base_url = f"https://{client}.api.identitynow.com"
source = input("Please enter the Source ID the source you need to aggregate.")
url = f"{base_url}/v2024/sources/{source}/loadAccounts"

# Get an access token
auth_url = f"{base_url}/oauth/token"
auth_data = {
    "grant_type": "client_credentials",
    "client_id": client_id,
    "client_secret": client_secret,
}
auth_response = requests.post(auth_url, data=auth_data)
print(auth_response)

# Extract the access token from the response
access_token = auth_response.json()["access_token"]
#print(access_token)

headers = {
    'Authorization': f'Bearer {access_token}',
    'Accept': 'application/json',
    'Content-Type': 'multipart/form-data',
    'X-SailPoint-Experimental': 'true'
}

payload = '{"disableOptimization": true}'

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

if response.status_code == 200:
    data = response.json()
  
else:
    print(f"Request for sources failed with status code: {response.status_code}")
    print("Response content:", response.text)
    

```

error was

```auto
Trigger an aggregation for a source with optimization disabled.
<Response [200]>
Request for sources failed with status code: 500
Response content: {"messages":[{"localeOrigin":"REQUEST","text":"An internal fault occurred.","locale":"en-US"},{"localeOrigin":"DEFAULT","text":"An internal fault occurred.","locale":"en-US"}],"trackingId":"2c9b753f36464d0c890823093b9c065b","detailCode":"500.0 Internal fault"}

```

---

<div class="post-metadata">

**Author:** ![zachm117](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/zachm117/32/3883_2.png) [@zachm117](https://developer.sailpoint.com/discuss/u/zachm117)\
**Post date:** [August 14, 2024, 4:53pm UTC](https://developer.sailpoint.com/discuss/t/disable-optimize-aggregation-from-a-source/76794/2 "2024-08-14T16:53:51Z")

</div>

Hey Fred,

It looks like that [endpoint](https://developer.sailpoint.com/docs/api/v2024/import-accounts) should be `/v2024/sources/:id/load-accounts`. Note the hyphen between ‘load’ and ‘accounts’, which I don’t see in your code. Can you try adding this and see if it resolves the issue?

Thank you,

- Zach

---

<div class="post-metadata">

**Author:** ![ts\_fpatterson](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/ts_fpatterson/32/26704_2.png) [@ts\_fpatterson](https://developer.sailpoint.com/discuss/u/ts_fpatterson)\
**Post date:** [August 14, 2024, 5:10pm UTC](https://developer.sailpoint.com/discuss/t/disable-optimize-aggregation-from-a-source/76794/3 "2024-08-14T17:10:03Z")

</div>

thanks, I did correct that and still see the same error.

I updated the headers with removing the experimental line, and a few of the others to see if it would change anything, but any change I made still gives the 500 error.

I get a 200 on the authentication, but always the 500 after.

Current logic I’m using is:

```auto
import requests
import getpass

# Prompt the user to enter the necessary variables
print("Trigger an aggregation for a source with optimization disabled.")
client_id = input("Please enter your client ID: ")
client_secret = getpass.getpass("Please enter your client secret: ")
client = input("Please enter your tenant name (example: acme-sb is what you would enter if the full URL is https://acme-sb.identitynow.com): ")
base_url = f"https://{client}.api.identitynow.com"
source = input("Please enter the Source ID the source you need to aggregate.")
url = f"{base_url}/v2024/sources/{source}/load-accounts"

# Get an access token
auth_url = f"{base_url}/oauth/token"
auth_data = {
    "grant_type": "client_credentials",
    "client_id": client_id,
    "client_secret": client_secret,
}
auth_response = requests.post(auth_url, data=auth_data)
print(auth_response)

# Extract the access token from the response
access_token = auth_response.json()["access_token"]
#print(access_token)

headers = {
    'Authorization': f'Bearer {access_token}',
    'Accept': 'application/json',
    'Content-Type': 'multipart/form-data',
    'X-SailPoint-Experimental': 'true'
}

payload = '{"disableOptimization": true}'

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

if response.status_code == 200:
    data = response.json()
  
else:
    print(f"Request for sources failed with status code: {response.status_code}")
    print("Response content:", response.text)
    

```

---

<div class="post-metadata">

**Author:** ![zachm117](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/zachm117/32/3883_2.png) [@zachm117](https://developer.sailpoint.com/discuss/u/zachm117)\
**Post date:** [August 14, 2024, 8:24pm UTC](https://developer.sailpoint.com/discuss/t/disable-optimize-aggregation-from-a-source/76794/4 "2024-08-14T20:24:18Z")

</div>

Did you try removing this header: ‘Content-Type’: ‘multipart/form-data’?

I believe that is only required for aggregating delimited file sources.

Thank you,

- Zach

---

<div class="post-metadata">

**Author:** ![zachm117](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/zachm117/32/3883_2.png) [@zachm117](https://developer.sailpoint.com/discuss/u/zachm117)\
**Post date:** [August 14, 2024, 8:26pm UTC](https://developer.sailpoint.com/discuss/t/disable-optimize-aggregation-from-a-source/76794/5 "2024-08-14T20:26:40Z")

</div>

Alternatively, if you are trying to aggregate a delimited file source, you can leave that header and include the file in the request body.

---

<div class="post-metadata">

**Author:** ![liamkokeeffe](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/liamkokeeffe/32/29279_2.png) [@liamkokeeffe](https://developer.sailpoint.com/discuss/u/liamkokeeffe)\
**Post date:** [August 14, 2024, 8:27pm UTC](https://developer.sailpoint.com/discuss/t/disable-optimize-aggregation-from-a-source/76794/6 "2024-08-14T20:27:34Z")

</div>

Hi Fred,

Could you try updating your payload line to the below format:

```auto
payload = {'disableOptimization': 'true'}

```

Thanks,

Liam

---

<div class="post-metadata">

**Author:** ![awyss](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/awyss/32/37310_2.png) [@awyss](https://developer.sailpoint.com/discuss/u/awyss)\
**Post date:** [August 14, 2024, 8:28pm UTC](https://developer.sailpoint.com/discuss/t/disable-optimize-aggregation-from-a-source/76794/7 "2024-08-14T20:28:24Z")

</div>

Try this from Colin a few weeks ago and see if this helps.

```auto
curl -L 'https://sailpoint.api.identitynow.com/beta/sources/:id/load-accounts' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer <TOKEN>' \
-d 'disableOptimization=true'

```

> [@POST /api/source/loadAccounts](https://developer.sailpoint.com/discuss/t/post-api-source-loadaccounts/20515/190):
>
> The API specification for the [beta load accounts endpoint](https://developer.sailpoint.com/docs/api/beta/import-accounts) has been updated to include the x-www-form-urlencoded content type. An example cURL command using this new content type would be as follows: curl -L 'https://sailpoint.api.identitynow.com/beta/sources/:id/load-accounts' \ -H 'Content-Type: application/x-www-form-urlencoded' \ -H 'Accept: application/json' \ -H 'Authorization: Bearer \<TOKEN\>' \ -d 'disableOptimization=true'

---

<div class="post-metadata">

**Author:** ![neeraj99](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/neeraj99/32/14001_2.png) [@neeraj99](https://developer.sailpoint.com/discuss/u/neeraj99)\
**Post date:** [August 15, 2024, 6:44am UTC](https://developer.sailpoint.com/discuss/t/disable-optimize-aggregation-from-a-source/76794/8 "2024-08-15T06:44:40Z")

</div>

@ts_fpatterson

I see that you are using v2024 experimental API’s and there i do not see `application/x-www-form-urlencoded` as the content type listed. But when i look at beta api’s its listed over there so maybe you can change the API endpoint to beta

` https://{{tenant}}.api.identitynow.com/beta/sources/:id/load-accounts`

The Content-Type should be “`application/x-www-form-urlencoded`” if it is connected source.  
In case of CSV, it should be “`multipart/form-data`”

Hope this helps…

---

<div class="post-metadata">

**Author:** ![ts\_fpatterson](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/ts_fpatterson/32/26704_2.png) [@ts\_fpatterson](https://developer.sailpoint.com/discuss/u/ts_fpatterson)\
**Post date:** [August 15, 2024, 10:57am UTC](https://developer.sailpoint.com/discuss/t/disable-optimize-aggregation-from-a-source/76794/9 "2024-08-15T10:57:20Z")

</div>

Thanks for all of the help.

I was able to get the Python code working using the beta api and fixing the content-Type as well as fixing the payload.

Feel free to use this logic

```auto
import requests
import getpass

# Prompt the user to enter the necessary variables
print("Trigger an aggregation for a source with optimization disabled.")
client_id = input("Please enter your client ID: ")
client_secret = getpass.getpass("Please enter your client secret: ")
client = input("Please enter your tenant name (example: acme-sb is what you would enter if the full URL is https://acme-sb.identitynow.com): ")
base_url = f"https://{client}.api.identitynow.com"
source = input("Please enter the Source ID the source you need to aggregate.")
url = f"{base_url}/beta/sources/{source}/load-accounts"

# Get an access token
auth_url = f"{base_url}/oauth/token"
auth_data = {
    "grant_type": "client_credentials",
    "client_id": client_id,
    "client_secret": client_secret,
}
auth_response = requests.post(auth_url, data=auth_data)
print(auth_response)

# Extract the access token from the response
access_token = auth_response.json()["access_token"]
#print(access_token)

headers = {
    'Authorization': f'Bearer {access_token}',
    'Accept': 'application/json',
    'Content-Type': 'application/x-www-form-urlencoded'
}

payload = {"disableOptimization": True}

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

if response.status_code == 200:
    data = response.json()
  
else:
    print(f"Request for sources failed with status code: {response.status_code}")
    print("Response content:", response.text)
    

```

---

<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:** [October 14, 2024, 10:58am UTC](https://developer.sailpoint.com/discuss/t/disable-optimize-aggregation-from-a-source/76794/10 "2024-10-14T10:58:00Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
