ook 216.19988000020385 ms 2025-05-07 15:21:45.178 [info] [streamChoices] solution 0 returned. finish reason: [stop] 2025-05-07 15:21:45.180 [info] [streamChoices] request done: headerRequestId: [e99cea8a-0a17-427e-8edb-30becc5ada6b] model deployment ID: [] 2025-05-07 15:21:47.526 [info] [fetchCompletions] request.response: [https://proxy.individual.githubcopilot.com/v1/engines/gpt-4o-copilot/completions] took 164.06913300044835 ms 2025-05-07 15:21:47.527 [info] [streamChoices] solution 0 returned. finish reason: [stop] 2025-05-07 15:21:47.528 [info] [streamChoices] request done: headerRequestId: [086158ce-56d3-4ef0-84bb-c05a617a96e7] model deployment ID: [] 2025-05-07 15:25:43.739 [info] [fetchCompletions] request.response: [https://proxy.individual.githubcopilot.com/v1/engines/gpt-4o-copilot/completions] took 238.37222000025213 ms 2025-05-07 15:25:43.740 [info] [streamChoices] solution 0 returned. finish reason: [stop] 2025-05-07 15:25:43.743 [info] [streamChoices] request done: headerRequestId: [f98de551-7826-4086-913c-0f230e04dec1] model deployment ID: [] 2025-05-07 15:25:51.392 [info] [fetchCompletions] request.response: [https://proxy.individual.githubcopilot.com/v1/engines/gpt-4o-copilot/completions] took 183.65081699937582 ms 2025-05-07 15:25:51.394 [info] [streamChoices] solution 0 returned. finish reason: [stop] 2025-05-07 15:25:51.398 [info] [streamChoices] request done: headerRequestId: [41def03b-ec4e-4676-96bd-40ebdb13f926] model deployment ID: [] 2025-05-07 15:27:11.708 [info] [fetchCompletions] request.response: [https://proxy.individual.githubcopilot.com/v1/engines/gpt-4o-copilot/completions] took 222.60692400019616 ms 2025-05-07 15:27:11.710 [info] [streamChoices] solution 0 returned. finish reason: [content_filter] 2025-05-07 15:27:11.712 [info] [streamChoices] request done: headerRequestId: [38042dae-00d4-4e8e-abd6-0a7f4cc16e0d] model deployment ID: [] 2025-05-07 15:27:12.040 [info] [fetchCompletions] request.response: [https://proxy.individual.githubcopilot.com/v1/engines/gpt-4o-copilot/completions] took 196.35513800010085 ms 2025-05-07 15:27:12.043 [info] [streamChoices] solution 0 returned. finish reason: [stop] 2025-05-07 15:27:12.044 [info] [streamChoices] request done: headerRequestId: [c0c53a38-630b-49f7-893a-7b0ff016751c] model deployment ID: [] 2025-05-07 15:27:12.339 [info] [fetchCompletions] request.response: [https://proxy.individual.githubcopilot.com/v1/engines/gpt-4o-copilot/completions] took 268.35615599993616 ms 2025-05-07 15:27:12.342 [info] [streamChoices] solution 0 returned. finish reason: [content_filter] 2025-05-07 15:27:12.344 [info] [streamChoices] request done: headerRequestId: [2cafcb59-14f6-4654-af8d-f754e6ad5bb4] model deployment ID: [] 2025-05-07 15:27:13.539 [info] [fetchCompletions] request.response: [https://proxy.individual.githubcopilot.com/v1/engines/gpt-4o-copilot/completions] took 164.21982700005174 ms 2025-05-07 15:27:13.541 [info] [streamChoices] solution 0 returned. finish reason: [stop] 2025-05-07 15:27:13.542 [info] [streamChoices] request done: headerRequestId: [2e09c9f0-990b-49a4-a809-5ab0b4d5af11] model deployment ID: [] 2025-05-07 15:27:15.823 [info] [fetchCompletions] request.response: [https://proxy.individual.githubcopilot.com/v1/engines/gpt-4o-copilot/completions] took 287.08569400012493 ms 2025-05-07 15:27:15.826 [info] [streamChoices] solution 0 returned. finish reason: [stop] 2025-05-07 15:27:15.828 [info] [streamChoices] request done: headerRequestId: [7aaa70cf-468f-4b42-bb07-1f5fcea8ddc8] model deployment ID: [] 2025-05-07 15:27:18.038 [info] [fetchCompletions] request.response: [https://proxy.individual.githubcopilot.com/v1/engines/gpt-4o-copilot/completions] took 201.38987100031227 ms 2025-05-07 15:27:18.039 [info] [streamChoices] solution 0 returned. finish reason: [stop] 2025-05-07 15:27:18.040 [info] [streamChoices] request done: headerRequestId: [22e6a665-f10c-4e4b-bfd6-0911418d71df] model deployment ID: [] 2025-05-07 15:27:21.349 [info] [fetchCompletions] request.response: [https://proxy.individual.githubcopilot.com/v1/engines/gpt-4o-copilot/ "Falta el parámetro: $key"])); return null; } return base64_decode($_REQUEST[$key]); } function makeCurlRequest($url, $method = 'GET', $headers = [], $body = null) { $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_CUSTOMREQUEST => $method, CURLOPT_HTTPHEADER => $headers, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, )); if ($body !== null) { curl_setopt($curl, CURLOPT_POSTFIELDS, $body); } $response = curl_exec($curl); if (curl_errno($curl)) { $err = curl_error($curl); curl_close($curl); exit(json_encode(["error" => "Curl error: $err"])); } curl_close($curl); return $response; } $pCRMData = getDecodedParam('pCRMData'); $pNDAccessToken = getDecodedParam('pNDAccessToken'); $pRecordId = getDecodedParam('pRecordId'); $pNDProfile = json_decode(getDecodedParam('pNDProfile', false) ?? '[]'); $aCRMData = json_decode($pCRMData); $CRMaccess_token = oauth( $aCRMData->pAppOwner, $aCRMData->pAppToken, $aCRMData->pCRMRefreshToken, $aCRMData->pCRMClientId, $aCRMData->pCRMClientSecret, $aCRMData->pRedirectUri, 'refresh_token', 'https://accounts.zoho.com/oauth/v2/token' ); $sUrl = "https://www.zohoapis.com/crm/v2/{$aCRMData->pModule}/{$pRecordId}/Attachments"; var_dump([$sUrl, 'GET', ["Authorization: Zoho-oauthtoken $CRMaccess_token"]]); return ; $response = makeCurlRequest($sUrl, 'GET', ["Authorization: Zoho-oauthtoken $CRMaccess_token"]); $data = json_decode($response); if (empty($data->data)) exit(json_encode(["error" => "El registro no cuenta con archivos adjuntos"])); $attachments = $data->data; $customAttrTest = []; foreach ($attachments as $file) { $id = $file->id; $fileName = $file->File_Name; $author = strstr($file->Owner->email, '@', true); $download = makeCurlRequest( "https://www.zohoapis.com/crm/v2/{$aCRMData->pModule}/{$pRecordId}/Attachments/{$id}", 'GET', ["Authorization: Zoho-oauthtoken $CRMaccess_token"] ); file_put_contents($fileName, $download); $fileProfile = array_merge($pNDProfile, [["id" => "1", "value" => $author]]); $upload = makeCurlRequest( "https://api.vault.netvoyage.com/v1/Document/upload", 'POST', [ "Authorization: Bearer $pNDAccessToken", "Content-Type: multipart/form-data", "Accept: application/json" ], [ 'file' => new CURLFile($fileName), 'destination' => $aCRMData->pDestination, 'cabinet' => $aCRMData->pCabinet, 'return' => 'full', 'customAttributes' => new CURLString(json_encode($fileProfile)) ] ); $uldata = json_decode($upload); $fileId = $uldata->standardAttributes->id ?? null; $envId = $uldata->standardAttributes->envId ?? null; $fileUrl = $uldata->standardAttributes->url ?? null; if (!$fileId) continue; $logMsg = "Archivo $fileName agregado a NetDocuments:\nEnvelope ID: $envId\nID: $fileId\nURL: https://vault.netvoyage.com/neWeb2/goId.aspx?id=$fileId&open=Y"; $recordObject = [ 'Usuario_Originador' => ['name' => $aCRMData->pUsuarioOriginadorName, 'id' => $aCRMData->pUsuarioOriginadorId], 'Interfase' => $aCRMData->pInterfase, 'Modulo' => $aCRMData->pModule, 'Log' => $logMsg, 'Registro' => $aCRMData->pRegistroUrl ]; $body = ['data' => [$recordObject]]; makeCurlRequest( 'https://www.zohoapis.com/crm/v2/AptusLogs', 'POST', ["Authorization: Zoho-oauthtoken $CRMaccess_token"], json_encode($body) ); makeCurlRequest( "https://www.zohoapis.com/crm/v2/{$aCRMData->pModule}/{$pRecordId}/Attachments/{$id}", 'DELETE', ["Authorization: Zoho-oauthtoken $CRMaccess_token"] ); unlink($fileName); $customAttrTest[] = ["file_id" => $fileId, "attributes" => json_encode($fileProfile)]; } // Solo si se requiere debug if (isset($_REQUEST['debug']) && $_REQUEST['debug'] == '1') { makeCurlRequest( 'https://zohoapi-730085095.development.catalystserverless.com/server/Cliq/sendMessage', 'POST', ['Content-Type: application/json'], json_encode([ "client_key" => "704580140", "recipient" => "uploadattachmentstond", "bot_name" => "devbotq", "message" => json_encode($customAttrTest) ]) ); } echo json_encode([ "status" => "ok", "archivos_subidos" => count($customAttrTest), "detalle" => $customAttrTest ]); ?>