Get All sources list Multi Source Inventory (MSI) Programmatically Magento 2.

Multi-source inventory (MSI) Was Introduced from Magento 2.3 Version.

MSI contains multiple sources related to store location.

If any website has multiple selling locations and that contains multiple inventory locations to sell products, you need to create multiple sources for the item to ship.

Magento Out-of-the-box comes with Default Source with MSI installation.

Related Table in Database to store sources entry:
* inventory_source

What are Sources in MSI?
Sources refer to inventory management in physical locations. Each source is a Warehouse (or brick-mortar store, drop shipper or distribution center) that contains products to ship.

If you have created multiple sources for the Magento system, You can fetch the list of sources available for a system via programmatically using a given code.

I have created a simple Model class to get all the sources,

<?php
namespace Jesadiya\SourceList\Model;

use Exception;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\InventoryApi\Api\Data\SourceInterface;
use Magento\InventoryApi\Api\SourceRepositoryInterface;
use Psr\Log\LoggerInterface;

class Demo
{
    /**
     * @var SearchCriteriaBuilder
     */
    private $searchCriteriaBuilder;

    /**
     * @var SourceRepositoryInterface
     */
    private $sourceRepository;

    /**
     * @var LoggerInterface
     */
    private $logger;

    public function __construct(
        SearchCriteriaBuilder $searchCriteriaBuilder,
        SourceRepositoryInterface $sourceRepository,
        LoggerInterface $logger
    ) {
        $this->searchCriteriaBuilder = $searchCriteriaBuilder;
        $this->sourceRepository = $sourceRepository;
        $this->logger = $logger;
    }

    /**
     * Get All source list
     *
     * @return SourceInterface[]|null
     */
    public function getSourcesList()
    {
        $searchCriteria = $this->searchCriteriaBuilder->create();
        try {
            $sourceData = $this->sourceRepository->getList($searchCriteria);
            if ($sourceData->getTotalCount()) {
                return $sourceData->getItems();
            }
        } catch (Exception $exception) {
            $this->logger->error($exception->getMessage());
        }
        return null;
    }
}

You can call the function to get a list of available sources,

$sourceList = $this->getSourcesList();
if ($sourceList) {
    foreach ($sourceList as $source) {
        echo "<pre>";
        print_r($$source->getData());
    }
}

The Output is an array of lists of sources defined in the system.

Array
(
    [source_code] => default
    [name] => Default Source
    [enabled] => 1
    [description] => Default Source
    [latitude] => 0.000000
    [longitude] => 0.000000
    [country_id] => US
    [region_id] => 
    [region] => 
    [city] => 
    [street] => 
    [postcode] => 00000
    [contact_name] => 
    [email] => 
    [phone] => 
    [fax] => 
    [use_default_carrier_config] => 1
    [carrier_links] => Array
        (
        )
)

You can get required data from the output like source name, is enable, city, state, country_id, email and phone.

This is the basic example of retrieving the list of sources in Magento 2 MSI.