Getting started overview
Integrating Drivet URL Shortener involves a series of steps designed to get you from account creation to a successful API call efficiently. The Drivet API is RESTful and uses API keys for authentication. This guide outlines the process, from signing up for a Drivet account to making your first programmatic URL shortening request. Developers can utilize official SDKs for Node.js, Python, Go, PHP, and Ruby to simplify interaction with the API, or directly make HTTP requests.
Before making any API calls, you will need to establish a Drivet account and generate an API key. This key authenticates your requests and links them to your Drivet account, enabling access to features such as link analytics and custom domains within your dashboard. The Drivet platform offers a free tier for basic usage, which includes a sufficient number of links and a custom domain for initial development and testing.
The primary goal of this guide is to demonstrate how to shorten a long URL into a Drivet short URL using the API. This foundational task confirms your setup is correct and provides a working example to build upon. Subsequent steps typically involve exploring advanced features like custom domains, QR code generation, and retrieving link analytics, all accessible through the same API.
Create an account and get keys
To begin with Drivet URL Shortener, you must first create an account on the Drivet platform. This account provides access to the developer dashboard where you manage your links, view analytics, and retrieve your API key. Follow these steps:
- Navigate to the Drivet Homepage: Open your web browser and go to the Drivet URL Shortener homepage.
- Sign Up: Locate the 'Sign Up' or 'Get Started Free' button, typically in the top right corner or prominently displayed on the page. Click it to initiate the registration process.
- Provide Registration Details: Enter the required information, which usually includes your email address and a password. You may also have the option to sign up using a third-party identity provider like Google or GitHub.
- Verify Email (if required): After submitting your details, Drivet may send a verification email to the address you provided. Follow the instructions in the email to verify your account and complete the registration.
- Access the Dashboard: Once registered and verified, log in to your Drivet account. This will take you to your user dashboard.
- Locate API Settings: Within the dashboard, look for a section related to 'API Settings', 'Developer Settings', or 'Integrations'. The exact naming might vary, but it's typically found in the account or profile settings. Refer to the Drivet API reference documentation for precise navigation within the dashboard.
- Generate API Key: In the API settings section, there will be an option to generate a new API key. Click this button. Drivet will generate a unique string of characters that serves as your API key. This key authenticates your requests to the Drivet API.
- Securely Store Your API Key: The API key grants full access to your Drivet account programmatically. Treat it like a password. Do not hardcode it directly into your application's source code, commit it to public version control systems, or share it unnecessarily. Best practices for API key management include using environment variables or a secure secret management service. For example, similar to how AWS Key Management Service helps manage cryptographic keys, you should secure your API keys.
| Step | What to do | Where to find it |
|---|---|---|
| 1. Create Account | Sign up for a Drivet account. | Drivet homepage |
| 2. Access Dashboard | Log in to your Drivet account. | Drivet login |
| 3. Generate API Key | Find 'API Settings' and create a new key. | Drivet Dashboard > Settings/Developer |
| 4. Review API Docs | Understand endpoints and parameters. | Drivet API reference |
| 5. Make First Request | Send a POST request to shorten a URL. | Terminal, IDE, or HTTP client |
Your first request
With your Drivet API key ready, you can now make your first request to shorten a URL. This example uses a common HTTP client, curl, for demonstration, but you can adapt it to any programming language or HTTP client. The primary endpoint for shortening URLs is typically a POST request to a /shorten or similar path, as detailed in the Drivet API documentation for creating a short link.
Before executing the request, ensure you have your API key. For this example, we'll assume your API key is stored in an environment variable named DRIVET_API_KEY.
Example using curl
export DRIVET_API_KEY="YOUR_DRIVET_API_KEY"
curl -X POST \
https://api.drivet.app/v1/shorten \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $DRIVET_API_KEY" \
-d '{ "long_url": "https://developers.google.com/maps/documentation/geocoding/overview" }'
Breakdown of the curl command:
export DRIVET_API_KEY="YOUR_DRIVET_API_KEY": Sets an environment variable for your API key. ReplaceYOUR_DRIVET_API_KEYwith the actual key you generated from your Drivet dashboard.-X POST: Specifies that this is an HTTP POST request.https://api.drivet.app/v1/shorten: This is the Drivet API endpoint for shortening URLs. Always verify the correct endpoint URL and version in the Drivet API reference.-H "Content-Type: application/json": Informs the API that the request body is in JSON format, aligning with JSON data interchange standards.-H "Authorization: Bearer $DRIVET_API_KEY": Provides your API key for authentication using the Bearer token scheme. The API key is prefixed withBearer. This is a common method for OAuth 2.0 Bearer Token usage.-d '{ "long_url": "https://developers.google.com/maps/documentation/geocoding/overview" }': This is the request body, containing a JSON object with thelong_urlparameter set to the URL you wish to shorten. The example uses the Google Maps Geocoding API overview as the long URL to shorten.
Expected successful response
A successful response from the Drivet API will typically return an HTTP 201 Created status code and a JSON object containing details about the newly created short URL. The structure might resemble this:
{
"id": "unique_link_id",
"short_url": "https://drivet.app/abcde",
"long_url": "https://developers.google.com/maps/documentation/geocoding/overview",
"created_at": "2026-05-29T10:30:00Z",
"clicks": 0
}
The short_url field will contain the shortened URL that you can now use. The id field is a unique identifier for this specific short link within your Drivet account, useful for later retrieval or updates.
Example using Python
If you prefer using a programming language, here's an example using Python with the requests library:
import os
import requests
import json
DRIVET_API_KEY = os.getenv("DRIVET_API_KEY")
DRIVET_API_ENDPOINT = "https://api.drivet.app/v1/shorten"
long_url_to_shorten = "https://developers.google.com/maps/documentation/geocoding/overview"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {DRIVET_API_KEY}"
}
payload = {
"long_url": long_url_to_shorten
}
try:
response = requests.post(DRIVET_API_ENDPOINT, headers=headers, data=json.dumps(payload))
response.raise_for_status() # Raises HTTPError for bad responses (4xx or 5xx)
short_link_data = response.json()
print("Successfully shortened URL:")
print(json.dumps(short_link_data, indent=2))
print(f"Short URL: {short_link_data.get('short_url')}")
except requests.exceptions.HTTPError as http_err:
print(f"HTTP error occurred: {http_err}")
print(f"Response body: {response.text}")
except Exception as err:
print(f"Other error occurred: {err}")
Ensure you have the requests library installed (pip install requests) and the DRIVET_API_KEY environment variable set before running this script. This Python example demonstrates how to construct the request, handle the JSON payload, and process the API response, including basic error handling.
Common next steps
After successfully making your first URL shortening request with Drivet, consider these common next steps to further integrate and utilize the platform's capabilities:
- Explore Custom Domains: Drivet allows you to use your own branded domains for short URLs (e.g.,
yourbrand.link/product). This enhances brand recognition and trust. Refer to the Drivet custom domain setup guide for instructions on configuring DNS records and linking your domain. - Implement Link Analytics: Access the analytics data for your shortened URLs through the Drivet dashboard or API. This includes click counts, referrer data, and geographical information, which are crucial for performance tracking in marketing campaigns. The Drivet API reference for link analytics provides details on retrieving this data programmatically.
- Generate QR Codes: Drivet often provides functionality to generate QR codes for your short links. This feature can be integrated into print materials or digital displays. Check the Drivet QR code generation documentation for specific API endpoints or dashboard features.
- Manage Links Programmatically: Beyond creating short links, the Drivet API allows for updating existing links (e.g., changing the long URL destination), deleting links, and retrieving lists of all your shortened URLs. Consult the full Drivet API reference for these management operations.
- Integrate with SDKs: If you are working in Node.js, Python, Go, PHP, or Ruby, consider using the official Drivet SDKs. These libraries abstract away the direct HTTP request handling, making API interactions simpler and more idiomatic for your chosen language. Details on specific Drivet SDK usage are available in the documentation.
- Error Handling and Webhooks: Implement robust error handling in your application to gracefully manage API failures. Additionally, explore if Drivet offers webhooks to receive real-time notifications about events, such as new clicks on your short links. Webhooks are a common pattern for real-time data notification, similar to how Stripe uses webhooks for payment events.
Troubleshooting the first call
Encountering issues during your first API call is common. Here are some troubleshooting steps for Drivet URL Shortener API requests:
- Check API Key: Ensure your API key is correct and hasn't expired or been revoked. Double-check for typos or leading/trailing spaces. If in doubt, generate a new key from your Drivet dashboard.
- Verify Endpoint URL: Confirm that the API endpoint URL (e.g.,
https://api.drivet.app/v1/shorten) is precisely correct, including the version number and path. Refer to the Drivet API reference for the most current endpoint. - Content-Type Header: Make sure the
Content-Type: application/jsonheader is correctly set in your request if you are sending a JSON payload. Missing or incorrect content type can lead to `415 Unsupported Media Type` errors. - Authorization Header Format: The authorization header should be in the format
Authorization: Bearer YOUR_DRIVET_API_KEY. Verify the 'Bearer' prefix and the space between 'Bearer' and your key. - Request Body Format: The JSON payload must be valid and contain the expected parameters, such as
long_url. Ensure the JSON is correctly formatted (e.g., no missing commas, correctly quoted keys and values). Use a JSON linter if you suspect formatting issues. - HTTP Status Codes: Pay attention to the HTTP status code returned in the response:
400 Bad Request: Often indicates an issue with your request body or parameters. Check the API documentation for required fields and data types.401 Unauthorized: Typically means your API key is missing, invalid, or expired.403 Forbidden: Your API key might be valid but lacks the necessary permissions for the requested action, or you've hit a rate limit.404 Not Found: The endpoint URL is incorrect or the resource you're trying to access (e.g., a specific short link ID) doesn't exist.429 Too Many Requests: You have exceeded the rate limits imposed by the API. Wait a period and retry, or implement exponential backoff.5xx Server Error: An issue on Drivet's side. While less common, these require Drivet to resolve.
- Check Response Body for Error Messages: Most APIs provide detailed error messages in the response body for non-2xx status codes. Parse and examine these messages for specific clues on what went wrong.
- Consult Drivet Documentation: The official Drivet documentation is the most authoritative source for API specifications, error codes, and troubleshooting guides.
- Network Issues: Ensure your development environment has a stable internet connection and no firewall rules are blocking outgoing HTTP requests to
api.drivet.app.