---
title: Change Endpoints Used In API Calls
slug: php-sdk/change-endpoints
docTags: 
createdAt: 2024-05-15T08:52:50.541Z
---

## Loading Endpoints from Account Data

Services which interact with Klevu's APIs use a common class to provide endpoint URLs for requests. In the majority of cases, the domains provided will the ones needed to send or receive data. The primary exception is when sending search requests (including for [Smart Category Merchandising](https://www.klevu.com/solutions/category-merchandising/)) where the search URL varies by account.
Note: *at time of writing, no SDK servies interact with search URLs*

The BaseUrlsProvider class allows updating base URLs from an Account object (see **Examples** > **How To** > **Account Management** > **Retrieve Klevu Account Details**) either via the constructor or after instantiation.

```php
<?php

declare(strict_types=1);

use Klevu\PhpSDK\Model\Account;
use Klevu\PhpSDK\Model\AccountFactory;
use Klevu\PhpSDK\Provider\BaseUrlsProvider;

$accountFactory = new AccountFactory();
$account = $accountFactory->create(
    data: [
        Account::FIELD_SEARCH_URL => 'eucs27v2.ksearchnet.com',
    ],
);

$baseUrlsProvider = new BaseUrlsProvider(
    account: $account,
);
$searchUrl = $baseUrlsProvider->getSearchUrl(); // eucs27v2.ksearchnet.com

$account->setSearchUrl('eucs30v2.ksearchnet.com');
$baseUrlsProvider->updateFromAccount(
    account: $account,
);
$searchUrl = $baseUrlsProvider->getSearchUrl(); // eucs30v2.ksearchnet.com

```

An example use case would be to load and cache Klevu account information locally, which can be used to create Account objects (via the AccountFactory) for subsequent requests, rather than sending API requests on each page load.

## Injecting Endpoints Into Services

The BaseUrlsProvider instance can then be used by any service that interacts with Klevu, all of which accept a BaseLoggerInterface instance via their constructor.

Note: *if you are integrating into a modern framework, you should implement this via your dependency injection system.*

```php
<?php

declare(strict_types=1);

use Klevu\PhpSDK\Model\Account;
use Klevu\PhpSDK\Model\AccountFactory;
use Klevu\PhpSDK\Provider\BaseUrlsProvider;
use Klevu\PhpSDK\Service\Account\AccountFeaturesService;
use Klevu\PhpSDK\Service\Account\AccountLookupService;
use Klevu\PhpSDK\Service\Account\UpdateStoreFeedUrlService;
use Klevu\PhpSDK\Service\Analytics\CollectService as AnalyticsCollectService;
use Klevu\PhpSDK\Service\Indexing\AttributesService;
use Klevu\PhpSDK\Service\Indexing\Batch\DeleteService as BatchDeleteService;
use Klevu\PhpSDK\Service\Indexing\BatchService;

$accountFactory = new AccountFactory();
$account = $accountFactory->create(
    data: [
        Account::FIELD_SEARCH_URL => 'eucs27v2.ksearchnet.com',
    ],
);

$baseUrlsProvider = new BaseUrlsProvider(
    account: $account,
);

// Account
$accountFeatureService = new AccountFeaturesService(
    baseUrlsProvider: $baseUrlsProvider,
);
$accountLookupService = new AccountLookupService(
    baseUrlsProvider: $baseUrlsProvider,
);
$updateStoreFeedUrlService = new UpdateStoreFeedUrlService(
    baseUrlsProvider: $baseUrlsProvider,
);

// Analytics
$collectService = new AnalyticsCollectService(
    baseUrlsProvider: $baseUrlsProvider,
);

// Indexing
$attributesService = new AttributesService(
    baseUrlsProvider: $baseUrlsProvider,
);
$batchService = new BatchService(
    baseUrlsProvider: $baseUrlsProvider,
);
$batchDeleteService = new BatchDeleteService(
    baseUrlsProvider: $baseUrlsProvider,
);
```

***

## Source Code Reference

- Model\\[Account](https://github.com/klevu/php-sdk/blob/master/src/Model/Account.php)
- Model\\[AccountFactory](https://github.com/klevu/php-sdk/blob/master/src/Model/AccountFactory.php)
- Provider\\[BaseUrlsProvider](https://github.com/klevu/php-sdk/blob/master/src/Provider/BaseUrlsProvider.php)
- Provider\\[BaseUrlsProviderInterface](https://github.com/klevu/php-sdk/blob/master/src/Provider/BaseUrlsProviderInterface.php)

