APIs & Integrations

JZhao
Participant

How can I recreate a custom object after delete?

 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
12 Replies 12
JZhao
Participant

How can I recreate a custom object after delete?

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
RMones
Contributor | Platinum Partner
Contributor | Platinum Partner

How can I recreate a custom object after delete?

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
Participant

How can I recreate a custom object after delete?

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 | Platinum Partner
Contributor | Platinum Partner

How can I recreate a custom object after delete?

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

0 Upvotes
JZhao
Participant

How can I recreate a custom object after delete?

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
RMones
Contributor | Platinum Partner
Contributor | Platinum Partner

How can I recreate a custom object after delete?

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
Participant

How can I recreate a custom object after delete?

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 | Platinum Partner
Contributor | Platinum Partner

How can I recreate a custom object after delete?

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
Participant

How can I recreate a custom object after delete?

@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
eliot_martin
Contributor

How can I recreate a custom object after delete?

Did you ever sort this out? I am getting the same response trying to purge a deleted object.

0 Upvotes
mathew_murphy
Participant

How can I recreate a custom object after delete?

I had the same problem, and after some hints from support and some searching and experimenting I managed to work out an answer.

 

You need to perform

DELETE https://api.hubspot.com/crm/v3/schemas/[objectTypeId]/purge

The documentation is (currently) wrong, you can't use the objectType as the parameter for purge. Instead, you need the objectTypeId, which is a value given to you as a property in the JSON data returned when you create the custom schema. It looks like 2-12345678.

 

There seems to be no way to find out what the objectTypeId is once you've deleted the custom schema. The error when you try to create a new schema with the same name as the deleted one doesn't tell you what the objectTypeId is either, which is a bit of a problem.

0 Upvotes
mathew_murphy
Participant

How can I recreate a custom object after delete?

Correction: There is a way to do it without the customObjectId, found here! Phew!

https://api.hubapi.com/crm/v3/schemas/{objectType}?archived=true

Apparently the purge endpoint is deprecated.

0 Upvotes