I am trying to copy Companies
inside BIM 360 from one account (Source) to another account (Target). The following code creates a Company inside of the Target account with the same properties as the Source account.
dynamic createdTargetCompany = await Autodesk.Forge.Client.Configuration.Default.ApiClient.CallApiAsync(
"https://developer.api.autodesk.com/hq/v1/accounts/" + targetAccountId + "/companies",
Method.POST,
new Dictionary<string, string>(),
Deserialize.DeserializeObject(sourceCompanyInfo.Content, "Company"),
targetHeaderParams,
new Dictionary<string, string>(),
new Dictionary<string, FileParameter>(),
new Dictionary<string, string>(),
"application/json");
The createdTargetCompany
variable contains status code InterServerError
with the following message:
"{\"code\":2000,\"message\":\"ERROR: duplicate key value violates unique constraint \\"companies_pkey\\"\nDETAIL: Key (id)=(15bf4765-73b8-4940-aec4-0bcbeeec2bae) already exists.\n\"}"
I am unsure what the DETAIL: Key (id)
is. Any ideas what's causing this and how to fix it?
From the code I posted in the question above, the Deserialize.DeserializeObject(sourceCompanyInfo.Content, "Company"),
method now no longer gets the Source's Account Id and Company Id. Removing this feature now creates the Companies in the Target account.
Many thanks to the comments posted regarding this issue.