PHP marketplace: The developer’s guide

Considering building a marketplace with PHP? Comparing marketplace PHP scripts or software? Worried about the drawbacks or looking for alternatives? This article is for you. Written by Sharetribe’s senior full-stack developer Mikko, it’s the complete developer’s guide to everything you need to know about building a marketplace with PHP.

Chapter 1

Introduction: Why a PHP marketplace?

A few thoughts on the popularity of PHP marketplace solutions and scripts.


An online marketplace has the potential to grow into a tremendous, global-scale business. 

But building a marketplace platform is a big undertaking. One solution to speed up the process and leverage the potential of marketplaces comes in the form of PHP scripts and PHP marketplace software.

An eCommerce marketplace has great growth potential

The online marketplace boom shows no sign of slowing down. In 2020, sales on the top online marketplaces were worth $2.67 trillion. By 2024, sales are predicted to go over $7 trillion. That’s a big window of opportunity. 

The marketplace model is tempting for eCommerce entrepreneurs for many reasons. 

In a nutshell, an online marketplace brings together two sides of a market, the supply, and the demand. The platform owner facilitates their transactions and typically makes money through commission or another marketplace business model.

Flowchart of a marketplace business model: provider on the right, marketplace in the middle, customer on the left.
A typical business model of a marketplace platform like Airbnb.

This two-sided marketplace model has tremendous benefits. It requires no initial inventory from the marketplace entrepreneur. It makes the experience of buying and selling efficient, convenient, and transparent. It has the potential to generate network effects that can become a massive growth lever for the business.

Developing a marketplace platform from scratch continues to be a big, complex project. Luckily, there are great alternatives for marketplace website development apart from building one from scratch. Which brings me to the next reason why PHP marketplace solutions have been popular in recent years.

A PHP marketplace script or software can save you time and money

Marketplaces are much more complex sites than traditional eCommerce stores. I’ve written about the specificities of marketplace functionality in more detail in this article. But the tl;dr would be that because there are two distinct user groups, everything from managing user-generated content to designing the exact transaction process becomes more challenging. Marketplace payments are particularly complicated, as there are all kinds of technical and legal hurdles to overcome. 

From the perspective of a developer, most of the must-have marketplaces are also pretty boring to build. Essential marketplace website features like listings, profiles, messages, online payments, and admin features are essentially the same on any marketplace. They’re the stuff users nowadays take for granted. And yet, building them will take the bulk of a dev’s time.

Using a marketplace script can save you lots of time by giving you some of the complicated-but-boring-yet-essential features out of the box. This is a big benefit, because it frees up your time to build the features that make your business unique. 

PHP is a practical coding language for getting stuff done

Even if the golden era of PHP might be in the past, the language is anything but abandoned. There was a major version release of PHP 8 in November 2020. And big companies like Facebook, Lyft, Tumblr, Slack, Etsy, and MailChimp continue to use PHP in their infrastructure.

PHP has been around for a long time – since 1995, according to Wikipedia. So we're talking about a mature language for sure, and a language with a big user community. When the time comes to expand your team, finding a PHP developer won’t be an issue. 

PHP is a mature coding language with a big user community.

Many developers enjoy working with PHP because it’s one of the easiest languages to learn.  And it offers a good set of frameworks you can choose your favorite from: Laravel, Codelgniter, and Symphony being the most popular. PHP frameworks implement commonly used functions and save you from writing every bit of code from scratch.

In short: while PHP may not be the most elegant coding language nowadays, it remains a practical language for those who want to get things done.

There are plenty of PHP marketplace scripts and PHP marketplace software out there

There are lots of marketplace solutions out there powered by PHP. Some people refer to them as scripts, others as marketplace software solutions or marketplace platforms. In the end, these terms mean roughly the same thing, but there are lots of differences between individual products offered. (The next chapter of this article will help you with comparing the offering.)

A marketplace script or software solution is essentially an application that powers a set of marketplace features. 

Some are available to download and install on your own server, either for a one-off fee or completely for free if you find an open-source marketplace solution. Places like CodeCanyon, for example, let you find scripts for different marketplace types, and many scripts have online demos you can test. After installing the script, you typically need to customize it using the coding language it was built on – in this case, PHP.

A PHP script is an application that powers a set of marketplace features.

There are also PHP-based eCommerce software solutions that are available as no or low-code Software-as-a-Service products. They have a graphic UI you can use to adjust the features and set up your marketplace, and many offer some level of hosting, maintenance, and technical support. Some of them are also offered as more customizable or open-source alternatives.

For example, CS Cart is a downloadable eCommerce solution that has a multi-vendor version to power online malls. It has a one-off downloading fee. The more features you want included, the bigger the price tag. You’ll then host the solution on your server, after which you can customize the software either using the built-in no-code tools or through code. 

Magento Commerce is an eCommerce store builder, on top of which you can buy a multi-vendor extension to get the basic two-sided functionality. It’s offered both as a hosted cloud solution, where pricing is based on Gross Merchandise Value and Average Order Value, and an open-source version with a more limited feature set.

Finally, you can build a marketplace with WordPress using the WooCommerce plugin for the online store functionality and a plugin for multi-vendor functionality. You can read more about this approach in our article comparing Wordpess and SaaS

To sum up: if you decide to use a PHP-script or an eCommerce builder to power your marketplace, there are plenty of options you can compare and choose from.

Our answer: Sharetribe's software

This feels like as good a spot as any for a short self-promotional message. There are many alternatives to building a marketplace other than using a PHP marketplace script – from no-code marketplace SaaS to coding from scratch. Every option presents a trade-off. No-code SaaS is fast, easy, and affordable, but low on customizability. Coding from scratch offers unlimited customizability but is work-intensive both during building and in terms of maintenance.

Self-hosted PHP scripts offer a faster time to market with improved customizability. However, they tend to pose challenges when it comes to custom-building entire new features, powering multiple marketplace transaction flows, or building third-party integrations. They may also offer a less than ideal developer experience. Most importantly, they leave most of the maintenance work to you, which, at any meaningful scale, quickly becomes a full-time job.

A grid with different ways to build a marketplace and their most important differences.
A headless marketplace solution like Sharetribe can reduce the trade-offs marketplace entrepreneurs have to make when they're choosing their approach to building a marketplace.

Sharetribe is a headless marketplace solution that we developed to combine the best aspects of all approaches. It’s fast to launch without coding if you choose the no-code Sharetribe-hosted option. This is a great way for any marketplace to start and validate the idea. Sharetribe is also effortless to maintain. In addition to its no-code capabilities, Sharetribe is built from the ground up to be fully customizable – it makes even challenging development projects like iterating on marketplace transaction processes a breeze. It puts developer experience front and center.

The Sharetribe backend gives you a powerful feature set for a fully functional marketplace. To take the backend into use very quickly, Sharetribe offers you an open-source web app template built with a combination of Javascript, React, and Node.js. But the beauty of Sharetribe is that you can use any technology to build a user interface on top of Sharetribe's Marketplace API.

If you’re interested, skip ahead to chapter three, where I share the steps of building a Sharetribe-powered marketplace with PHP, along with a code example for calling the Marketplace API with PHP that is copy-paste ready.

Chapter 2

Potential challenges with marketplace scripts and eCommerce builders

Things to consider when choosing a PHP marketplace script.


Depending on your future plans and goals for your business, there are some questions worth considering already at the early stages. These questions can also help you compare the offering and choose the best script or software solution for you.

Is your marketplace type supported? 

A big chunk of the essential marketplace functionality works for almost every marketplace idea, niche, and market. But one thing plays a big role here: your marketplace offering type.

“Online malls” (websites like Amazon, eBay, and Alibaba) ship relatively low-value items from multiple sellers across the globe. They often need a shopping cart with a multi-vendor checkout and great features to support shipping and inventory management. They might get by with one-sided reviews (only the customers review the sellers). Building a peer-to-peer product marketplace like Etsy introduces more two-sided feature requirements.

If your marketplace offers rentals (you're building a website like Airbnb) or services (you want to build a website like Fiverr) are different. They have no use for a shopping cart or shipping. Instead, what they need is a great booking calendar, an availability management feature, and location search. Two-sided reviews are a must – both customers and providers need a guarantee they can trust the other party.

To make things more complicated, a marketplace for selling single unique, high-value products (like works of art, vehicles, or apartments) might in fact work more like a rental or service marketplace than a product marketplace, from a strictly feature-set-point-of-view that is. The audience type might play a role as well – peer-to-peer marketplaces need different features than B2C businesses, not to mention B2B marketplaces with complicated, multi-sided transaction flows.

Thinking about your marketplace idea from this perspective helps you with choosing the best starting point for your platform. For example, big eCommerce players like CS-Cart, Magento, and WooCommerce are designed for the “online mall” starting point and might be more challenging to customize into powerful service, rental, or job marketplaces.


Our guides on how to build rental marketpalces, service marketplaces, peer-to-peer marketplaces, and B2B marketplaces might help you with estimating your exact feature requirements.

How are payments processed?

Marketplace payments are about as complicated as online payments get. Both from a technical point of view and a legal one.

First, your customers want to check out easily with the payment method they prefer. Different methods require vastly different processes. Then, the customer’s payment needs to be split into your marketplace commission (if that’s your revenue model) and the payout your provider gets. 

Marketplace payments are about as complicated as online payments get.

You probably want to delay paying the provider until they’ve delivered what the customer bought — a process that is subject to all kinds of regulatory and technical challenges. Finally, paying the provider requires going through a Know Your Customer process to comply with anti-money laundering legislation.

Different PHP scripts and eCommerce solutions handle payments differently. At the very least, make sure they allow you to process payouts to the sellers without the money going through your own bank account first. Otherwise, you might step into a legal jungle as in the eyes of regulators, you’re acting as a bank and depositing your seller’s money without the required legal compliance.

These questions should impact your choice of marketplace solution. But it’s also a question of choosing the right marketplace payment service provider and deciding on the right kind of payment integration. I’ve written about integrating a 3rd party payment gateway at length in our documentation. The article can be quite useful even if you’re not building your marketplace with Sharetribe.

Is the transaction process customizable?

Your marketplace transaction process (or transaction flow) includes online payments – and much more. The transaction flow includes all of the steps your customers and providers need to take to complete a transaction. From their very first point of contact, through messages and booking requests, all the way to a successful payment and review. 

The process also needs to include other possible outcomes. What if the provider doesn’t accept the booking on time? Can both the customer and the provider cancel a booking at any time? What happens if the payment process fails? What if the customer asks for a refund?

Our CEO Juho’s article about designing your marketplace transaction flow can help you figure out your requirements. This piece of Sharetribe documentation can also help regardless of the technology you choose.

Flowchart portraying a default marketplace booking process in Sharetribe.
Sharetribe's default booking process is a good starting point for modelling your own transaction process.

When you’re choosing a PHP marketplace script, pay attention to how well the default transaction process can be customized. A fixed process with a simple “add to cart” -> checkout -> profit flow can be tough to customize to support everything you want from your marketplace.

Another important point: you’re guaranteed to want to customize your transaction process as your business grows. At least in my experience, this is the part that entrepreneurs iterate on the most and where the biggest potential gains are in terms of conversion rate optimization.

So in addition to being offering a customizable transaction process, check that the script supports editing the transaction process while your marketplace is live and there are ongoing transactions. If you can’t have multiple transaction process versions live simultaneously, you’ll effectively have to close down your marketplace for several weeks if you want to make the slightest change to your transaction process. Having the ability to have multiple different transaction processes for different order types is a great feature as well. 

I’ve written a detailed article about marketplace apps that discusses transaction processes in more detail.

Is marketplace the core offering?

Related to the previous points about transactions processes and payments: marketplaces are a lot more complicated applications than online eCommerce stores. 

Usually, my recommendation is to choose a software solution or a script that was specifically built for powering online marketplaces. If the word “marketplace” isn’t mentioned on the front page, and instead words like “multi-vendor eCommerce” are used, that may indicate that the support for multiple sellers was added as an afterthought. But building a multi-vendor marketplace is not as simple as adding seller profiles to an eCommerce store. A tweaked online store solution may not be ideal for powering a competitive marketplace platform with plans to reach a significant scale. Or at the very least, you’ll need to do heavy customization.

Choose a dedicated marketplace solution if your goal is to compete at a significant scale.

I have some bias here because Sharetribe's software is specifically built for creating online marketplaces, and the benefits are clear in my book. But there are some PHP-based marketplace scripts and software solutions available that take a marketplace platform as a starting point, too.

How is the developer experience?

When you’re starting a new marketplace business, the best move is to work with the MVP mindset and launch as fast as possible. But sometimes, a platform needs a powerful custom feature from the get-go. That might mean trading speed with a better UX makes sense.

But having to delay your launch because you’re too busy debugging or navigating a messy codebase that wasn't built with customizability in mind? Unacceptable.  

When you choose your PHP marketplace script, make sure it’s a joy to work with. Check things like:

  • Are there lots of features you don’t need? These will over-complicate the code.
  • Are there interdependencies? Does changing one feature require updating everything else?
  • How is the quality of documentation?
  • Is expert technical support available? Will it be available throughout your project? 

Though this is time-consuming to estimate (and compare – good to check at least a few candidates to get a sense of the standards), I really recommend taking the time. Check the demos, download the code if there’s a free trial, read through the documentation, and test the support with challenging questions.

The time you spend here will pay back multiple times over the course of building, maintaining, and improving your marketplace.

But does it scale?

Though I just recommended the MVP-approach, sparing some thought for the future is warranted.

The big question here is does the PHP marketplace solution have an API, and do you need one. If you want to build a mobile app and/or integrate third-party tools (say for marketing automation, CRM, shipping, notifications, payment methods, or the like), an API is pretty much a must.

The green-hued "Philosoraptor" meme with the head and claw of a velociraptor with text "but does it scale?"

If you’re working with a marketplace script where you’re in charge of hosting both the frontend and the backend databases, large listing images, and search indexes, maintenance is another concern. How do you estimate the cost, both in terms of money and time, of hosting and maintaining a platform for 10,000 users? 100,000? 1,000,000?

Security and performance are also worth a thought. If you suddenly get mentioned on the front page of HackerNews, do you have sufficient monitoring and maintenance capability to handle the traffic spike? Or the more negative potentiality, where a rogue player notices the spamming opportunities of your growing marketplace. What if a plugin fails, or if online payment or data security regulation changes? 

Everything I’ve said about customizability and developer experience applies here, too. If it’s possible, avoid creating a situation where scaling your business will require building a completely new platform from scratch. 

How big is the upfront investment?

The price range in marketplace PHP scripts is big – from a few bucks to several thousands of dollars per project. The bigger the upfront investment, the more careful I’d be with finding answers to the questions I’ve listed above.

Another challenge of the one-time fee model is that PHP scripts can get outdated quite fast. Are maintenance and updates included in the one-off fee, or are you responsible for the entire codebase after you’ve bought it? If something breaks and fixing it is not included in the fee, how big a hit will your budget take?

Subscription-based models have one advantage over one-off fees: the marketplace software provider has skin in the game. To retain your business, it’s in the software partner’s best interest to maintain your platform at top performance level and add updates that boost your growth. 

Is the script your fastest way to launch?

As I mentioned earlier, most entrepreneurs will benefit from launching their business as fast as possible. That gives them the opportunity to validate their idea before spending months building, find out what works and what doesn’t, and iterate if needed.

If fast validation is your goal, starting with a no-code marketplace SaaS tool is an option worth considering. Our former customer Mike chose this route over alternatives that required coding exactly because he wanted to optimize for speed. He launched his music studio rental platform on Sharetribe's earlier no-code product Sharetribe Go in one evening, posted to Product Hunt a week later, and got his first 1,000 users in a matter of hours.

Launch your marketplace as fast as possible.

Sometimes, the features of no-code tools aren’t enough. A future-proof solution like Sharetribe might then be a great alternative to a PHP script. That's also what Mike chose – after validating his idea, he moved his platform to Sharetribe Flex, the predecessor of our current marketplace software, to grow it further.

If you’re interested in giving Sharetribe a try, you can sign up and test and build your marketplace with a 14-day free trial. We won’t ask for your credit card details until your trial runs out – or until you're ready to open your site to actual users. 

In addition to the marketplace backend, Sharetribe offers a customizable website template built with Javascript, React, and Node.js. You can build a marketplace with Sharetribe completely no-code and later build custom functionality and design on top of your Sharetribe marketplace.

If you’re interested in trying Sharetribe with PHP, you can also build your PHP-based web app from scratch (with the help of our design files, if you like) and connect it with the Sharetribe-powered backend.

Next, I’ll go through this process step by step and share a code example for calling Sharetribe’s marketplace API with PHP.

Chapter 3

How to build a marketplace with Sharetribe + PHP

My step-by-step guide + a full copy-pasteable PHP code example


Sharetribe gives you all the essential marketplace features out of the box. These include a flexible transaction engine, secure online payments, customizable data storage, a powerful set of marketplace admin features, and more.

You can take the backend to use by building a marketplace user interface in PHP and connecting it with the backend through Sharetribe’s Marketplace API. Here’s how.

Install PHP

Start by installing PHP locally. Install the latest version 8, or at least version 7, which contains significant performance improvements compared to the earlier versions.

If you were building a marketplace with PHP from scratch or with a script, at this point you’d need to set up your database and configure email sending. 

With Sharetribe, you don’t need a database. The Sharetribe API handles storing large images, listings, users, transactions etc. In addition, Sharetribe provides extended data to store data that is specific to your marketplace type. You can go really far without ever needing your own database.

Choose your framework (example: Laravel)

PHP has a wide variety of frameworks available. I recommend using a PHP framework for several reasons: 

  • PHP frameworks have good documentation available.
  • PHP frameworks have built-in security features.
  • Coding conventions, directory structure, and so on are pre-built, so you don't need to start completely from scratch.
  • Most frameworks contain features that you will need when building your marketplace front-end, such as routing, view templates, sessions (cookie data management), data validations, error handling, and logging.

Laravel is a popular PHP framework that contains the important features I listed above. It offers a minimal API around the Guzzle HTTP client, which you can use to interact with the Sharetribe API.

Use a PHP framework to speed up development.

Another benefit of Laravel is that it’s a full stack framework. It has support for rendering the views with Blade templates or Inertia.js. For example, Inertia lets you build a marketplace application that feels like a single-page application, with fast page changes without full page reload, without the complexity of having to actually build one. 

I won’t go into the details of using Laravel in this article (check out their great documentation for more info). But later in the code example, I’ll demonstrate how to call Sharetribe API directly with the Guzzle HTTP client. The example should be fairly easy to convert to use Lavarel's Guzzle HTTP Client facade.

Build your PHP marketplace user interface

Sharetribe offers you a JSON API that you can use with PHP. Through the API, you’ll have access to all of Sharetribe's powerful marketplace features. 

The thing that is left for you to build in PHP is the marketplace UI. With a good PHP framework, the process of building the MVP marketplace UI can be quite fast with a good PHP framework.

On the UI side, a few elements you’ll definitely need from day one include:

  • User login, sign up, password reset
  • Posting a new listing
  • Listing editing
  • Listing search and listing details
  • Transaction/messaging/payment UI.

In addition, you might already want to build:

  • User profile editing
  • Landing page
  • User Inbox
  • Static pages, i.e. About, Privacy, Terms of Services.

Naturally, you’ll need a nice design for your UI. Here, we can offer you a shortcut. Take a look at Sharetribe’s marketplace web app design files in Sketch and copy as much as you like!

Screenshot of the design application Sketch with layouts for a mobile marketplace UI.
Example of a Sharetribe marketplace's mobile UI design files on the design tool app Sketch.

How to use the Sharetribe API from PHP

In these examples, we'll use a popular Guzzle HTTP client. When using Laravel, you can use Lavarel's HTTP client facade, which uses Guzzle Client under the hood. For the purpose of this article, we'll install Guzzle directly with composer.

composer require guzzlehttp/guzzle:^7.0

First, head to sharetribe.com and sign up for a Sharetribe account. The sign-up only takes a few seconds, and you get the 14-day free trial without any payment commitment.

After you've created the Sharetribe account, you will be redirected to Console. Head to the Advanced > Applications page, where you can add a new application and get your marketplace's unique Client ID.

After you have installed Guzzle, you need to require it, set your marketplace's unique client ID, and create a new Guzzle client instance. Here's how:

require 'vendor/autoload.php';
use GuzzleHttp\Client;

// The client-id to identify your marketplace
// The client-id looks like this: 91d81bb4-8261-431d-9eb2-4202900919a6
$client_id = "YOUR CLIENT ID HERE";

// Initialize Authentication API client
$auth_api = new Client([
    'base_uri' => 'https://flex-api.sharetribe.com/v1/auth/',
    'debug' => true,
    'headers' => ['Accept' => 'application/json']
]);

Now that you have an HTTP client that you can use to call the Authentication API, you need to authenticate. Every request to Sharetribe’s API needs to be authenticated by an authentication token. Here's how to issue an authentication token for an anonymous user:

$response = $auth_api->post('token',
                            ['form_params' =>
                             ['client_id' => $client_id,
                              'grant_type' => 'client_credentials',
                              'scope' => 'public_read']]);

$body = json_decode($response->getBody());
$anon_access_token = $body->access_token;

API Response:

{
    "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtYXJrZXRwbGFjZS1pZCI6IjYwNDIxNTI3LTljMDctNDc5ZS1iN2I3LTE0YmY1MmUxMzNhZiIsImNsaWVudC1pZCI6IjkxZDgxYmI0LTg4NjEtNDMxZC05ZWIyLTQyMDA5MDA5ZTlhNiIsInRlbmFuY3ktaWQiOiI2MDQyMTUyNy05YzA3LTQ3OWUtYjdiNy0xNGJmNTJlMTMzYWYiLCJzY29wZSI6InB1YmxpYy1yZWFkIiwiZXhwIjoxNjE2Nzg1NTI1fQ.dYH-vvmhxLjg8RHGj0skHs1p6FsQGsW4aY71PwM3C6A",
    "scope": "public-read",
    "token_type": "bearer",
    "expires_in": 86400
}

We called the Authentication API to issue an access token and stored it to $anon_access_token variable. 

Now that you have the access token, you can use it to make requests to the Marketplace API. But first, we need to initialize a Marketplace API client the same way we did for Authentication API:

$mp_api_anon = new Client([
    'base_uri' => 'https://flex-api.sharetribe.com/v1/api/',
    'debug' => true,
    'headers' => ['Accept' => 'application/json',
                  'Authorization' => 'Bearer ' . $anon_access_token]]);

The newly-created Marketplace API client uses the anonymous access token to authenticate itself.

Now, let's use the new Marketplace API to query all listings in the marketplace:

$response = $mp_api_anon->get('listings/query');
$body = json_decode($response->getBody());
echo(json_encode($body, JSON_PRETTY_PRINT));

API Response:

{
    "data": [],
    "meta": {
        "totalItems": 0,
        "totalPages": 0,
        "page": 1,
        "perPage": 100
    }
}

As you can see, the marketplace doesn't have any listings yet. So let's create some! But before that, we need to sign up as a user who will become the seller of that new listing.

First, we'll create the user. Let's call him John:

$response = $mp_api_anon->post('current_user/create',
                               ['json' =>
                                ['firstName' => 'John',
                                 'lastName' => 'Doe',
                                 'email' => 'john.doe@example.com.invalid',
                                 'password' => 'secret-password']]);

After that, we'll log John in. This needs again the Authentication API:


$response = $auth_api->post('token',
                            ['form_params' =>
                             ['client_id' => $client_id,
                              'grant_type' => 'password',
                              'scope' => 'user',
                              'username' => 'john.doe@example.com.invalid',
                              'password' => 'secret-password']]);

$body = json_decode($response->getBody());
echo(json_encode($body, JSON_PRETTY_PRINT));
$john_access_token = $body->access_token;
$john_refresh_token = $body->access_token;

API Response:

{
    "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJtYXJrZXRwbGFjZS1pZCI6IjYwNDIxNTI3LTljMDctNDc5ZS1iN2I3LTE0YmY1MmUxMzNhZiIsImNsaWVudC1pZCI6IjkxZDgxYmI0LTg4NjEtNDMxZC05ZWIyLTQyMDA5MDA5ZTlhNiIsInRlbmFuY3ktaWQiOiI2MDQyMTUyNy05YzA3LTQ3OWUtYjdiNy0xNGJmNTJlMTMzYWYiLCJzY29wZSI6InVzZXIiLCJleHAiOjE2MTY3MDAxMzUsInVzZXItaWQiOiI2MDU5ZmYxMi1kYmNmLTRhYmYtYmFiOS03NDVlYWJhNGY0OWUiLCJ1c2VyLXJvbGVzIjpbInVzZXIucm9sZS9wcm92aWRlciIsInVzZXIucm9sZS9jdXN0b21lciJdfQ.KgG1N1_L6YgIP5qvbL4S7fF1ZQRPoWBWhgO6lb2R8fQ",
    "scope": "user",
    "token_type": "bearer",
    "expires_in": 600,
    "refresh_token": "v2--ce1c9777-33f1-425b-9661-4ce1690be6c2--d83cf09a50e9239f3458a8dea28134b241c33e10"
}

In the example above, we logged in as John using his email and password. In the response, we received the access token and stored it to the $john_access_token variable. We will use this token to make subsequent requests as John. In addition, we received a refresh token. The access token is valid for 10 minutes only. After that, you need to issue a new access token using the refresh token.

Now that we have an access token for John, we can again make a new Marketplace API client that will call the API as John.

$mp_api_john = new Client([
    'base_uri' => 'https://flex-api.sharetribe.com/v1/api/',
    'debug' => true,
    'http_errors' => false,
    'headers' => ['Accept' => 'application/json',
                  'Authorization' => 'Bearer ' . $john_access_token]]);

Next, we can create a new listings. Let's imagine our marketplace is a sauna rental marketplace. An API call to create a new sauna listing might look like this:

$response = $mp_api_john->post('own_listings/create',
                               ['json' =>
                                ['title' => 'Sauna by the sea',
                                 'description' =>
                                 'A lovely public wooden sauna by the sea. ' .
                                 'Open from Monday to Friday. ' .
                                 'Each day, we have room for 10 people, ' .
                                 'except on Fridays where we heat the other ' .
                                 'sauna nearby and have room for 20 people. ' .
                                 'The price is 20 EUR per person',
                                 'geolocation' => [
                                     'lat' => 60.160872,
                                     'lng' => 24.853492
                                 ],
                                 'availabilityPlan' => [
                                     'type' => 'availability-plan/day',
                                     'entries' => [
                                         ['dayOfWeek' => 'mon', 'seats' => 10],
                                         ['dayOfWeek' => 'tue', 'seats' => 10],
                                         ['dayOfWeek' => 'wed', 'seats' => 10],
                                         ['dayOfWeek' => 'thu', 'seats' => 10],
                                         ['dayOfWeek' => 'fri', 'seats' => 20]
                                     ]
                                 ],
                                 'price' => [
                                     'amount' => 2000,
                                     'currency' => 'USD'
                                 ],
                                 'publicData' => [
                                     'address' => [
                                         'country' => 'Finland',
                                         'city' => 'Helsinki',
                                         'postalCode' => '00200',
                                         'street' => 'Vaskiniemi road'],
                                     'amenities' => [
                                         'towels-for-rent',
                                         'shower',
                                         'by-the-sea']]]]);

$body = json_decode($response->getBody());
echo(json_encode($body, JSON_PRETTY_PRINT));

In the API call above, we created a new sauna listing for John with quite a bit of details. The listings has a title, description, location, availability plan, price and some additional free-form data (called Extended data) for address and amenities.

The availability plan describes a listings default weekly availability. In this case, the sauna is open from Monday to Friday and it has room for 10 people. Except on Friday, when there's extra room, for 20 people in total.

Now, let's try to search some listings again. This time, we'll add some search parameters. We want to find a sauna for next Monday with enough room for 15 people:

$response = $mp_api_john->get('listings/query',
                              ['query' =>
                               ['start' => date("c", strtotime('next Monday')),
                                'end' => date("c", strtotime('next Tuesday')),
                                'seats' => 15]]);

$body = json_decode($response->getBody());
echo(json_encode($body, JSON_PRETTY_PRINT));

API Response:

{
    "data": [],
    "meta": {
        "totalItems": 0,
        "totalPages": 0,
        "page": 1,
        "perPage": 100
    }
}

Even though we just created a new listing, the listing search returns an empty set of search results. The reason is that our newly added listing only has room for 10 people on Mondays  according to its availability plan.

So let's try to tweak the search a bit. Since we need to find a sauna for 15 people, we might try to reschedule the sauna event a bit. Would there be saunas that could fit 15 people next Friday? Let's try:

$response = $mp_api_john->get('listings/query',
                              ['query' =>
                               ['start' => date("c", strtotime('next Friday')),
                                'end' => date("c", strtotime('next Saturday')),
                                'seats' => 15]]);

$body = json_decode($response->getBody());
echo(json_encode($body, JSON_PRETTY_PRINT));

API Response:

{
    "data": [
        {
            "id": "605ccbfb-7ceb-4d2b-a8df-2948e58b62e6",
            "type": "listing",
            "attributes": {
                "description": "A lovely public wooden sauna by the sea. Open from Monday to Friday. Each day, we have room for 10 people, except on Fridays where we heat the other sauna nearby and have room for 20 people. The price is 20 EUR per person",
                "deleted": false,
                "geolocation": {
                    "lat": 60.160873,
                    "lng": 24.853493
                },
                "createdAt": "2021-03-25T17:44:27.415Z",
                "state": "published",
                "title": "Sauna by the sea",
                "availabilityPlan": {
                    "type": "availability-plan\/day"
                },
                "publicData": {
                    "address": {
                        "city": "Helsinki",
                        "country": "Finland",
                        "postalCode": "00200",
                        "street": "Vaskiniemi road"
                    },
                    "amenities": [
                        "towels-for-rent",
                        "shower",
                        "by-the-sea"
                    ]
                },
                "price": {
                    "amount": 2000,
                    "currency": "USD"
                },
                "metadata": {}
            }
        }
    ],
    "meta": {
        "totalItems": 1,
        "totalPages": 1,
        "page": 1,
        "perPage": 100
    }
}

There we go! We found our sauna, since it now matches the search criteria. There are plenty of other search parameters available, e.g. search by keyword, location, price etc.

This was a quick introduction how to use Sharetribe API from PHP. Please have a look at the API reference document for full documentation about all the available endpoints.

Launch your marketplace!

After you’ve built your marketplace user interface in PHP and connected it with the Sharetribe backend, it’s time to go live. It's now time to upgrade your Build plan to a live plan, the prices of which start at $99/month.

Building a marketplace is a process, not a project.

Before going live, you need to pick a web hosting for your PHP user interface. Sharetribe takes care of hosting the backend. There are plenty of PHP web hosting services available, most of them quite affordable. We at Sharetribe have had a good experience with Heroku, so their PHP hosting is our recommendation. 

Building a marketplace is a process, not a project. The launch is only the beginning! My colleagues in Sharetribe’s support are there for you every step of the way. We also have a big library of resources that offer practical advice for different stages of your marketplace journey. A good starting point is our How to build a marketplace guide.

Chapter 4

Conclusion: Start building your marketplace

My final piece of advice: start today.


In this article, I’ve listed several reasons why PHP marketplace scripts and software are popular solutions for building an online marketplace. I’ve also listed some challenges you might encounter while choosing a script and tried to give advice that will help you choose the best possible marketplace solution for your business.

Naturally, I hope you’ll give Sharetribe a try and test the code examples I’ve written in action (if you do, let us know how that worked out – that’s @sharetribe on Twitter).

Whichever approach you choose, my final word of advice would be: start today. Whether it’s checking out a script or creating one free trial, that’s a great start that already moves your thinking forward. Building a marketplace may seem like a daunting task, so commit to an iterative process of building, learning, and improving. Launch fast, learn fast, and validate as you go. 

Best of luck with your marketplace project!

Start your 14-day free trial

Create a marketplace today!

  • Launch quickly, without coding
  • Extend infinitely
  • Scale to any size
Start free trial

No credit card required