Hi Jaycee, thank yoo for your response, here It is
The program querys a database, the query returns the field ‘CARTERA’ and this field indicates the deal_stage that mus bew updated on the pipeline:
$client = Factory::createWithAccessToken(TOKEN_HUBSPOT);
$i = 0;
while ($arr_Cartera = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
if ($arr_Cartera[‘CARTERA’] != NULL) {
$paramsRO = array(
‘where’ => ‘t.post_title = "’ . $arr_Cartera[‘CEDULA’] . ‘" and t.post_status = “private”’
);
$obj_registro_obligacion = pods(‘registro_obligacion’, $paramsRO);
// Here the program gets and invoice number
if (!empty($obj_registro_obligacion->display(‘ref_cuota_inicial’))) {
$sql = " select reb.impcob VALOR_PAGO
from talu_rebut reb
where
reb.refreb = ‘" . $obj_registro_obligacion->display(‘ref_cuota_inicial’) . "’";
$result = consultar_bd_uxxi($sql);
// Here the program querys antoher database to check if the invoice is already paid
while (oci_fetch($result)) {
$valor_pago = oci_result($result, ‘VALOR_PAGO’);
if(!empty($valor_pago) && $valor_pago > 0){
$params = array(
‘where’ => “documento_identidad.meta_value = '” . $arr_Cartera[‘CEDULA’] . “’ and t.post_status = ‘private’”
);
$obj_Admitido = pods(“admitido”, $params);
$id_DealHubspot = $obj_Admitido->display(“deal_id_hubspot”);
// Here the program obtains the deal_id for that user
if (isset($id_DealHubspot)) {
$properties = [
“dealstage” => $arr_Cartera[‘CARTERA’],
“pipeline” => 9821569 // Gestión de cartera
];
// Here the program begins the construccion of the batch
$x = ‘simplePublicObjectBatchInput’.$i;
$$x = new SimplePublicObjectBatchInput([
‘properties’ => $properties,
‘id’ => $id_DealHubspot
]);
$i++;
}
}
}
}
}
else {
// If ‘CARTERA’ is NULL the program breaks the loop
break;
}
}
// Here the program creates an array of BatchInput Objects
for($j=0; $j<=$i; $j++){
$arr_Updates[$j] = ${‘simplePublicObjectBatchInput’.$j};
}
$obj_LoteUpdate = new BatchInputSimplePublicObjectBatchInput([
‘inputs’ => [],
]);
$obj_LoteUpdate->setInputs($arr_Updates);
try {
$apiResponse = $client->crm()->deals()->batchApi()->update($obj_LoteUpdate);
var_dump($apiResponse);
} catch (ApiException $e) {
// Here occurs the 500 internal server error exception
guardar_log(‘Gestión de cartera’, 'Fallo al reportar la cartera en Hubspot: Exception when calling basic_api->update: ’ . $e->getMessage(), basename($_SERVER[‘PHP_SELF’]), false);
}