APIs & Integrations

IParsons
Participante

Error when posting to multiple checkbox contact field via Properties API

resolver

I'm attempting to post to two multiple checkbox fields using the Properties API (see my previous question here).

 

When I run the below script as part of my full contacts update script, I am getting a validation error. The option I am trying to save to the multiple checkbox does not exist: "message":"b0e3726b-7fed-4e61-8e66-702a45416813 was not one of the allowed options.

 

I'm pretty sure I'm missing something obvious 🙂 

 

<?php



$allTeamGuids = array();


function addTeamGUIDtoGUIDProperties($guids){

    //update properties
    //PUT /properties/v1/contacts/properties/named/:property_name

    $properties = array('active_team_guids', 'allteamguids');

    foreach($properties as $property){

        $update_property_url = 'https://api.hubapi.com/crm/v3/properties/contacts/'.$property.'?hapikey=' . HS_API_KEY;

        $ch = curl_init();


        $update_property_json = array(

            "name" => $property,
            "groupName" => "app_data",
            "description" => "",
            "fieldType" => "checkbox",
            "formField" => false,
            "type" => "enumeration",
            "displayOrder" => '',
            "label" => $property,
            'options' => array(
            )
        );

        foreach($guids as $guid) {

            array_push($update_property_json['options'], $guid);
        }

        $update_property_json = json_encode($update_property_json);

        /* echo '<pre>';
        print_r( $update_property_json );
        echo '</pre>'; */

        curl_setopt_array($ch, array(
            CURLOPT_URL => $update_property_url,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => "",
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 30,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => "PUT",
            CURLOPT_POSTFIELDS => $update_property_json,
            CURLOPT_HTTPHEADER => array('Content-Type: application/json', 'Content-Length: ' . strlen($update_property_json)),
          ));

          $response = curl_exec($ch);
          $err = curl_error($ch);
          
          curl_close($ch);
          
          if ($err) {
            echo "cURL Error #:" . $err;
          } else {
            echo $response;
          }


    }

    

}

$ch = curl_init();

$url = $base_url.'/Analytics/Teams?FromDate='.$fromDate;

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','X-API-KEY: '.$client_api_key));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

try{

    $response = curl_exec($ch);

    /* echo '<pre>';
    print_r( json_decode($response, true));
    echo '</pre>'; */

    $teams = json_decode($response, true);
    foreach((array) $teams as $team){
        $guid = array();
        $guid['label'] = $team['guid'];
        $guid['value'] = $team['guid'];
            
        array_push($allTeamGuids, $guid);
    }

    addTeamGUIDtoGUIDProperties($allTeamGuids);

} catch(Exception $e){
	die('Error');
}

 

0 Me gusta
1 Soluciones aceptada
MichaelC
Solución
Guía | Partner
Guía | Partner

Error when posting to multiple checkbox contact field via Properties API

resolver

@IParsons 

 

Have you tried using PATCH instead of PUT when updating a property?

 

See documentation here: https://developers.hubspot.com/docs/api/crm/properties

 



Need further help with integrations or business development?



Want to help me?

Go to the following links and read through the ideas. If you like them - give the idea an upvote

Upvote the following ideas:

Ver la solución en mensaje original publicado

3 Respuestas 3
MichaelC
Solución
Guía | Partner
Guía | Partner

Error when posting to multiple checkbox contact field via Properties API

resolver

@IParsons 

 

Have you tried using PATCH instead of PUT when updating a property?

 

See documentation here: https://developers.hubspot.com/docs/api/crm/properties

 



Need further help with integrations or business development?



Want to help me?

Go to the following links and read through the ideas. If you like them - give the idea an upvote

Upvote the following ideas:

IParsons
Participante

Error when posting to multiple checkbox contact field via Properties API

resolver

Thanks, @MichaelC, my script ran perfectly - 200s all the way. 

dennisedson
Equipo de producto de HubSpot
Equipo de producto de HubSpot

Error when posting to multiple checkbox contact field via Properties API

resolver

@IParsons 👋

Throwing @MichaelC at this.  He is a pretty smart fellow 😀

0 Me gusta