Question

Update API issue

  • 22 March 2024
  • 3 replies
  • 35 views

Hi!

I’m trying to update my company records using GSID in the endpoint as the key, but then when I include the gsid in the payload I get an error saying that it can’t be updated:

Failed to update a batch of 50 records in Gainsight: {"result":false,"errorCode":"GSOBJ_1010","errorDesc":"Immutable fields such as Gsid cannot be changed. Please re-check your request.","localizedErrorDesc":null,"requestId":"4b28d446-0435-4abf-b94a-e91d82cd4f61","data":null,"message":"gsid cannot be modified since it is an immutable field.","localizedMessage":null}

But in the documentation it says if a field is a key then it isn’t updated. When I tried to match on Name it ended up creating a brand new set of records instead of matching, even though the record names were exactly the same. Here is my request (I’m using Hex). Any help would be appreciated!

 

post_url = "https://vertice.eu.gainsightcloud.com/v1/data/objects/Company?keys=GSID"

gainsight_headers = {

'content-type': 'application/json',

'accesskey': gainsight_api_key

}

 

def update_gainsight_companies(batch_data):

 

data_payload = {

"records": batch_data

}

response = requests.post(post_url, headers=gainsight_headers, data=json.dumps(data_payload))

if response.status_code == 200:

print(f"Successfully updated a batch of {len(batch_data)} records in Gainsight.")

else:

print(f"Failed to update a batch of {len(batch_data)} records in Gainsight: {response.text}")

 

def batch_update_gainsight(missed_spend_df):

 

chunk_size = 50

num_chunks = len(missed_spend_df) // chunk_size + (1 if len(missed_spend_df) % chunk_size else 0)

for i in range(num_chunks):

batch = missed_spend_df.iloc[i*chunk_size:(i+1)*chunk_size]

batch_data = [

{

"Gsid": row['gsid'],

"company_account_id__gc": row['account_id'],

"SaaS_Missed_Spend__gc": row['total_account']

}

for index, row in batch.iterrows()

]

update_gainsight_companies(batch_data)

 

#if hex_scheduled:

batch_update_gainsight(missed_spend)


3 replies

Userlevel 7
Badge +9

Are you possibly using Upsert, rather than Update, somewhere along the way?

Also, any chance you’re using the Insert API rather than the Update API? Your scenario about getting new records rather than updated records when using Name as the key sounds like Gainsight is inserting rather than updating.

Hi Matthew,

I was following the Gainsight documentation here: https://support.gainsight.com/Gainsight_NXT/API_and_Developer_Docs/Company_and_Relationship_API/Company_API_Documentation#:~:text=%7D-,Update,-API

You can see my endpoint here: "https://company.eu.gainsightcloud.com/v1/data/objects/Company?keys=GSID"

By the looks of things, the only differentiator between Insert and Update is the keys at the end of the URL. But is there another way of knowing?

Thanks

Userlevel 7
Badge +9

Hi @adamjustice .

The Method is also different between the Insert API (where it’s POST) and the Update API (where it’s PUT). Any chance that’s a cause, or might you experiment with an adjustment there and see if you get different results?

Reply