Skip to content

Instantly share code, notes, and snippets.

@Kurtiii
Last active November 21, 2023 15:33
Show Gist options
  • Save Kurtiii/bf12ede38590aed0f202dad2f50051d8 to your computer and use it in GitHub Desktop.
Save Kurtiii/bf12ede38590aed0f202dad2f50051d8 to your computer and use it in GitHub Desktop.
Create a Route-Code (routeto.page/api)
const url = 'https://routeto.page/api/v1/route-code/create';
const data = `{
"api_key": "[your_key]",
"destination_url": "https://kurtiii.de/pdf-reihenbriefe-mithilfe-von-excel-und-php-erstellen/"
}`;
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: data,
});
const resp = await response.text();
// Deal with the response (resp):
console.log(resp);
<?php
$url = "https://routeto.page/api/v1/route-code/create";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$headers = array(
"Content-Type: application/json",
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$data = <<<DATA
{
"api_key": "[your_key]",
"destination_url": "https://kurtiii.de/pdf-reihenbriefe-mithilfe-von-excel-und-php-erstellen/"
}
DATA;
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$resp = curl_exec($curl);
curl_close($curl);
// Deal with the response ($resp):
var_dump($resp);
?>
import requests
from requests.structures import CaseInsensitiveDict
url = "https://routeto.page/api/v1/route-code/create"
headers = CaseInsensitiveDict()
headers["Content-Type"] = "application/json"
data = """
{
"api_key": "[your_key]",
"destination_url": "https://kurtiii.de/pdf-reihenbriefe-mithilfe-von-excel-und-php-erstellen/"
}
"""
resp = requests.post(url, headers=headers, data=data)
# Deal with the response (resp):
print(resp)
{
"status":"success", // if status = error => "message" will contain error informations.
"data":{
"route_code":"2594P", // the created route-code
"destination_url":"https://kurtiii.de/pdf-reihenbriefe-mithilfe-von-excel-und-php-erstellen/", // the url of the route code
"created_at":1697037758, // UNIX-timestamp of creation
"valid_until":1697124158, // UNIX-timestamp of deletion
"server_time":1700580418 // our server time => we use Berlin (CET/UTC+1) as our timezone (should be (nearly) the same as created_at)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment