Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with page size, but it's set at 1? #11

Open
swooningfish opened this issue Aug 17, 2021 · 6 comments · May be fixed by #12
Open

Issue with page size, but it's set at 1? #11

swooningfish opened this issue Aug 17, 2021 · 6 comments · May be fixed by #12

Comments

@swooningfish
Copy link

swooningfish commented Aug 17, 2021

Getting this strange bug when I search by name. any idea's?

(See below for details)

Bad request: Invalid value '[14]' for query parameter page. Invalid number 14 expected number between 1 and 13 vendor/synergitech/creditsafe-connect/src/Client.php Line:175

The code i have is

$creditSafeClient = new \SynergiTech\Creditsafe\Client([
		'username' => env('CREDIT_SAFE_USERNAME'),
		'password' => env('CREDIT_SAFE_PASSWORD')
]);
					
$searchParams = ['countries' => 'GB', 'name' => 'Test'];
$creditSafeResults = $creditSafeClient->companies()->search($searchParams);
$creditSafeResults->setPageSize(1);


if ($creditSafeResults->valid()) {
	foreach ($creditSafeResults as $result) {
		$accounts = $result->get();
	}
	$returnArray['code'] = 200;
	$returnArray['accounts'] = $accounts;
} else {
	$returnArray['code'] = 200;
	$returnArray['message'] = 'No results found';
}
@willpower232
Copy link
Member

You've set page size to 1 so if there are lots of results then it will have to fetch many pages but apparently it is possible to fetch too many pages.

I'm not able to reproduce the issue with ['countries' => 'GB', 'name' => 'Test'], are you or can you share what you're searching for?

@swooningfish
Copy link
Author

swooningfish commented Aug 18, 2021

Thanks,

Was thinking about the page size of 1 just before my head hit the pillow.. Have now set the page size to 100, but think there is a lot of results, and perhaps it's not knowing when the last page stops at?

I'm searching for a company by name 'Test' shows the same error as the company which I'm searching for Elevator

Putting the code in a try and catch statement it seems to take a long time and then throws this exception
Bad request: Invalid value '[14]' for query parameter page. Invalid number 14 expected number between 1 and 13

The full stack trace is shown below.
Line 116 in the JsonController is the foreach loop.

    "message": "Bad request: Invalid value '[14]' for query parameter page. Invalid number 14 expected number between 1 and 13",
    "exception": "SynergiTech\\Creditsafe\\Exception\\APIException",
    "file": "C:\\vhosts\\website.local\\vendor\\synergitech\\creditsafe-connect\\src\\Client.php",
    "line": 175,
    "trace": [
        {
            "file": "C:\\vhosts\\website.local\\vendor\\synergitech\\creditsafe-connect\\src\\Client.php",
            "line": 195,
            "function": "request",
            "class": "SynergiTech\\Creditsafe\\Client",
            "type": "->"
        },
        {
            "file": "C:\\vhosts\\website.local\\vendor\\synergitech\\creditsafe-connect\\src\\ListResult.php",
            "line": 91,
            "function": "get",
            "class": "SynergiTech\\Creditsafe\\Client",
            "type": "->"
        },
        {
            "file": "C:\\vhosts\\website.local\\vendor\\synergitech\\creditsafe-connect\\src\\ListResult.php",
            "line": 77,
            "function": "fetchPage",
            "class": "SynergiTech\\Creditsafe\\ListResult",
            "type": "->"
        },
        {
            "file": "C:\\vhosts\\website.local\\vendor\\synergitech\\creditsafe-connect\\src\\ListResult.php",
            "line": 126,
            "function": "page",
            "class": "SynergiTech\\Creditsafe\\ListResult",
            "type": "->"
        },
        {
            "file": "C:\\vhosts\\website.local\\app\\Http\\Controllers\\Admin\\JsonController.php",
            "line": 116,
            "function": "next",
            "class": "SynergiTech\\Creditsafe\\ListResult",
            "type": "->"
        }
	]

Full code snippet querying Credit Safe

        $returnArray = array(
            'status' => 'error',
            'accounts' => [],
            'message' => '',
            'html' => '',
            'code' => 500
        );

        $accounts = [];
        $company_name = $request->input('name');
        if ($company_name) {
            try {
                $creditSafeClient = new \SynergiTech\Creditsafe\Client(['username' => env('CREDIT_SAFE_USERNAME'),
                    'password' => env('CREDIT_SAFE_PASSWORD')]);
                
                $searchParams = ['countries' => 'GB', 'name' => $company_name];
                if ($request->input('city')) {
                    $searchParams['city'] = $request->input('city');
                }

                $creditSafeResults = $creditSafeClient->companies()->search($searchParams);
                $creditSafeResults->setPageSize(100);

                if ($creditSafeResults->valid()) {
                    foreach ($creditSafeResults as $result) {
                        $accounts[] = array(
                            'companyID' => $result->getID(),
                            'businessName' => $result->getName(),
                            'registeredCompanyName' => $result->getRefNo(),
                            'mainAddress' => $result->getAddress(),
                            'type' => $result->getType(),
                            'dateOfLatestChange' => $result->getDateOfLatestChange()->format('Y-m-d H:i:s'),
                        );
                    }
                    $returnArray['code'] = 200;
                    $returnArray['accounts'] = $accounts;
                } else {
                    $returnArray['code'] = 200;
                    $returnArray['message'] = 'No results found';
                }


            } catch (APIException $e) {
                $returnArray['status'] = 'error';
                $returnArray['message'] = $e->getMessage();
                $returnArray['code'] = 500;
                return response()->json($returnArray, $returnArray['code']);
            }
        }
       return $returnArray;

Wonder if a for loop rather than the foreach could be done if the List results can know the page and last page number?

@willpower232
Copy link
Member

Thanks for the extra information, I can now reproduce. It looks like there are some problems with how we have implemented iteration so we'll have a look at fixing it.

@swooningfish
Copy link
Author

swooningfish commented Aug 18, 2021

Thanks,

Think it might also be if it's over the page size of 14, of the results ,e.g. 14000+ records, being returned by credit save, I've limited the result set only 300 by putting in the city field to Aberdeen,

Would be good to get the full record set,
Or add in a limit e.g. stop after page 3 of a result set of 100. so it only shows the first 300 records.. (if the page size is set to 100)

@willpower232 willpower232 linked a pull request Aug 18, 2021 that will close this issue
@ghost
Copy link

ghost commented Aug 18, 2021

Superb! and super faster.. Awesome work people!

@willpower232
Copy link
Member

blast from the past but it also seems to be broken in their own UI, hashtag watch this space

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants