FAQ - Frequently asked questions

PHP API Client - The parameter order of individual methods has changed after an update

Unfortunately, when the API client is regenerated, the swagger codegen produces different parameter orders for individual methods. This can happen when new filter options are added.

But you can work around this, as in the following example, by determining the order based on the parameter names and "calling" the method with an associative array, where the keys in the associative array correspond to the names of the individual parameters.


setApiKey('Authorization', JWT_API_TOKEN);
eSagu\\EBay\\RePricing\\V1\\Configuration::getDefaultConfiguration()->setApiKeyPrefix('Authorization', 'Bearer');

$itemApi = new eSagu\\EBay\\RePricing\\V1\\Api\\ItemApi();

$itemsPerPage = 5;
$page = 0;
try {
    do {
        $items = callWithOrderedParams($itemApi, 'callList', [
            'offset'   => $page++ * $itemsPerPage,
            'limit'    => $itemsPerPage,
            'by_title' => \"Turnschuhe\",
        ]);

        $hasMore = count($items) === $itemsPerPage;
        $ebayItemIds = implode(', ', array_map(function (RepricingItemDTO $item) { return $item->getItemId(); }, $items));

        echo \"Page: \\\"$page\\\", Item Ids: \\\"$ebayItemIds\\\"\", PHP_EOL;

    } while ($hasMore);
} catch (Exception $e) {
    echo $e->getMessage(), PHP_EOL;
}

\/**
 * @param mixed $apiInstance
 * @param string $methodName
 * @param array $paramsAssoc
 * @return mixed
 * @throws \\ReflectionException
 *\/
function callWithOrderedParams($apiInstance, $methodName, $paramsAssoc)
{
    $params = [];
    foreach ((new \\ReflectionMethod($apiInstance, $methodName))->getParameters() as $refParam) {
        $params[$refParam->name] = null;
    }

    foreach ($paramsAssoc as $key => $val) {
        if (array_key_exists($key, $params)) {
            $params[$key] = $val;
            continue;
        }

        $className = get_class($apiInstance);
        $methodParams = implode(', ', array_map(function ($p) { return \"\\$$p\"; }, array_keys($params)));

        throw new InvalidArgumentException(\"Param \\\"$key\\\" is not present in \\\"$className->$methodName($methodParams)\\\"!\");
    }

    return call_user_func_array([$apiInstance, $methodName], $params);
}