Publisher Integration
Getting Started

Overview of Website Access

Linkbest API provides a range of functionalities that allow publishers to effectively monetize their traffic and optimize their advertising strategies. By integrating with this API, publishers can:

  • Access Advertising Campaigns: Retrieve detailed information about available advertising campaigns, including campaign descriptions, commission rates, and promotional materials.
  • Generate Affiliate Links: Generate unique affiliate links for specific products or promotions, enabling publishers to track referrals and earn commissions for successful sales.
  • Track Conversions: Monitor and track conversions generated through affiliate links, allowing publishers to measure the effectiveness of their promotional efforts and optimize their marketing strategies.
  • Get Earnings and Statistics Data: Real-time access to earnings and performance statistics such as click counts, conversions, and commissions, to understand the performance and revenue of advertising campaigns.

Integration Steps

1. Create the App Key

After registering and logging in to Linkbest, go to "My Tools - API", click "Add" to create your App Key. View API Integration Documentation

getting-started

2. Request Interface Requirements

  • Encoding Requirement: The data sent must be encoded in UTF-8.

  • Request Method: POST

  • HTTP Content-Type Requirement: When encoding the request body as form data, set the HTTP Content-Type header to application/x-www-form-urlencoded. If encoding the request body as JSON, set it to application/json. If you need to upload files as part of the request, use multipart/form-data.

  • Linkbest API Endpoint:

    https://api.linkbest.com
  • Request Parameter Format Requirements:

    Parameter TypeFormat Requirements
    string255 UTF-8 characters
    decimal8 digits, 2 decimal places
    datetimeISO-8601 (e.g., 2022-12-11T11:10:01-07:00)
    currencyISO-4217 (e.g., USD)
    integer16 digits

3. Signature Authentication

Below is an example of calling the Get Promotion Conversion Links (linkbest.service.links.post) interface.

Parameter Example

// Public parameters
app_key=5435967&timestamp=1692696195&service=linkbest.service.links.post
// API parameters
{"url":"https://www.example.com","site_id":"1026"}

1. Concatenate the public parameters in alphabetical

{"Timestamp":"1692696195","Url":"https://www.example.com","WebsiteId":"1026"}

2. Append the post request JSON parameters

/AppKey/linkbest.service.links.post{"Timestamp":"1692696195","Url":"https://www.example.com","WebsiteId":"1026"}

3. Append the app_secret

AppSecret/AppKey/linkbest.service.links.post{"Timestamp":"1692696195","Url":"https://www.example.com","WebsiteId":"1026"}AppSecret

4. MD5 hash the resulting signature string and convert it to uppercase to obtain the sign parameter

B442F34C01D716A563F30828C03A4351

5. Set the HTTP request headers and use the API parameters as the JSON body

{"Timestamp":"1692696195","Url":"https://www.example.com","WebsiteId":"1026","Sign":"11bf6f13de0d6e95d74b9b2210d95acb"}

4. Request Example

cURL Example
# Example curl command
curl -X POST https://api.linkbest.com/{APP_KEY}/{SERVICE_NAME} \
    -H 'Content-Type: application/x-www-form-urlencoded' \
    -d 'sign=**********' \
    -d 'app_key=**********' \
    -d 'timestamp=**********' \
    -d 'service=**********' 
php Request Example
   $AppKey = "your key";
   $AppSecret = "your secret";
 
   $header = [
       "Content-Type" => "application/json"
   ];
   $Url = "/{$AppKey}/linkbest.service.links.post";
   $Body = [
       "Timestamp" => time(),
       "Url"=> "https://www.example.com",
       "WebsiteId" => "your website id"
   ];
   ksort($Body);
   $SignStr = json_encode($Body, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_HEX_AMP);
   $body["Sign"] = strtoupper(md5($AppSecret . $Url . $SignStr . $AppSecret));
   try {
       $client = new \GuzzleHttp\Client();
       $response = $client->request('POST', sprintf("%s%s", 'https://api.linkbest.com', $Url), [
           "verify" => false,
           "headers" => $header,
           "body" => json_encode($body, JSON_UNESCAPED_UNICODE)
       ]);
   } catch (ClientException $e) {
       $response = $e->getResponse();
   }
   echo $response->getStatusCode();
   echo $response->getHeaderLine('content-type');
   echo $response->getBody()->getContents();
golang Request Example
package main

import (
	"crypto/md5"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/http"
	"sort"
	"strings"
	"time"
)

func main() {
	AppKey := "your key"
	AppSecret := "your secret"

	Url := fmt.Sprintf("/%s/linkbest.open-service.orders.query.get", AppKey)
	Body := map[string]interface{}{
		"Timestamp": time.Now().Unix(),
		"Stime":     time.Now().Unix(),
		"Etime":     time.Now().Unix(),
	}

	// sort keys
	BodyKeys := make([]string, 0, len(Body))
	for k := range Body {
		BodyKeys = append(BodyKeys, k)
	}
	sort.Strings(BodyKeys)

	sortedMap := make(map[string]interface{})
	for _, k := range BodyKeys {
		sortedMap[k] = Body[k]
	}

	bodyStr, _ := json.Marshal(sortedMap)

	fmt.Println(string(bodyStr))

	Sign := fmt.Sprintf("%X", md5.Sum([]byte(AppSecret+Url+string(bodyStr)+AppSecret)))
	Body["Sign"] = Sign

	client := &http.Client{}

	bodyStr, _ = json.Marshal(Body)
	req, err := http.NewRequest("POST", fmt.Sprintf("%s%s", "https://api.linkbest.com", Url), strings.NewReader(string(bodyStr)))
	if err != nil {
		fmt.Println("Error creating request:", err)
		return
	}
	req.Header.Set("Content-Type", "application/json")
	resp, err := client.Do(req)
	if err != nil {
		fmt.Println("Error sending request:", err)
		return
	}
	defer resp.Body.Close()
	body, err := io.ReadAll(resp.Body)
	if err != nil {
		fmt.Println("Error reading response:", err)
		return
	}
	fmt.Println("Status Code:", resp.StatusCode)
	fmt.Println("Content-Type:", resp.Header.Get("Content-Type"))
	fmt.Println("Response:", string(body))
}
java Request Example
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.*;

public class Main {
  public static void main(String[] args) throws JsonProcessingException {
    String appKey = "your key";
    String appSecret = "your secret";
    String url = "/" + appKey + "/linkbest.open-service.orders.query.get";
    Map<String, Object> body = new TreeMap<>();
    body.put("Timestamp", new Date().getTime() / 1000);
    body.put("Stime", new Date().getTime() / 1000);
    body.put("Etime", new Date().getTime() / 1000);

    ObjectMapper objectMapper = new ObjectMapper();
    String signStr = objectMapper.writeValueAsString(body);
    String sign = md5(appSecret + url + signStr + appSecret);
    body.put("Sign", sign);

    System.out.println(signStr);
    System.out.println(sign);

    try {
      URI uri = new URI("https://api.linkbest.com" + url);
      HttpRequest request =
          HttpRequest.newBuilder()
              .uri(uri)
              .header("Content-Type", "application/json")
              .POST(HttpRequest.BodyPublishers.ofString(objectMapper.writeValueAsString(body)))
              .build();
      String result =
          HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString()).body();

      System.out.println(result);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  private static String md5(String input) {
    try {
      MessageDigest md = MessageDigest.getInstance("MD5");
      byte[] messageDigest = md.digest(input.getBytes());
      StringBuilder hexString = new StringBuilder();
      for (byte b : messageDigest) {
        hexString.append(String.format("%02X", b));
      }
      return hexString.toString();
    } catch (NoSuchAlgorithmException e) {
      e.printStackTrace();
      return null;
    }
  }
}

5. Error Handling

There may be cases where the API request fails due to various reasons. When an error is returned, the system will provide a message indicating more detailed information about the failure. Adjust your request based on this information and retry, or contact our integration engineer for assistance. Please refer to the Error Codes for more details.