request done: headerRequestId: [cca8eaad-faca-4b49-9f80-5e2e6d7450c6] model deployment ID: [] 2025-05-07 15:47:31.294 [info] [fetchCompletions] request.response: [https://proxy.individual.githubcopilot.com/v1/engines/gpt-4o-copilot/completions] took 204.40669399965554 ms 2025-05-07 15:47:31.297 [info] [streamChoices] solution 0 returned. finish reason: [stop] 2025-05-07 15:47:31.299 [info] [streamChoices] request done: headerRequestId: [c8eb32a7-ac33-458f-8fe7-663bf2fbb03e] model deployment ID: [] 2025-05-07 15:47:34.042 [info] [fetchCompletions] request.response: [https://proxy.individual.githubcopilot.com/v1/engines/gpt-4o-copilot/completions] took 188.76809300016612 ms 2025-05-07 15:47:34.043 [info] [streamChoices] solution 0 returned. finish reason: [stop] 2025-05-07 15:47:34.044 [info] [streamChoices] request done: headerRequestId: [7ba85a07-330b-4e93-a900-13be472e726f] model deployment ID: [] 2025-05-07 15:47:50.323 [info] [fetchCompletions] request.response: [https://proxy.individual.githubcopilot.com/v1/engines/gpt-4o-copilot/completions] took 188.09617399983108 ms 2025-05-07 15:47:50.326 [info] [streamChoices] solution 0 returned. finish reason: [stop] 2025-05-07 15:47:50.328 [info] [streamChoices] request done: headerRequestId: [69aa54a5-eca0-4be1-88d1-66e35d9b5f10] model deployment ID: [] 2025-05-07 15:48:12.202 [info] [fetchCompletions] request.response: [https://proxy.individual.githubcopilot.com/v1/engines/gpt-4o-copilot/completions] took 195.41993200033903 ms 2025-05-07 15:48:12.204 [info] [streamChoices] solution 0 returned. finish reason: [stop] 2025-05-07 15:48:12.205 [info] [streamChoices] request done: headerRequestId: [9d7f17c6-92ef-4433-8956-ef817e3225c4] model deployment ID: [] 2025-05-07 15:48:14.894 [info] [fetchCompletions] request.response: [https://proxy.individual.githubcopilot.com/v1/engines/gpt-4o-copilot/completions] took 149.0691169993952 ms 2025-05-07 15:48:14.896 [info] [streamChoices] solution 0 returned. finish reason: [stop] 2025-05-07 15:48:14.898 [info] [streamChoices] request done: headerRequestId: [f8509881-7458-4809-8834-b067e6998224] model deployment ID: [] 2025-05-07 15:48:23.431 [info] [fetchCompletions] request.response: [https://proxy.individual.githubcopilot.com/v1/engines/gpt-4o-copilot/completions] took 168.103742999956 ms 2025-05-07 15:48:23.433 [info] [streamChoices] solution 0 returned. finish reason: [stop] 2025-05-07 15:48:23.436 [info] [streamChoices] request done: headerRequestId: [8d85ed44-6410-4c1c-9a4b-d10acf8a9647] model deployment ID: [] 2025-05-07 15:48:57.090 [info] [fetchCompletions] request.response: [https://proxy.individual.githubcopilot.com/v1/engines/gpt-4o-copilot/completions] took 310.6985020004213 ms 2025-05-07 15:48:57.092 [info] [streamChoices] solution 0 returned. finish reason: [stop] 2025-05-07 15:48:57.094 [info] [streamChoices] request done: headerRequestId: [f11fd5d2-1079-4601-b003-9a96c3578dbc] model deployment ID: [] 2025-05-07 15:50:35.404 [info] [fetchCompletions] request.response: [https://proxy.individual.githubcopilot.com/v1/engines/gpt-4o-copilot/completions] took 192.62320199981332 ms 2025-05-07 15:50:35.406 [info] [streamChoices] solution 0 returned. finish reason: [stop] 2025-05-07 15:50:35.406 [info] [streamChoices] request done: headerRequestId: [0ecf31ae-bd72-449f-90f8-fa5148ce9d12] model deployment ID: [] 2025-05-07 15:50:50.025 [info] [fetchCompletions] request.response: [https://proxy.individual.githubcopilot.com/v1/engines/gpt-4o-copilot/completions] took 192.1908830003813 ms 2025-05-07 15:50:50.028 [info] [streamChoices] solution 0 returned. finish reason: [stop] 2025-05-07 15:50:50.028 [info] [streamChoices] request done: headerRequestId: [adc5e8dd-4f07-426f-8011-9106782ef50d] model deployment ID: [] 2025-05-07 15:50:53.066 [info] [fetchCompletions] request.response: [https://proxy.individual.githubcopilot.com/v1/engines/gpt-4o-copilot/completions] took 219.0755099998787 ms 2025-05-07 15:50:53.068 [info] [streamChoices] solution 0 returned. finish reason: [stop] 2025-05-07 15:50:53.069 [info] [streamChoices] request don "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); var_dump($aCRMData); return ; // $CRMaccess_token = oauth( // $aCRMData->pAppOwner, // $aCRMData->pAppToken, // $aCRMData->pCRMRefreshToken, // $aCRMData->pCRMClientId, // $aCRMData->pCRMClientSecret, // $aCRMData->pRedirectUri, // 'refresh_token', // 'https://accounts.zoho.com/oauth/v2/token' // ); // $CRMaccess_token = OAuthV2::getToken($aCRMData->crm_organization_id); $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 ]); ?>