Creating Links via API
If users have api.access permission, they will be able to create links via dgLnk API.
API Endpoint
Requests should be sent to /api/links/create endpoint via POST request and include user api_token. For example:
https://app.dglnk.me/api/links/create?api_token=s45s45sd4AADWLLKFfkl4545as
Note:Unique API token will be automatically generated for each user and it can be found in user account settings page, under password panel.
Request Parameters
A number of parameters can be used when creating links. All parameters except long_url or multiple_urls are optional. Parameters should be sent as POST request body in JSON format.
Name | Type | Description |
---|---|---|
alias | string | Custom ID for link, if empty, random string will be generated. |
long_url | string | Destination url. |
multiple_urls | array | Array of multiple urls. Separate link will be created for each one. Can’t be used together with long_url parameter. |
domain_id | number | ID of custom domain that should be attached to this link. |
password | string | Password for the link. |
disabled | boolean | Whether link should be active or not. |
title | string | Short title for link. If empty, title of destination url will be used. |
description | string | Short description for link. If empty, meta description of destination url will be used. |
tags | array | Array of tags that should be attached to this link. |
expires_at | string | Until when link should be active. Format example: 2019-08-23 13:24:00 |
pixels | array | Array of tracking pixel IDs that should be attached to this link. |
rules | array | Array of country and device rules. Format example: {key: “ru”, value: “https://destination.ru”, type: “geo”}, {key: “phone”, value: “https://bing.com”, type: “device”} |
Response
Successful response structure will look like this. If multiple_urls parameter is used, response will contain links property instead, with array of all created links in the same format as single link.
{
"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://sml.life/oV5Ox"
}
}
If there were any errors when creating a link, Error response with below format will be returned instead:
{
"status": "error",
"messages": {
"long_url": [
"This url is not valid."
]
}
}
Example with PHP and CURL
<?php
$url = "https://app.dglnlk.me/api/links/create?api_token=s45s45sd4AADWLLKFfkl4545as";
$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
For any support, please reach out to [email protected]