Skip to main content

Installing the addon

In the following section, we assume that you have already set up a partner e-shop and have been approved as a Shoptet API partner. For the purposes of this example, the partner e-shop URL will be https://12345.myshoptet.com.

Used terms​

OAuth access token
A unique string representing each individual installation of your addon in an e-shop. It is required to obtain an API access token. It has unlimited validity and is 255 characters long.

code
A string sent as a GET parameter to your specified URL (as set in the addon settings). It is valid for 30 seconds and can be used only once.

API access token
A string used to access the Shoptet API. It has limited-time validity and its length ranges from 38 to 60 characters. You can obtain an API access token by making an authorized request to the OAuth server. This authorization is carried out using the OAuth access token, which you receive from the e-shop during the installation process described below.

How to obtain an OAuth access token​

For each individual installation of the addon, you need to obtain an OAuth access token and store it securely in your data structures. The OAuth access token uniquely identifies both the e-shop and the addon. It is obtained only once for each e-shop and addon, during installation.

Process of obtaining the OAuth access token:

  • When an e-shop installs your addon, you will receive an HTTP request containing a code GET parameter. The URL to which these requests are sent is specified in the addon settings (Partner e-shop administration → Connections → API Partner → Addons tab). URLs with ports 80, 8080, 443, and 8443 are permitted.

  • Use the code value to authorize with the OAuth server. In response, you will receive an OAuth access token, which is then used to obtain API access tokens.

note

Attention: Your server must respond with HTTP status 200 to the code request if the installation is successful. If your server does not respond with status 200, we consider the installation process to have failed.

Installation calls from Shoptet are only sent from the IP range 185.184.254.0/24.

An example of obtaining the OAuth access token in PHP​

In the addon detail (Partner e-shop administration → Connections → API Partner → Addons tab), under the Settings tab, enter the URL in the Your URL to receive OAuth code field. This is the URL where you expect to receive the request containing the code parameter — for example: https://www.my-server.com/shoptet-installation

When you install the addon, your server will receive an HTTP GET request to the specified URL with the code parameter, for example: https://www.my-server.com/shoptet-installation?code=21cc615b4a01067a75713dd1396057bf96bd925c

Once you have obtained the code parameter, use it to authorize with the OAuth server API and retrieve the OAuth access token.

// Your client ID in the OAuth server
// This is an example only. For a specific value,
// refer to Partner e-shop administration → Connections → API Partner → Access to API
$clientId = 'ae5d72b8964a08ed';

// Your secret string for communicating with the OAuth server
// If, in Partner e-shop administration → Connections → API Partner → Access to API,
// you do not see the value, clientSecret has not been activated (older API partners),
// so do not send it in communication with the OAuth server
$clientSecret = 'dqwffewfsgdrgwefsfgdtjtkyodg';

// OAuth server URL for authorization
// This is an example only. For a specific value,
// refer to Partner e-shop administration → Connections → API Partner → Access to API
$oAuthServerTokenUrl = 'https://12345.myshoptet.com/action/ApiOAuthServer/token';

// Received value of code
$code = $_GET['code'];

// OAuth server authorization type, always enter 'authorization_code'
$grantType = 'authorization_code';

// OAuth server rights group, always enter 'api'
$scope = 'api';

// URL entered on the addon settings page, where you expect the request with the 'code' parameter, for example:
$redirectUri = 'https://www.my-server.com/shoptet-installation';

// Send the request to obtain the OAuth access token
$data = [
'client_id' => $clientId,
'client_secret' => $clientSecret, // Enter only if set for you
'code' => $code,
'grant_type' => $grantType,
'redirect_uri' => $redirectUri,
'scope' => $scope,
];
$curl = curl_init($oAuthServerTokenUrl);
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-type: application/json']);
$response = curl_exec($curl);
curl_close($curl);

The response $response is in JSON format:

{
"access_token":"5wty54dv2y5jxaj9lu2glnb6upv2z7a6b3v92xsy06wfaeygmcfa3alg2gx2rdp8ozjqytb3l4eqfub4nbnbm7somfgup58wf6jjjstwyvdtp3kjmh08nhskl0z06qyso27l0q6op5udooofq15zhq7w3h1k4b6jj0j4o83hyar2fu9847e802t56xa87v81lblzed5kgvutjzrp3afvpsefit304q6g3pat0m09pzbd5iyu0qk55zwu6a31sq9",
"expires_in": null,
"token_type": "bearer",
"scope": "api",
"eshopId": 222651,
"eshopUrl": "https:\/\/12345.myshoptet.com\/",
"contactEmail": "customer@example.com",
"trial": false
}

The $response contains the access_token (the OAuth access token), which you use to authorize yourself and obtain API access tokens.

$response = json_decode($response, TRUE);
echo "oAuth access token: " . $response['access_token'];
$oAuthAccessToken = $response['access_token'];

Save the value of $oAuthAccessToken, which is unique for each addon installation. Once you acquire and store the OAuth access token, the installation process is complete.

If you are able to save the OAuth access token, respond to the HTTP request with 200 OK. In the default PHP configuration, you should be able to exit the script without setting a return value manually.

The eshopId, eshopUrl, contactEmail, and trial fields contain basic information about the e-shop where the addon is being installed (trial tells you whether the e-shop is still in its trial period). For more details, use the E-shop info endpoint (see also Identity of an e-shop below). Even if the installation fails, you still have some basic data that may help you complete the installation later or contact the customer.

Basic examples of an installation script:

Unsuccessful installation​

We consider the installation of the addon unsuccessful if, upon the request with the code:

  • your server does not accept the connection within 5 seconds, or does not respond within 15 seconds in total, or
  • you respond with an HTTP status code other than 200, or
  • you do not exchange the code for the OAuth access token while handling the request.

If the installation fails, the code is invalidated, and any OAuth access token already issued for it is revoked.

Testing the installation​

For testing purposes, open the Test installation tab in the detail of the addon. There you can invoke the installation procedure on your partner e-shop, or create a test API access token without implementing the installation procedure at all.

Identity of an e-shop​

A new client initiates the installation process anonymously (you receive only basic information about the e-shop along with the OAuth access token). It is essential to extract this key information and store it securely. The OAuth access token and short-term API access tokens are always linked to a specific e-shop, which allows you to identify it reliably.

A common practice after the installation is to request an API access token and call the E-shop info endpoint. You can then store the OAuth access token together with the e-shop’s ID (data.contactInformation.eshopId), URL (data.contactInformation.url), contact email, and other relevant details.

It is recommended that the installation routine performs only a single action to keep the duration as short as possible and minimize the risk of errors. Ideally, you should just obtain the OAuth access token, store it securely, and exit the installation script. The e-shop identification and any further processing should be handled asynchronously.

Do not send an email as part of the installation script, as this could significantly increase the execution time. This degrades the user experience, and if the installation takes longer than 15 seconds, we will consider it unsuccessful.

Reinstalling​

You must also account for the case where the e-shop operator uninstalls the addon and later decides to reinstall it. Without proper handling, this may lead to issues such as duplicate accounts or conflicting data. For more information, see Uninstalling the addon.

Pausing and resuming addons​

In rare cases, an OAuth access token can be paused: the addon remains installed and billing continues, but API requests are rejected. For more information, see Pausing and resuming addons.