private function callApiLogin($token = null)
    {
        $postData = ['lgname' => $this->apiUser, 'lgpassword' => $this->apiPassword];
        if (null !== $token) {
            $postData['lgtoken'] = $token;
        }

        $result = $this->callApi('action=login', $postData);
        try {
            $this->checkApiResponseResult('login', $result);
        } catch (BuildException $e) {
            if (null !== $token) {
                throw $e;
            }
            // if token is required then call login again with token
            $this->checkApiResponseResult('login', $result, 'NeedToken');
            if (isset($result['login']) && isset($result['login']['token'])) {
                $this->callApiLogin($result['login']['token']);
            } else {
                throw $e;
            }
        }
    }