Author |
|
festusngor Newbie
Joined: 10 April 2018 Location: United Kingdom
Online Status: Offline Posts: 20
|
Posted: 10 April 2018 at 7:14am | IP Logged
|
|
|
I keep getting an ErrorCode 102 when trying to get user's list of folders in Web API. I can authenticate the user only but can't get mail folders. This is my error log below
05:31.68][b9facea3] API: Core::Login
[14:05:31.70][b9facea3] Execute subscription: AdminAuth::onLogin
[14:05:31.71][b9facea3] Execute subscription: Mail::onLogin
[14:05:31.78][b9facea3] IMAP[NOTE]: Start connection to "ssl://imap.gmail.com:993"
[14:05:31.85][b9facea3] IMAP[DATA]: < * OK Gimap ready for requests from 94.126.47.167 a25mb32068621edb\r\n
[14:05:31.86][b9facea3] IMAP[DATA]: > TAG1 CAPABILITY\r\n
[14:05:31.89][b9facea3] IMAP[DATA]: < * CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 XYZZY SASL-IR AUTH=XOAUTH2 AUTH=PLAIN AUTH=PLAIN-CLIENTTOKEN AUTH=OAUTHBEARER AUTH=XOAUTH\r\n
[14:05:31.89][b9facea3] IMAP[DATA]: < TAG1 OK Thats all she wrote! a25mb32068621edb\r\n
[14:05:31.90][b9facea3] IMAP[SECURE]: > TAG2 LOGIN "ngor.tester@gmail.com" "********"\r\n
[14:05:32.28][b9facea3] IMAP[DATA]: < * CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA ID XLIST CHILDREN X-GM-EXT-1 UIDPLUS COMPRESS=DEFLATE ENABLE MOVE CONDSTORE ESEARCH UTF8=ACCEPT LIST-EXTENDED LIST-STATUS LITERAL- SPECIAL-USE APPENDLIMIT=35651584\r\n
[14:05:32.29][b9facea3] IMAP[DATA]: < TAG2 OK ngor.tester@gmail.com authenticated (Success)\r\n
[14:05:32.34][b9facea3] INFO[MEMORY]: Memory peak usage: 10MB
[14:05:32.35][b9facea3] INFO[TIME]: Time delta: 1523369132.3479
[14:05:32.35][b9facea3] IMAP[DATA]: > TAG3 LOGOUT\r\n
[14:05:32.49][b9facea3] IMAP[DATA]: < * BYE LOGOUT Requested\r\n
[14:05:32.49][b9facea3] IMAP[DATA]: < TAG3 OK 73 good day (Success)\r\n
[14:05:32.49][b9facea3] IMAP[NOTE]: Disconnected from "ssl://imap.gmail.com:993" (success)
[14:05:32.71][fe438d6e] [POST(4)][ip:::1] /?/Api/
[14:05:32.71][fe438d6e] POST > [Module, Method, TenantName, Parameters]
[14:05:32.71][fe438d6e]
[14:05:32.71][fe438d6e] API: LogsViewerWebclient::GetLogFilesData
[14:05:32.78][c0b04492] [POST(3)][ip:127.0.0.1] /index.php?/Api/
[14:05:32.78][c0b04492] POST > [Module, Method, Parameters]
[14:05:32.78][c0b04492]
[14:05:32.78][c0b04492] API: Mail::GetFolders
[14:05:32.79][c0b04492] Aurora\System\Exceptions\ApiException: ApiException in C:\Apache24\htdocs\Sandbox\webmail_php\modules\Core\Module.php:503
Stack trace:
#0 [internal function]: Aurora\Modules\Core\Module->EntryApi()
#1 C:\Apache24\htdocs\Sandbox\webmail_php\system\Module\AbstractModule.php(619): call_user_func_array(Array, Array)
#2 C:\Apache24\htdocs\Sandbox\webmail_php\system\Module\Manager.php(689): Aurora\System\Module\AbstractModule->RunEntry('api')
#3 C:\Apache24\htdocs\Sandbox\webmail_php\system\Application.php(87): Aurora\System\Module\Manager->RunEntry('api')
#4 C:\Apache24\htdocs\Sandbox\webmail_php\index.php(21): Aurora\System\Application::Start()
#5 {main}
[14:05:37.66][0bdc3b6b] [POST(4)][ip:::1] /?/Api/
[14:05:37.66][0bdc3b6b] POST > [Module, Method, TenantName, Parameters]
[14:05:37.66][0bdc3b6b]
[14:05:37.66][0bdc3b6b] API: LogsViewerWebclient::GetLog
[14:05:37.68][0bdc3b6b] PHP[NOTICE]: C:\Apache24\htdocs\Sandbox\webmail_php\modules\Core\Module.php [line:3343, code:2]
[14:05:37.68][0bdc3b6b] PHP[NOTICE]: Error: file_get_contents(): Failed to seek to position -7187 in the stream
[14:05:37.73][0bdc3b6b] INFO[MEMORY]: Memory peak usage: 2MB
[14:05:37.73][0bdc3b6b] INFO[TIME]: Time delta: 1523369137.7335
[14:05:37.95][e0b4edf4] [POST(4)][ip:::1] /?/Api/
[14:05:37.95][e0b4edf4] POST > [Module, Method, TenantName, Parameters]
[14:05:37.95][e0b4edf4]
[14:05:37.95][e0b4edf4] API: LogsViewerWebclient::GetLogFilesData
[14:05:39.08][48347ca4] [POST(4)][ip:::1] /?/Api/
[14:05:39.08][48347ca4] POST > [Module, Method, TenantName, Parameters]
[14:05:39.08][48347ca4]
[14:05:39.08][48347ca4] API: LogsViewerWebclient::GetLog
[14:05:39.09][48347ca4] PHP[NOTICE]: C:\Apache24\htdocs\Sandbox\webmail_php\modules\Core\Module.php [line:3343, code:2]
[14:05:39.10][48347ca4] PHP[NOTICE]: Error: file_get_contents(): Failed to seek to position -6399 in the stream
[14:05:39.14][48347ca4] INFO[MEMORY]: Memory peak usage: 2MB
[14:05:39.15][48347ca4] INFO[TIME]: Time delta: 1523369139.1494
[14:05:43.19][892fa80e] [POST(4)][ip:::1] /?/Api/
[14:05:43.19][892fa80e] POST > [Module, Method, TenantName, Parameters]
[14:05:43.19][892fa80e]
[14:05:43.19][892fa80e] API: LogsViewerWebclient::GetLogFilesData
[14:05:43.61][29f462c0] [POST(4)][ip:::1] /?/Api/
[14:05:43.61][29f462c0] POST > [Module, Method, TenantName, Parameters]
[14:05:43.61][29f462c0]
[14:05:43.61][29f462c0] API: LogsViewerWebclient::GetLog
[14:05:43.63][29f462c0] PHP[NOTICE]: C:\Apache24\htdocs\Sandbox\webmail_php\modules\Core\Module.php [line:3343, code:2]
[14:05:43.63][29f462c0] PHP[NOTICE]: Error: file_get_contents(): Failed to seek to position -5611 in the stream
[14:05:43.68][29f462c0] INFO[MEMORY]: Memory peak usage: 2MB
[14:05:43.68][29f462c0] INFO[TIME]: Time delta: 1523369143.6813
[14:05:45.35][a1f06d93] [POST(4)][ip:::1] /?/Api/
[14:05:45.35][a1f06d93] POST > [Module, Method, TenantName, Parameters]
[14:05:45.35][a1f06d93]
[14:05:45.35][a1f06d93] API: LogsViewerWebclient::GetLog
|
Back to Top |
|
|
Igor AfterLogic Support
Joined: 24 June 2008 Location: United States
Online Status: Offline Posts: 6104
|
Posted: 11 April 2018 at 2:13am | IP Logged
|
|
|
Can you post a sample code showing how exactly you're getting list of folders?
--
Regards,
Igor, Afterlogic Support
|
Back to Top |
|
|
festusngor Newbie
Joined: 10 April 2018 Location: United Kingdom
Online Status: Offline Posts: 20
|
Posted: 11 April 2018 at 2:15am | IP Logged
|
|
|
This is how I'm authenticating and trying to fetch folders
$authResponse = CURL::POST(
EMAIL_API_URI,
[
'Module' => 'Core',
'Method' => 'Login',
'Parameters' => '{"Login":"' . $checkPswdAvailable['sync_email_login'] . '","Password":"' . $checkPswdAvailable['sync_email_pswd'] . '","SignMe":true}',
],
[CURLOPT_SSL_VERIFYPEER => TRUE]
);
if ($authResponse && $authResponse->result) {
$emailAuthResponse = json_decode($authResponse->result);
// Fetch mail folders.
if (intval($emailAuthResponse->AuthenticatedUserId) > 0) {
$authFetchResponse = CURL::POST(
EMAIL_API_URI,
[
'M odule' => 'Mail',
'M ethod' => 'GetFolders',
'P aramet ers' => '{"AccountID":' . $emailAuthResponse->AuthenticatedUserId . '}'
],
[
CU RLOPT_ SSL_VERIFYPEER => TRUE,
CU RLOPT_ SSL_VERIFYHOST => 2,
],
[
CU RLOPT_ HTTPHEADER => ["Authorization: Bearer {$emailAuthResponse->Result->AuthToken}"]
]
);
if ($authFetchResponse) {
$emailAuthToken = [
"l oginEm ail" => $checkPswdAvailable['sync_email_login'],
"e mailAu thResponse" => $emailAuthResponse,
"e mailFe tchResponse" => json_decode($authFetchResponse->result),
];
}
}
} else {
throw new \Exception("Cannot connect to email server. Contact administrator");
}
|
Back to Top |
|
|
festusngor Newbie
Joined: 10 April 2018 Location: United Kingdom
Online Status: Offline Posts: 20
|
Posted: 11 April 2018 at 2:20am | IP Logged
|
|
|
Initially I was using a base64_encode to set my header:
CURLOPT_HTTPHEADER => ["Authorization: Bearer " . base64_encode("{$emailAuthResponse->Result->AuthToken}")]
but changed to:
CURLOPT_HTTPHEADER => ["Authorization: Bearer {$emailAuthResponse->Result->AuthToken}"]
So it seemed to have gone through but its now returning this error:
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Fatal error: Uncaught TypeError: Argument 1 passed to Aurora\Modules\Mail\Managers\Main\Manager::_getImapClient() must be an instance of Aurora\Modules\Mail\Classes\Account, null given, called in C:\Apache24\htdocs\Sandbox\webmail_php\modules\Mail\Managers\Main\Manager.php on line 506 and defined in C:\Apache24\htdocs\Sandbox\webmail_php\modules\Mail\Managers\Main\Manager.php on line <i>61</i></th></tr>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> TypeError: Argument 1 passed to Aurora\Modules\Mail\Managers\Main\Manager::_getImapClient() must be an instance of Aurora\Modules\Mail\Classes\Account, null given, called in C:\Apache24\htdocs\Sandbox\webmail_php\modules\Mail\Managers\Main\Manager.php on line 506 in C:\Apache24\htdocs\Sandbox\webmail_php\modules\Mail\Managers\Main\Manager.php on line <i>61</i></th></tr>
|
Back to Top |
|
|
Igor AfterLogic Support
Joined: 24 June 2008 Location: United States
Online Status: Offline Posts: 6104
|
Posted: 11 April 2018 at 2:55am | IP Logged
|
|
|
We believe the problem is caused by this:
Code:
'Parameters' => '{"AccountID":' . $emailAuthResponse->AuthenticatedUserId . '}' |
|
|
You need to supply email account ID there, not user ID. You can retrieve list of email accounts for the user with:
https://afterlogic.com/webmail-pro-8-webapi/#api-Mail-GetAccounts
After getting an account you need, use it with:
https://afterlogic.com/webmail-pro-8-webapi/#api-Mail-GetFolders
Hope this helps.
--
Regards,
Igor, Afterlogic Support
|
Back to Top |
|
|
festusngor Newbie
Joined: 10 April 2018 Location: United Kingdom
Online Status: Offline Posts: 20
|
Posted: 11 April 2018 at 4:02am | IP Logged
|
|
|
That worked out perfect... Thanks Igor
|
Back to Top |
|
|