APIs & Integrations

OLicorn
Membro

Creation dynamic list : filter branch type error 'ASSOCIATION' expected instead of 'OR'

Hi everyone,

For one of my projects, I need to create a dynamic contact list via the API. I've used the API to develop my function, but for some reason the Api response returns an exception.
I get an error, but my list has been well created in the hubspot backoffice.

My project is on symfony
I'm using the hubspot/api-client 11.3

And my function code is :

 

public function createList($type, $year)
	{
		$listName = '[my-list] ' . $type['name'] . ' ' . $year;

		// Manually create the filter structure
		$filter = [
			'filterType' => 'PROPERTY',
			'property' => $type['slug'],
			'operation' => [
				'operationType' => 'STRING',
				'operator' => 'IS_EQUAL_TO',  
				'value' => $year
			]
		];

		// Create the filter branch
		$filterBranch = [
			'filterBranchOperator' => 'OR',
			'filterBranchType' => 'OR',
			'filterBranches' => [
				[
					'filterBranchOperator' => 'AND',
					'filterBranchType' => 'AND',
					'filters' => [$filter]
				]
			],
			'filters' => []
		];

		// Create the ListCreateRequest
		$listCreateRequest = new ListCreateRequest();
		$listCreateRequest->setName($listName);
		$listCreateRequest->setProcessingType('DYNAMIC');
		$listCreateRequest->setFilterBranch($filterBranch);
		$listCreateRequest->setObjectTypeId('0-1'); 

		try {
			$apiResponse = $this->hubspot->crm()->lists()->listsApi()->create($listCreateRequest);
			return $apiResponse;
		} catch (\Exception $e) {
			$errorMessage = "Error creating list: " . $e->getMessage();
			return $errorMessage;
		}
	}

 


My property type["slug"] exist.

When I execute the function I get the error :
Error creating list: Invalid value 'OR' for 'filter_branch_type', must be one of 'ASSOCIATION

I try my best to change the filter_branch_type to ASSOCIATION, but then impossible to create my list.

So for the moment I'm ignoring the error, which doesn't prevent the list from being created.

Thank you for your feedback

0 Avaliação positiva
3 Respostas 3
OLicorn
Membro

Creation dynamic list : filter branch type error 'ASSOCIATION' expected instead of 'OR'

Hi Jaycee, and thank you for your kind response.
I used the endpoint to make your request.
the API returns :
hubspot-list.jpg

So I executed the request in Postman, and this is what I get
postmanid.png

The list exist well, but as you suggest the structure for filter_branch_type seems not to appear.
This is surprising because the filter does exist on the list.
filtre-in-list.png
I hope this helps

Cheers

0 Avaliação positiva
Jaycee_Lewis
Gerente da Comunidade
Gerente da Comunidade

Creation dynamic list : filter branch type error 'ASSOCIATION' expected instead of 'OR'

I lied 😊 I do have one request. Can you make a request to the `GET/crm/v3/lists/{listId}` endpoint for the list that you created that threw the error, please? The structure for filter_branch_type should come back in the response. 

 

Thank you very much @OLicorn 🙌 — Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

0 Avaliação positiva
Jaycee_Lewis
Gerente da Comunidade
Gerente da Comunidade

Creation dynamic list : filter branch type error 'ASSOCIATION' expected instead of 'OR'

Hey, @OLicorn 👋 Thanks for sharing this. That definitely sounds unexpected. Looking at the documentation for Filter Branches, it indicates you should use the approach that's in your example — using `AND` or `OR` for `filter_branch_type`. I'm going to set up a quick test to try to reproduce the error and then track down the team that is the endpoint owner. If I have additional questions or any follow up, I'll post here and tag you in the reply.

 

Talk soon! — Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

0 Avaliação positiva