Esc
Start typing to search...

Authentication and Token Retrieval

User Login #

To make requests to marketplace services, you first need to obtain a token via the authentication service.

This token will be used in the Authorization header in all other API requests.

Authenticate Service #

Endpoint Information #

TEST Environment:

POST https://apitest.paynkolay.com.tr/marketplace/v1/authenticate

PROD Environment:

POST https://api.paynkolay.com.tr/marketplace/v1/authenticate

Request Parameters #

{
  "username": "nkolay_marketplace",
  "password": "nkolaypassword",
  "merchantNo": "400000904"
}

Parameter Descriptions #

ParameterTypeRequiredDescription
usernameStringUsername created for you
passwordStringPassword created for you
merchantNoStringMerchant number created for you

Response Format #

After a successful authentication, you will receive a response like this:

{
  "success": true,
  "responseCode": "200",
  "responseMessage": "SUCCESS",
  "data": {
    "token": "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJua29sYXlfbWFya2V0cGxhY2UiLCJleHAiOjE3NjI5NDY0NTYsImlhdCI6MTc2Mjk0NDY1Nn0.KzUrZmGymeI0Tzqss8XNJzWrCrVmPEtcbep1hXDpqxZ4ALHNk3DQoepdVWWsXs6gnhj3njWgk2klHcrBfn2OLw"
  }
}

Response Parameters #

ParameterTypeDescription
successBooleanIndicates whether the operation was successful
responseCodeStringOperation result code (200 = Successful)
responseMessageStringOperation result message
data.tokenStringAccess token in JWT format (to be used as Bearer token)

Token Usage #

You should use the token you received as a Bearer Token in the Authorization header in other API requests.

Example Usage #

curl -X POST https://apitest.paynkolay.com.tr/marketplace/v1/seller/get \
  -H "Authorization: Bearer eyJhbGciOiJIUzUxMiJ9..." \
  -H "Content-Type: application/json" \
  -d '{
    "sellerExternalId": "SELLER123"
  }'

JavaScript/TypeScript Example #

// Token alma
const getToken = async () => {
  const response = await fetch(
    'https://apitest.paynkolay.com.tr/marketplace/v1/authenticate',
    {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        username: process.env.MARKETPLACE_USERNAME,
        password: process.env.MARKETPLACE_PASSWORD,
        merchantNo: process.env.MARKETPLACE_MERCHANT_NO,
      }),
    }
  );

  const data = await response.json();
  return data.data.token;
};

// Token ile API çağrısı
const callAPI = async (token) => {
  const response = await fetch(
    'https://apitest.paynkolay.com.tr/marketplace/v1/seller/get',
    {
      method: 'POST',
      headers: {
        'Authorization': `Bearer ${token}`,
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        sellerExternalId: 'SELLER123',
      }),
    }
  );

  return await response.json();
};

PHP Example #

<?php
// Token alma
function getToken($username, $password, $merchantNo) {
    $url = 'https://apitest.paynkolay.com.tr/marketplace/v1/authenticate';

    $data = [
        'username' => $username,
        'password' => $password,
        'merchantNo' => $merchantNo
    ];

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        'Content-Type: application/json'
    ]);

    $response = curl_exec($ch);
    curl_close($ch);

    $result = json_decode($response, true);
    return $result['data']['token'];
}

// Token ile API çağrısı
function callAPI($token, $sellerExternalId) {
    $url = 'https://apitest.paynkolay.com.tr/marketplace/v1/seller/get';

    $data = [
        'sellerExternalId' => $sellerExternalId
    ];

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        'Authorization: Bearer ' . $token,
        'Content-Type: application/json'
    ]);

    $response = curl_exec($ch);
    curl_close($ch);

    return json_decode($response, true);
}

// Kullanım
$token = getToken(
    getenv('MARKETPLACE_USERNAME'),
    getenv('MARKETPLACE_PASSWORD'),
    getenv('MARKETPLACE_MERCHANT_NO')
);

$result = callAPI($token, 'SELLER123');
?>

Token Management #

Token Expiration #

  • JWT tokens expire after a certain period
  • The token's exp (expiration) claim contains the validity period
  • When the token becomes invalid, you need to obtain a new token

Best Practices #

  • Cache the Token: Instead of getting a new token for every API request, use the existing token
  • Token Refresh: Obtain a new token before the current one expires
  • Error Handling: Refresh the token when you receive a 401 Unauthorized error
  • Secure Storage: Store tokens securely (memory, secure storage)

Token Refresh Example #

class MarketplaceAPIClient {
  constructor(username, password, merchantNo) {
    this.credentials = { username, password, merchantNo };
    this.token = null;
    this.tokenExpiry = null;
  }

  async ensureValidToken() {
    // Token yoksa veya süresi dolmuşsa yeni al
    if (!this.token || Date.now() >= this.tokenExpiry) {
      await this.refreshToken();
    }
    return this.token;
  }

  async refreshToken() {
    const response = await fetch(
      'https://apitest.paynkolay.com.tr/marketplace/v1/authenticate',
      {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify(this.credentials),
      }
    );

    const data = await response.json();
    this.token = data.data.token;

    // JWT'den expiry time'ı parse et
    const payload = JSON.parse(atob(this.token.split('.')[1]));
    this.tokenExpiry = payload.exp * 1000; // milisaniyeye çevir
  }

  async callAPI(endpoint, body) {
    const token = await this.ensureValidToken();

    const response = await fetch(endpoint, {
      method: 'POST',
      headers: {
        'Authorization': `Bearer ${token}`,
        'Content-Type': 'application/json',
      },
      body: JSON.stringify(body),
    });

    // 401 hatası alırsak token'ı yenile ve tekrar dene
    if (response.status === 401) {
      await this.refreshToken();
      return this.callAPI(endpoint, body);
    }

    return await response.json();
  }
}

Security Keys #

Other important security keys used in the Marketplace API:

KeyDescriptionUsage
apiSecretKeySX value - Used for payment operationsPayment, Seller, Profile services
merchantSecretKeyUsed in hash calculation for payment operationsHash calculation
apiSecretKey (iptal)Special SX value for cancellation operationsCancel/Refund services

Next Steps #

After obtaining the token: