I am using hubspot api to update the value of lifecycle stage of a contact. The value can be changed to any other value in the hubspot crm. But when I am using the api to do so, I can change the value of the lifecycle stage to a higher stage say, from a Subscriber to Lead, as Subscriber is lower in rank than Lead. But when I try to change the value from Lead to Subscriber using the api, it doesn't do so. There is no error too. I am not sure if it is a bug with the api or there is some restriction to do so.
The code for my api:
def update_contact_lifecycle_stage(request , *args):
try:
api_client = HubSpot(access_token=HUBSPOT_API_KEY)
#get this from params
contact_email = "[email protected]"
filter_query = { "propertyName": 'email', "operator": 'EQ', "value": contact_email }
filterGroup = {
"filters" : [filter_query]
}
search_request = PublicObjectSearchRequest(
filter_groups= [filterGroup],
properties=['vid']
)
response = api_client.crm.contacts.search_api.do_search(public_object_search_request=search_request)
contacts = response.results
if contacts:
contact_vid = str(contacts[0].id)
#Get this from params
new_lifecycle_stage = "subscriber"
contact_update = {
"lifecyclestage": new_lifecycle_stage
}
simple_public_object_input = SimplePublicObjectInput(
properties=contact_update)
try:
api_response = api_client.crm.contacts.basic_api.update(
contact_vid,
simple_public_object_input=simple_public_object_input
)
except ApiException as e:
print(f"HubSpot API error: {e}")
except Exception as e:
print(f"An error occurred: {e}")