How can I recreate a custom object after delete?

JZhao
Member

 I created a custom object but deleted it. After that I try to create it again with different associations, I got below error. It says "p8013920_device" already exists. I already deleted it and I can't find it in my dashboard. Why do I get this error message?

 

```

{
"status": "error",
"message": "p8013920_device already exists",
"correlationId": "aa470271-83ba-44c5-b41c-95e7189220f6",
"context": {
"name": [
"p8013920_device"
]
},
"category": "OBJECT_ALREADY_EXISTS",
"subCategory": "InboundDbObjectTypeError.OBJECT_TYPE_ALREADY_EXIST"
}
```
0 Upvotes
9 Replies 9
RMones
Contributor

Hi @JZhao ,

 

After you delete, you will need to purge to fully remove the schema:

 

 

/crm-object-schemas/v3/schemas/{objectType}/purge

 

Greets,

 

Ronald

 

JZhao
Member

@RMones could you send me the link for this API doc? I tried but got an error not sure what I did wrong

 

{
"status": "error",
"message": "Unable to infer object type from: p8013920_device",
"correlationId": "a6b82746-f3a9-4167-b0cf-8d3c7de80e9c"
}
0 Upvotes
RMones
Contributor

Hi @JZhao 

 

https://developers.hubspot.com/docs/api/crm/crm-custom-objects

You can only delete a custom object after all object instances of that type are deleted. To delete a custom object, use: 
DELETE https://api.hubapi.com/crm/v3/schemas/{objectType}.
 If you need to create a new custom object with the same name as the deleted object, you must hard delete the schema by DELETE https://api.hubapi.com/crm/v3/schemas/{objectType}?archived=true


There are two endpoints:

DELETE /crm/v3/schemas/{objectType}/purge
DELETE /crm/v3/schemas/{objectType}

 

I used the NodeJS library of Hubspot and there I have to use to different functions:

hubspotClient.crm.schemas.coreApi.archive(fullyQualifiedName) where fullyQualifiedName = p99688696_car in the Cars Examle in the documentation
hubspotClient.crm.schemas.defaultApi.purge(objectTypeId) where objectTypeId = 2-529881 in the Cars Examle in the documentation;

 

Greets Ronald

JZhao
Member

I tried to run purge API but it returns this error.  Is the object type mean object id? if not what object type I should put in the request?

 

 

{
"status": "error",
"message": "Unable to infer object type from: p8013920_device",
"correlationId": "e78713cc-ead4-4491-a33d-505deabbf1a0"
}
0 Upvotes
RMones
Contributor

The ObjectTypeId is returned with the call when you create a custom object.

Checkout the docmentation:

 

https://developers.hubspot.com/docs/api/crm/crm-custom-objects

 

and search for Fetching Object Schema.

JZhao
Member

Could you give me some guidence on this? My project is completed blocked since I am not able to create a custom object and I am not able to delete the object either, so that I am not able to create the object.

 

when I create a object, I get this error:

 

{
"status": "error",
"message": "p8013920_device already exists",
"correlationId": "03487491-b106-4044-b72c-279e84fbfd29",
"context": {
"name": [
"p8013920_device"
]
},
"category": "OBJECT_ALREADY_EXISTS",
"subCategory": "InboundDbObjectTypeError.OBJECT_TYPE_ALREADY_EXIST"
}
 
when I purge the deleted object, I got this error:
 
{
"status": "error",
"message": "Couldn't find soft-deleted object type(s) for: ObjectTypeId{metaTypeId=2, innerId=1435617}",
"correlationId": "cb539a7b-3a7a-4cc1-b9df-3057948421f5",
"category": "VALIDATION_ERROR"
}
 
when I delete the with "archived=true" parameter, I get this error.
 
{
"status": "error",
"message": "Invalid object or event type id: 2-1435617",
"correlationId": "f8ccc31f-48b0-4854-abdb-3006c575b3d8"
}
0 Upvotes
RMones
Contributor

How do you get the ObjectId? Had you saved it? It looks you are using the wrong objectId

0 Upvotes
JZhao
Member

I got the ID when I run get schema with archived=true. Then I tried to delete/purge it but both failed. After that I can't get the ID from `get` anymore. So the question now is how to get and delete the old object?

0 Upvotes
JZhao
Member

I didn't save the object id when I delete the custom object. What I can get is when I recreate the object, I see this output:

 

{
"status": "error",
"message": "p8013920_device already exists",
"correlationId": "90cbbd01-3715-4424-9b98-5b196c525470",
"context": {
"name": [
"p8013920_device"
]
},
"category": "OBJECT_ALREADY_EXISTS",
"subCategory": "InboundDbObjectTypeError.OBJECT_TYPE_ALREADY_EXIST"
}
 
Is `p8013920_device` the object type id? If not, how can I get the object type id?
0 Upvotes