Symptom
while trying to upsert using Odata API , we get the following error message
"message" : "Single-valued key cannot be represented as a complex value"
Environment
Successfactors
Reproducing the Issue
In this KBA we are using a sample entity, to reproduce the issue ; please do note this error could be for other entity as well.
Trigger this odata query from any odata rest api client
odata request :
{"__metadata":
{"uri":"Background_Education(userId='1234')"}
,"degree":"567","endDate":"/Date(1388880000000)/","major":"Engineer","school":"test School","startDate":"/Date(1325721600000)/"}
odata response :
{
"d" : [
{ "key" : null, "status" : "ERROR", "editStatus" : null, "message" : "Single-valued key cannot be represented as a complex value", "index" : 0, "httpCode" : 500, "inlineResults" : null }
]
}
Cause
This is because, the response is not supplying the required business key to for further execution/upserting of values
Resolution
- Please trigger the following query - https://apiURL/odata/V2/entityName/$metadata
- apiURL - this URL is specific to the DC you are hosted in
- entityName - the entity you are trying to upsert the data to
- ex : for DC2 - https://apisuccessfactors.eu/odata/V2/Background_Education/$metadata
- From the extracted metadata,please do check for the similar snippet
<EntityType Name="Background_Education">
<Key>
<PropertyRef Name="backgroundElementId"/>
<PropertyRef Name="userId"/>
</Key>
- From the snippet we could see that, backgroundElemetId and userId is the key - hence these two field should be a part of response uri.
- So a well written response would be
{"__metadata":
{"uri":"Background_Education(userId='1234',backgroundElementId='abc')"}
,"degree":"567","endDate":"/Date(1388880000000)/","major":"Engineer","school":"test School","startDate":"/Date(1325721600000)/"}
Keywords
Single-valued key cannot be represented as a complex value , upsert failure , KBA , LOD-SF-INT-API , API & Adhoc API Framework , Problem