> ## Documentation Index
> Fetch the complete documentation index at: https://www.ayrshare.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# إنشاء رابط قصير

> زوّد برابط وسيُعاد رابط مختصر.

export const HeaderAPI = ({noProfileKey, profileKeyRequired}) => <>
    <ParamField header="Authorization" type="string" required>
      <a href="/apis/overview#authorization">API Key</a> of the Primary Profile.
      <br />
      <br />
      Format: <code>Authorization: Bearer API_KEY</code>
    </ParamField>
    {!noProfileKey && (profileKeyRequired ? <ParamField header="Profile-Key" type="string" required>
          <a href="/apis/overview#profile-key-format">Profile Key</a> of a User Profile.
          <br />
          <br />
          Format: <code>Profile-Key: PROFILE_KEY</code>
        </ParamField> : <ParamField header="Profile-Key" type="string">
          <a href="/apis/overview#profile-key-format">Profile Key</a> of a User Profile.
          <br />
          <br />
          Format: <code>Profile-Key: PROFILE_KEY</code>
        </ParamField>)}
  </>;

export const PlansAvailable = ({plans = [], maxPackRequired}) => {
  let displayPlans = plans;
  if (plans && plans.length === 1) {
    const lowerCasePlan = plans[0].toLowerCase();
    if (lowerCasePlan === "business") {
      displayPlans = ["Launch", "Business", "Enterprise"];
    } else if (lowerCasePlan === "premium") {
      displayPlans = ["Premium", "Launch", "Business", "Enterprise"];
    }
  }
  return <Note>
Available on {displayPlans.length === 1 ? "the " : ""}
{displayPlans.join(", ").replace(/\b\w/g, l => l.toUpperCase())}{" "}
{displayPlans.length > 1 ? "plans" : "plan"}.

{maxPackRequired && <span onClick={() => window.open('https://www.ayrshare.com/docs/additional/maxpack', '_self')} className="flex items-center mt-2 cursor-pointer">
 <span className="px-1.5 py-0.5 rounded text-sm" style={{
    backgroundColor: '#C264B6',
    color: 'white',
    fontSize: '12px'
  }}>
   Max Pack required
 </span>
</span>}
</Note>;
};

<PlansAvailable plans={["business"]} maxPackRequired={true} />

زوّد برابط وسيُعاد رابط مختصر. يمكن بعد ذلك جمع تحليلات حول النقرات ونوع المتصفح وغير ذلك.

سيؤدي إرسال الرابط نفسه للاختصار دائمًا إلى نفس الرابط المختصر. لإنشاء رابط مختصر فريد للرابط نفسه، يمكنك إضافة معاملات استعلام إضافية إليه. على سبيل المثال، إضافة معرّف فريد مثل [https://ayrshare.com?uniqueId=123](https://ayrshare.com?uniqueId=123) سيُنشئ رابطًا مختصرًا مختلفًا.

يمكنك أيضًا تضمين معاملات UTM، والتي ستُدمج في الرابط المختصر.

## معاملات الترويسة

<HeaderAPI noProfileKey />

## معاملات الجسم

<ParamField body="url" type="string" required>
  الرابط المراد اختصاره. يجب أن يكون رابطًا صالحًا يبدأ بـ https\://
</ParamField>

<ParamField body="utmId" type="string">
  يُستخدم لتحديد حملة إعلانات Google Analytics التي تشير إليها هذه الإحالة.
</ParamField>

<ParamField body="utmSource" type="string">
  يُستخدم لتحديد محرك بحث أو اسم نشرة إخبارية أو مصدر آخر.
</ParamField>

<ParamField body="utmMedium" type="string">
  يُستخدم لتحديد وسيلة كالبريد الإلكتروني أو الدفع لكل نقرة.
</ParamField>

<ParamField body="utmCampaign" type="string">
  يُستخدم لتحليل الكلمات المفتاحية. يُستخدم لتحديد ترويج منتج معيّن أو حملة استراتيجية.
</ParamField>

<ParamField body="utmTerm" type="string">
  يُستخدم للبحث المدفوع. يُستخدم للإشارة إلى الكلمات المفتاحية لهذا الإعلان.
</ParamField>

<ParamField body="utmContent" type="string">
  يُستخدم لاختبارات A/B والإعلانات الموجهة بالمحتوى. يُستخدم للتمييز بين الإعلانات أو الروابط التي تشير إلى الرابط نفسه.
</ParamField>

<RequestExample>
  ```bash cURL theme={"system"}
  curl \
  -H "Authorization: Bearer API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"url": "https://www.ayrshare.com", "utmSource": "google_ads"}' \
  -X POST https://api.ayrshare.com/api/links
  ```

  ```javascript JavaScript theme={"system"}
  const API_KEY = "API_KEY";

  fetch("https://api.ayrshare.com/api/links", {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          "Authorization": `Bearer ${API_KEY}`
        },
        body: JSON.stringify({
          url: "https://www.ayrshare.com", // required
          utmSource: "google_ads", // optional
        }),
      })
        .then((res) => res.json())
        .then((json) => console.log(json))
        .catch(console.error);
  ```

  ```python Python theme={"system"}
  import requests

  payload = {'url': 'https://www.ayrshare.com',
          'utmSource': 'google_ads"}
  headers = {'Content-Type': 'application/json',
          'Authorization': 'Bearer API_KEY'}

  r = requests.post('https://api.ayrshare.com/api/links',
      json=payload,
      headers=headers)

  print(r.json())
  ```

  ```php PHP theme={"system"}
  require 'vendor/autoload.php';// Composer auto-loader using Guzzle. See .../guzzlephp.org/en/stable/overview.html

  $client = new GuzzleHttp\Client();
  $res = $client->request(
      'POST',
      'https://api.ayrshare.com/api/links',
      [
          'headers' => [
              'Content-Type'  => 'application/json',
              'Authorization' => 'Bearer API_KEY'
          ],
          'json' => [
              'url' => 'https://www.ayrshare.com',
              'utmSource' => 'google_ads', // optional
          ]
      ]
  );

  echo json_encode(json_decode($res->getBody()), JSON_PRETTY_PRINT);
  ```

  ```go Go theme={"system"}
  package main

  import (
  	"bytes"
  	"encoding/json"
  	"log"
  	"net/http"
  )

  func main() {
  	message := map[string]interface{}{
  		"url":      "https://www.ayrshare.com",
  		"utmSource": "google_ads",
  	}

  	bytesRepresentation, err := json.Marshal(message)
  	if err != nil {
  		log.Fatalln(err)
  	}

  	req, _ := http.NewRequest("POST", "https://api.ayrshare.com/api/links",
  		bytes.NewBuffer(bytesRepresentation))

  	req.Header.Add("Content-Type", "application/json; charset=UTF-8")
  	req.Header.Add("Authorization", "Bearer API_KEY")

  	res, err := http.DefaultClient.Do(req)
  	if err != nil {
  		log.Fatal("Error:", err)
  	}

  	res.Body.Close()
  }
  ```

  ```csharp C# theme={"system"}
  using System;
  using System.Net.Http;
  using System.Text;
  using System.Threading.Tasks;

  namespace CreateShortLinkPOSTRequest_csharp
  {
  class CreateShortLink
  {
      private static readonly HttpClient client = new HttpClient();

      static async Task Main(string[] args)
      {
          string API_KEY = "API_KEY";
          string url = "https://api.ayrshare.com/api/analytics/links";

          client.DefaultRequestHeaders.Add("Authorization", "Bearer " + API_KEY);

          string json = "{\"url\" : \"https://www.ayrshare.com\"," +
              "\"utmSource\" :\"google_ads\"";

          try
          {
              var content = new StringContent(json, Encoding.UTF8, "application/json");
              HttpResponseMessage response = await client.PostAsync(url, content);
              response.EnsureSuccessStatusCode();
              string responseBody = await response.Content.ReadAsStringAsync();
              Console.WriteLine(responseBody);
          }
          catch (HttpRequestException e)
          {
              Console.WriteLine($"Error: {e.Message}");
          }
      }
  }
  }
  ```
</RequestExample>

<ResponseExample>
  ```json 200: Success theme={"system"}
  {
      "created": "2023-07-17T15:20:51.118Z",
      "id": "yC0fTl",
      "originalUrl": "https://www.ayrshare.com/?utm_source=looking",
      "shortUrl": "https://ayrs.io/yC0fTl",
      "status": "success",
      "utmSource": "looking"
  }
  ```

  ```json 400: Error Shortening Link theme={"system"}
  {
    "action": "request",
    "status": "error",
    "code": 126,
    "message": "Shorten URL failed. Please verify the URL is properly formatted and the correct UTM parameters are used."
  }
  ```
</ResponseExample>
