curl \
-H "Authorization: Bearer API_KEY" \
-H 'Content-Type: application/json' \
-d '{"url": "https://www.ayrshare.com", "utmSource": "google_ads"}' \
-X POST https://api.ayrshare.com/api/links
const API_KEY = "API_KEY";
fetch("https://api.ayrshare.com/api/links", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${API_KEY}`
},
body: JSON.stringify({
url: "https://www.ayrshare.com", // required
utmSource: "google_ads", // optional
}),
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
import requests
payload = {'url': 'https://www.ayrshare.com',
'utmSource': 'google_ads"}
headers = {'Content-Type': 'application/json',
'Authorization': 'Bearer API_KEY'}
r = requests.post('https://api.ayrshare.com/api/links',
json=payload,
headers=headers)
print(r.json())
require 'vendor/autoload.php';// Composer auto-loader using Guzzle. See .../guzzlephp.org/en/stable/overview.html
$client = new GuzzleHttp\Client();
$res = $client->request(
'POST',
'https://api.ayrshare.com/api/links',
[
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer API_KEY'
],
'json' => [
'url' => 'https://www.ayrshare.com',
'utmSource' => 'google_ads', // optional
]
]
);
echo json_encode(json_decode($res->getBody()), JSON_PRETTY_PRINT);
package main
import (
"bytes"
"encoding/json"
"log"
"net/http"
)
func main() {
message := map[string]interface{}{
"url": "https://www.ayrshare.com",
"utmSource": "google_ads",
}
bytesRepresentation, err := json.Marshal(message)
if err != nil {
log.Fatalln(err)
}
req, _ := http.NewRequest("POST", "https://api.ayrshare.com/api/links",
bytes.NewBuffer(bytesRepresentation))
req.Header.Add("Content-Type", "application/json; charset=UTF-8")
req.Header.Add("Authorization", "Bearer API_KEY")
res, err := http.DefaultClient.Do(req)
if err != nil {
log.Fatal("Error:", err)
}
res.Body.Close()
}
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace CreateShortLinkPOSTRequest_csharp
{
class CreateShortLink
{
private static readonly HttpClient client = new HttpClient();
static async Task Main(string[] args)
{
string API_KEY = "API_KEY";
string url = "https://api.ayrshare.com/api/analytics/links";
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + API_KEY);
string json = "{\"url\" : \"https://www.ayrshare.com\"," +
"\"utmSource\" :\"google_ads\"";
try
{
var content = new StringContent(json, Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PostAsync(url, content);
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
}
catch (HttpRequestException e)
{
Console.WriteLine($"Error: {e.Message}");
}
}
}
}
{
"created": "2023-07-17T15:20:51.118Z",
"id": "yC0fTl",
"originalUrl": "https://www.ayrshare.com/?utm_source=looking",
"shortUrl": "https://ayrs.io/yC0fTl",
"status": "success",
"utmSource": "looking"
}
{
"action": "request",
"status": "error",
"code": 126,
"message": "Shorten URL failed. Please verify the URL is properly formatted and the correct UTM parameters are used."
}
Links
Tạo Short Link
Cung cấp một URL và một liên kết đã được rút gọn sẽ được trả về.
POST
/
links
curl \
-H "Authorization: Bearer API_KEY" \
-H 'Content-Type: application/json' \
-d '{"url": "https://www.ayrshare.com", "utmSource": "google_ads"}' \
-X POST https://api.ayrshare.com/api/links
const API_KEY = "API_KEY";
fetch("https://api.ayrshare.com/api/links", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${API_KEY}`
},
body: JSON.stringify({
url: "https://www.ayrshare.com", // required
utmSource: "google_ads", // optional
}),
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
import requests
payload = {'url': 'https://www.ayrshare.com',
'utmSource': 'google_ads"}
headers = {'Content-Type': 'application/json',
'Authorization': 'Bearer API_KEY'}
r = requests.post('https://api.ayrshare.com/api/links',
json=payload,
headers=headers)
print(r.json())
require 'vendor/autoload.php';// Composer auto-loader using Guzzle. See .../guzzlephp.org/en/stable/overview.html
$client = new GuzzleHttp\Client();
$res = $client->request(
'POST',
'https://api.ayrshare.com/api/links',
[
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer API_KEY'
],
'json' => [
'url' => 'https://www.ayrshare.com',
'utmSource' => 'google_ads', // optional
]
]
);
echo json_encode(json_decode($res->getBody()), JSON_PRETTY_PRINT);
package main
import (
"bytes"
"encoding/json"
"log"
"net/http"
)
func main() {
message := map[string]interface{}{
"url": "https://www.ayrshare.com",
"utmSource": "google_ads",
}
bytesRepresentation, err := json.Marshal(message)
if err != nil {
log.Fatalln(err)
}
req, _ := http.NewRequest("POST", "https://api.ayrshare.com/api/links",
bytes.NewBuffer(bytesRepresentation))
req.Header.Add("Content-Type", "application/json; charset=UTF-8")
req.Header.Add("Authorization", "Bearer API_KEY")
res, err := http.DefaultClient.Do(req)
if err != nil {
log.Fatal("Error:", err)
}
res.Body.Close()
}
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace CreateShortLinkPOSTRequest_csharp
{
class CreateShortLink
{
private static readonly HttpClient client = new HttpClient();
static async Task Main(string[] args)
{
string API_KEY = "API_KEY";
string url = "https://api.ayrshare.com/api/analytics/links";
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + API_KEY);
string json = "{\"url\" : \"https://www.ayrshare.com\"," +
"\"utmSource\" :\"google_ads\"";
try
{
var content = new StringContent(json, Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PostAsync(url, content);
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
}
catch (HttpRequestException e)
{
Console.WriteLine($"Error: {e.Message}");
}
}
}
}
{
"created": "2023-07-17T15:20:51.118Z",
"id": "yC0fTl",
"originalUrl": "https://www.ayrshare.com/?utm_source=looking",
"shortUrl": "https://ayrs.io/yC0fTl",
"status": "success",
"utmSource": "looking"
}
{
"action": "request",
"status": "error",
"code": 126,
"message": "Shorten URL failed. Please verify the URL is properly formatted and the correct UTM parameters are used."
}
Cung cấp một URL và một liên kết đã được rút gọn sẽ được trả về. Sau đó có thể thu thập phân tích về số lượt nhấp, loại trình duyệt, v.v.
Việc gửi cùng một URL để rút gọn sẽ luôn dẫn đến cùng một liên kết rút gọn. Để tạo một liên kết rút gọn duy nhất cho cùng một URL, bạn có thể thêm các tham số truy vấn bổ sung vào URL đó. Ví dụ, thêm một mã định danh duy nhất như https://ayrshare.com?uniqueId=123 sẽ tạo ra một liên kết rút gọn khác biệt.
Bạn cũng có thể bao gồm các tham số UTM, chúng sẽ được nhúng trong liên kết URL rút gọn.
Header Parameters
Body Parameters
URL cần được rút gọn. Phải là một URL hợp lệ bắt đầu bằng https://
Dùng để xác định chiến dịch quảng cáo Google Analytics nào mà referral này tham chiếu đến.
Dùng để xác định một công cụ tìm kiếm, tên bản tin, hoặc nguồn khác.
Dùng để xác định một phương tiện chẳng hạn như email hoặc cost-per-click.
Dùng để phân tích từ khóa. Dùng để xác định một khuyến mãi sản phẩm cụ thể hoặc chiến dịch chiến lược.
Dùng cho paid search. Dùng để ghi lại các từ khóa cho quảng cáo này.
Dùng cho A/B testing và các quảng cáo được nhắm mục tiêu theo nội dung. Dùng để phân biệt các quảng cáo hoặc liên kết trỏ đến cùng một URL.
curl \
-H "Authorization: Bearer API_KEY" \
-H 'Content-Type: application/json' \
-d '{"url": "https://www.ayrshare.com", "utmSource": "google_ads"}' \
-X POST https://api.ayrshare.com/api/links
const API_KEY = "API_KEY";
fetch("https://api.ayrshare.com/api/links", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${API_KEY}`
},
body: JSON.stringify({
url: "https://www.ayrshare.com", // required
utmSource: "google_ads", // optional
}),
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
import requests
payload = {'url': 'https://www.ayrshare.com',
'utmSource': 'google_ads"}
headers = {'Content-Type': 'application/json',
'Authorization': 'Bearer API_KEY'}
r = requests.post('https://api.ayrshare.com/api/links',
json=payload,
headers=headers)
print(r.json())
require 'vendor/autoload.php';// Composer auto-loader using Guzzle. See .../guzzlephp.org/en/stable/overview.html
$client = new GuzzleHttp\Client();
$res = $client->request(
'POST',
'https://api.ayrshare.com/api/links',
[
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer API_KEY'
],
'json' => [
'url' => 'https://www.ayrshare.com',
'utmSource' => 'google_ads', // optional
]
]
);
echo json_encode(json_decode($res->getBody()), JSON_PRETTY_PRINT);
package main
import (
"bytes"
"encoding/json"
"log"
"net/http"
)
func main() {
message := map[string]interface{}{
"url": "https://www.ayrshare.com",
"utmSource": "google_ads",
}
bytesRepresentation, err := json.Marshal(message)
if err != nil {
log.Fatalln(err)
}
req, _ := http.NewRequest("POST", "https://api.ayrshare.com/api/links",
bytes.NewBuffer(bytesRepresentation))
req.Header.Add("Content-Type", "application/json; charset=UTF-8")
req.Header.Add("Authorization", "Bearer API_KEY")
res, err := http.DefaultClient.Do(req)
if err != nil {
log.Fatal("Error:", err)
}
res.Body.Close()
}
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace CreateShortLinkPOSTRequest_csharp
{
class CreateShortLink
{
private static readonly HttpClient client = new HttpClient();
static async Task Main(string[] args)
{
string API_KEY = "API_KEY";
string url = "https://api.ayrshare.com/api/analytics/links";
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + API_KEY);
string json = "{\"url\" : \"https://www.ayrshare.com\"," +
"\"utmSource\" :\"google_ads\"";
try
{
var content = new StringContent(json, Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PostAsync(url, content);
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
}
catch (HttpRequestException e)
{
Console.WriteLine($"Error: {e.Message}");
}
}
}
}
{
"created": "2023-07-17T15:20:51.118Z",
"id": "yC0fTl",
"originalUrl": "https://www.ayrshare.com/?utm_source=looking",
"shortUrl": "https://ayrs.io/yC0fTl",
"status": "success",
"utmSource": "looking"
}
{
"action": "request",
"status": "error",
"code": 126,
"message": "Shorten URL failed. Please verify the URL is properly formatted and the correct UTM parameters are used."
}
⌘I
