> This page is for version v1.
> For other versions, use one of these documentation indexes:
> - v2 (default): https://docs.pinnacle.sh/v-2/llms.txt
> - v1: https://docs.pinnacle.sh/v1/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.pinnacle.sh/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.pinnacle.sh/_mcp/server.

# Shorten URL

POST https://www.trypinnacle.dev/api/tools/urls/shorten
Content-Type: application/json

Create a shortened URL with an optional expiration date (default and max expiration is 90 days). The shortened URL will redirect to the original URL and will have the following format https://urls.p1n.io/ABCD5678.

Reference: https://docs.pinnacle.sh/v1/api-reference/tools/shorten-url

## Authentication

- `PINNACLE-API-Key` header (required) — Pinnacle API Key

## Request

### Body (application/json)

This endpoint expects an object.

- `url` (string, required) — The URL to be shortened. Must be a valid URL with either http or https protocol.
- `expiresAt` (string, optional) — Optional expiration date for the shortened URL in ISO 8601 format. Default and max expiration is 90 days.

## Response

### 200

Successfully created shortened URL

- `shortenedUrl` (string, optional) — The shortened URL.
- `expiresAt` (string, optional) — The expiration date of the shortened URL, if provided.

## Errors

### 400 Bad Request Error

Bad request due to invalid input parameters

- `errors` (list of string, optional)

### 401 Unauthorized Error

Unauthorized due to invalid API key

- `errors` (list of string, optional)

### 500 Internal Server Error

Internal server error

- `errors` (list of string, optional)

## Examples

**Request**

```json
{
  "url": "https://example.com"
}
```

**Response**

```json
{
  "shortenedUrl": "https://urls.p1n.io/abcd1234",
  "expiresAt": "2023-12-31T23:59:59Z"
}
```

**SDK Code**

```python
import requests

url = "https://www.trypinnacle.dev/api/tools/urls/shorten"

payload = { "url": "https://example.com" }
headers = {
    "PINNACLE-API-Key": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://www.trypinnacle.dev/api/tools/urls/shorten';
const options = {
  method: 'POST',
  headers: {'PINNACLE-API-Key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"url":"https://example.com"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://www.trypinnacle.dev/api/tools/urls/shorten"

	payload := strings.NewReader("{\n  \"url\": \"https://example.com\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("PINNACLE-API-Key", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://www.trypinnacle.dev/api/tools/urls/shorten")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["PINNACLE-API-Key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"url\": \"https://example.com\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://www.trypinnacle.dev/api/tools/urls/shorten")
  .header("PINNACLE-API-Key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"url\": \"https://example.com\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://www.trypinnacle.dev/api/tools/urls/shorten', [
  'body' => '{
  "url": "https://example.com"
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'PINNACLE-API-Key' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://www.trypinnacle.dev/api/tools/urls/shorten");
var request = new RestRequest(Method.POST);
request.AddHeader("PINNACLE-API-Key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"url\": \"https://example.com\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "PINNACLE-API-Key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = ["url": "https://example.com"] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://www.trypinnacle.dev/api/tools/urls/shorten")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```