cURL
curl --request GET \
--url https://api.u301.com/v2/shorten \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.u301.com/v2/shorten"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('https://api.u301.com/v2/shorten', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.u301.com/v2/shorten",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.u301.com/v2/shorten"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.u301.com/v2/shorten")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.u301.com/v2/shorten")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"code": "ax",
"url": "https://google.com",
"status": "public",
"shortened": "https://u301.co/ax"
}{
"message": "The url field must be a valid URL",
"code": "E_VALIDATION_ERROR"
}Shorten link
Shorten Link
Shorten a long link
GET
/
shorten
cURL
curl --request GET \
--url https://api.u301.com/v2/shorten \
--header 'Authorization: Bearer <token>'import requests
url = "https://api.u301.com/v2/shorten"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('https://api.u301.com/v2/shorten', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.u301.com/v2/shorten",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.u301.com/v2/shorten"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.u301.com/v2/shorten")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.u301.com/v2/shorten")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"code": "ax",
"url": "https://google.com",
"status": "public",
"shortened": "https://u301.co/ax"
}{
"message": "The url field must be a valid URL",
"code": "E_VALIDATION_ERROR"
}This API DOES NOT require authorization, which means using an anonymous account.
Example #1: Shorten google.com
You can shortgoogle.com by request API URL: https://api.u301.com/v2/shorten?url=https://google.com,
even if visit the URL directly in the browser.
Example #2: Specify Domain
We assume you have already added your own domaingo.example.com, you can shorten your link by request API:
https://api.u301.com/v2/shorten?domain=go.example.com&url=https://google.com
Which specifies the domain in the query string, and that will override the default domain.
Example #3: Custom Alias
We’d like to create a shortened linku301.co/dashboard which point to u301 dashboard.Request with a parameter
slug:https://api.u301.com/v2/shorten?url=https://u301.com/dashboard/&slug=dashboard
the returned result is
{
"hostname": "u301.com",
"url": "https://u301.com/dashboard/",
"code": "cZ",
"tally": 216,
"status": "public",
"slug": "dashboard",
"urlPrefix": "https://u301.co",
"domain": "u301.co",
"shortened": "https://u301.co/dashboard"
}
shortened is https://u301.co/dashboard 🎉Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Query Parameters
The long URL to shorten. the URL MUST starts with a valid schema, such as http:// or https://
The title of the link
Domain that you want to use for the short link.
Custom alias for the short link, must be unique, only accept letter, number, underscore _ and hyphen -.
Response
Shortened url