Closed stphnlngdncoding closed 1 year ago
Hi @stphnlngdncoding ,
Thanks for raising this question.
To correctly migrate properties from one environment to another you have to do following steps:
Regarding errors:
Here is code sample that might with conversion implementation:
const enumFromValue = <T extends Record<string, any>>(val: string, _enum: T) => {
const enumName = (Object.keys(_enum) as Array<keyof T>).find(k => _enum[k] === val)
if (!enumName) {
throw Error(`Cannot find enum value for ${val}`)
}
return _enum[enumName]
}
const client = new Client( {apiKey: '123'});
const result = await client.crm.properties.coreApi.getAll('deals')
const propertiesToCreate: propertiesModels.PropertyCreate[] = result.body.results
.filter(property => !property.modificationMetadata.readOnlyDefinition)
.map(property => (
{
...property,
name: `${property.name}_${new Date().getTime()}`,
label: property.label,
type: property.type === 'bool'? propertiesModels.PropertyCreate.TypeEnum.Enumeration : enumFromValue(property.type, propertiesModels.PropertyCreate.TypeEnum),
fieldType: enumFromValue(property.fieldType, propertiesModels.PropertyCreate.FieldTypeEnum),
groupName: property.groupName
}
))
await client.crm.properties.batchApi.create('deals', {
inputs: propertiesToCreate
})
bool
which is not supported on new API. To make it work, please change bool
to enumeration
I'll create an issue in HubSpot about this and keep you posted on any updates.
Kind Regards, Andrii
I am attempting to bulk-read properties from one hubspot environment to the other with the code below:
However, it appears that the type
Property
which is returned from getAll is not compatible with the data that the inputs is expecting, namelyPropertyCreate
. This is the typescript error that I recieve:And if I try to use
.apiRequest
with the following signature:I recieve the following error:
Is there any way to work around this?