如果用户有api。访问权限,他们将能够通过UrlGO API创建链接。

API端点

请求应该通过POST请求发送到/api/links/create endpoint,并包含用户api_token。例如:

https://302verify.com/api/links/create?api_token=xxxx

请求参数

在创建链接时可以使用许多参数。除long_url和multiple_urls之外的所有参数都是可选的。参数应该以JSON格式作为POST请求体发送。

NameTypeDescription
aliasstringCustom ID for link, if empty, random string will be generated.
long_urlstringDestination url.
multiple_urlsarrayArray of multiple urls. Separate link will be created for each one. Can't be used together with long_url parameter.
domain_idnumberID of custom domain that should be attached to this link.
passwordstringPassword for the link.
disabledbooleanWhether link should be active or not.
titlestringShort title for link. If empty, title of destination url will be used.
descriptionstringShort description for link. If empty, meta description of destination url will be used.
tagsarrayArray of tags that should be attached to this link.
expires_atstringUntil when link should be active. Format example: 2019-08-23 13:24:00
pixelsarrayArray of tracking pixel IDs that should be attached to this link.
rulesarrayArray of country and device rules. Format example:{key: "ru", value: "https://destination.ru", type: "geo"},{key: "phone", value: "https://bing.com", type: "device"}

响应输出

成功的响应结构如下所示。如果使用multiple_urls参数,则response将包含links属性,并以与单个链接相同的格式包含所有已创建链接的数组。

{
"status": "success",
"link": {
"type": "direct",
"title": "Google",
"description": "Description",
"hash": "oV5Ox",
"long_url": "https://google.com",
"expires_at": null,
"disabled": false,
"user_id": 1,
"domain_id": null,
"alias": null,
"has_password": false,
"updated_at": "2019-08-21 13:33:17",
"created_at": "2019-08-21 13:33:17",
"id": 80,
"short_url": "https://302verify.com/oV5Ox"
}
}

如果在创建链接时出现任何错误,则会返回如下格式的错误响应:

{
  "status": "error",
  "messages": {
    "long_url": [
      "This url is not valid."
    ]
  }
}

使用PHP和CURL的示例

<?php

$url = "https://302verify.com/api/links/create?api_token=xxxxx";

$curl = curl_init();

$params = json_encode([
    'long_url' => 'https://destination.com',
]);

curl_setopt_array($curl, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_URL => $url,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => $params,
    CURLOPT_HTTPHEADER => [
        'Content-Type: application/json',
        'Content-Length: ' . strlen($params)
    ]
]);
$response = json_decode(curl_exec($curl));
curl_close($curl);

// $response can now be used, see above for how it's formated

print_r($response);
最后修改:2021 年 04 月 18 日
如果觉得我的文章对你有用,请随意赞赏