curl \
-H "Authorization: Bearer API_KEY" \
-H 'Content-Type: application/json' \
-H 'Profile-Key: PROFILE_KEY' \
-d '{"expiresIn": 60}' \
-X POST https://api.ayrshare.com/api/profiles/link-sessions
const API_KEY = "API_KEY";
const PROFILE_KEY = "PROFILE_KEY";
fetch("https://api.ayrshare.com/api/profiles/link-sessions", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${API_KEY}`,
"Profile-Key": PROFILE_KEY,
},
body: JSON.stringify({ expiresIn: 60 }),
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
import requests
payload = {'expiresIn': 60}
headers = {'Content-Type': 'application/json',
'Authorization': 'Bearer API_KEY',
'Profile-Key': 'PROFILE_KEY'}
response = requests.post('https://api.ayrshare.com/api/profiles/link-sessions',
json=payload, headers=headers)
print(response.json())
<?php
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/profiles/link-sessions',
[
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer API_KEY',
'Profile-Key' => 'PROFILE_KEY'
],
'json' => [
'expiresIn' => 60,
]
]
);
echo json_encode(json_decode($res->getBody()), JSON_PRETTY_PRINT);
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace CreateLinkSession_csharp
{
class CreateLinkSession
{
static async Task Main(string[] args)
{
string API_KEY = "API_KEY";
string PROFILE_KEY = "PROFILE_KEY";
string url = "https://api.ayrshare.com/api/profiles/link-sessions";
try
{
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + API_KEY);
client.DefaultRequestHeaders.Add("Profile-Key", PROFILE_KEY);
var sendData = new { expiresIn = 60 };
string jsonData = JsonConvert.SerializeObject(sendData);
var content = new StringContent(jsonData, 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($"HTTP request error: {e.Message}");
}
}
}
}
{
"status": "success",
"sessionId": "c7a2434e72e91bde27579efde0fd6dd0b74ceee29a471fd368407f273708c2e8", // Identifier for this link. Use it with Get and Revoke a Link Session.
"url": "https://profile.ayrshare.com?session=ayr_ls_kJ8mQ2vX9pLnR4tYwZ6aBcD1eFgH3iJkLmN0oPqRsTu&domain=YOUR_DOMAIN", // Send this to your user exactly as returned. The token exists only in here.
"expiresAt": "2026-09-02T08:03:26.838Z", // When the link stops working, as an ISO 8601 timestamp.
"emailSent": false, // Whether the connect-accounts email was sent. false with no emailError means no email was requested.
"title": "Acme Client" // The User Profile's title. Omitted when the profile has none.
}
{
"status": "success",
"sessionId": "c7a2434e72e91bde27579efde0fd6dd0b74ceee29a471fd368407f273708c2e8",
"url": "https://profile.ayrshare.com?session=ayr_ls_kJ8mQ2vX9pLnR4tYwZ6aBcD1eFgH3iJkLmN0oPqRsTu&domain=YOUR_DOMAIN", // Still valid. Send it to your user yourself.
"expiresAt": "2026-09-02T08:03:26.838Z",
"emailSent": false,
"emailError": { // Only present when an email was requested and could not be sent.
"code": 333,
"message": "Email failed to send. Please confirm a valid email was provided."
},
"title": "Acme Client"
}
{
"status": "success",
"sessionId": "c7a2434e72e91bde27579efde0fd6dd0b74ceee29a471fd368407f273708c2e8",
"url": "https://profile.ayrshare.com/connect?session=ayr_ls_kJ8mQ2vX9pLnR4tYwZ6aBcD1eFgH3iJkLmN0oPqRsTu", // Open this in a popup. One network, no domain parameter.
"expiresAt": "2026-09-02T08:03:26.838Z",
"emailSent": false,
"title": "Acme Client"
}
{
"status": "success",
"sessionId": "c7a2434e72e91bde27579efde0fd6dd0b74ceee29a471fd368407f273708c2e8",
"token": "ayr_ls_kJ8mQ2vX9pLnR4tYwZ6aBcD1eFgH3iJkLmN0oPqRsTu", // No url: this shape returns the bare token instead. Treat it like a password.
"expiresAt": "2026-09-02T08:03:26.838Z",
"emailSent": false, // Always false here - email needs a link to send, so it returns code: 510.
"title": "Acme Client"
}
{
"action": "link session",
"status": "error",
"code": 504,
"message": "Connect mode requires the Max Pack. Activate it on your Account page: https://app.ayrshare.com/account"
}
{
"action": "JWT",
"status": "error",
"code": 188,
"message": "Missing or incorrect privateKey, profileKey, domain, email 'to', or expiresIn fields."
}
{
"action": "JWT",
"status": "error",
"code": 189,
"message": "Error generating JWT. Check the sent parameters.",
"details": "Missing or incorrect domain."
}
{
"action": "JWT",
"status": "error",
"code": 340,
"message": "Max Pack required. Go to your dashboard to add the Max Pack."
}
Profiles
Link Session बनाएँ
किसी User Profile के लिए private key भेजे बिना सोशल-लिंकिंग URL बनाएँ।
POST
/
profiles
/
link-sessions
curl \
-H "Authorization: Bearer API_KEY" \
-H 'Content-Type: application/json' \
-H 'Profile-Key: PROFILE_KEY' \
-d '{"expiresIn": 60}' \
-X POST https://api.ayrshare.com/api/profiles/link-sessions
const API_KEY = "API_KEY";
const PROFILE_KEY = "PROFILE_KEY";
fetch("https://api.ayrshare.com/api/profiles/link-sessions", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${API_KEY}`,
"Profile-Key": PROFILE_KEY,
},
body: JSON.stringify({ expiresIn: 60 }),
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
import requests
payload = {'expiresIn': 60}
headers = {'Content-Type': 'application/json',
'Authorization': 'Bearer API_KEY',
'Profile-Key': 'PROFILE_KEY'}
response = requests.post('https://api.ayrshare.com/api/profiles/link-sessions',
json=payload, headers=headers)
print(response.json())
<?php
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/profiles/link-sessions',
[
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer API_KEY',
'Profile-Key' => 'PROFILE_KEY'
],
'json' => [
'expiresIn' => 60,
]
]
);
echo json_encode(json_decode($res->getBody()), JSON_PRETTY_PRINT);
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace CreateLinkSession_csharp
{
class CreateLinkSession
{
static async Task Main(string[] args)
{
string API_KEY = "API_KEY";
string PROFILE_KEY = "PROFILE_KEY";
string url = "https://api.ayrshare.com/api/profiles/link-sessions";
try
{
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + API_KEY);
client.DefaultRequestHeaders.Add("Profile-Key", PROFILE_KEY);
var sendData = new { expiresIn = 60 };
string jsonData = JsonConvert.SerializeObject(sendData);
var content = new StringContent(jsonData, 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($"HTTP request error: {e.Message}");
}
}
}
}
{
"status": "success",
"sessionId": "c7a2434e72e91bde27579efde0fd6dd0b74ceee29a471fd368407f273708c2e8", // Identifier for this link. Use it with Get and Revoke a Link Session.
"url": "https://profile.ayrshare.com?session=ayr_ls_kJ8mQ2vX9pLnR4tYwZ6aBcD1eFgH3iJkLmN0oPqRsTu&domain=YOUR_DOMAIN", // Send this to your user exactly as returned. The token exists only in here.
"expiresAt": "2026-09-02T08:03:26.838Z", // When the link stops working, as an ISO 8601 timestamp.
"emailSent": false, // Whether the connect-accounts email was sent. false with no emailError means no email was requested.
"title": "Acme Client" // The User Profile's title. Omitted when the profile has none.
}
{
"status": "success",
"sessionId": "c7a2434e72e91bde27579efde0fd6dd0b74ceee29a471fd368407f273708c2e8",
"url": "https://profile.ayrshare.com?session=ayr_ls_kJ8mQ2vX9pLnR4tYwZ6aBcD1eFgH3iJkLmN0oPqRsTu&domain=YOUR_DOMAIN", // Still valid. Send it to your user yourself.
"expiresAt": "2026-09-02T08:03:26.838Z",
"emailSent": false,
"emailError": { // Only present when an email was requested and could not be sent.
"code": 333,
"message": "Email failed to send. Please confirm a valid email was provided."
},
"title": "Acme Client"
}
{
"status": "success",
"sessionId": "c7a2434e72e91bde27579efde0fd6dd0b74ceee29a471fd368407f273708c2e8",
"url": "https://profile.ayrshare.com/connect?session=ayr_ls_kJ8mQ2vX9pLnR4tYwZ6aBcD1eFgH3iJkLmN0oPqRsTu", // Open this in a popup. One network, no domain parameter.
"expiresAt": "2026-09-02T08:03:26.838Z",
"emailSent": false,
"title": "Acme Client"
}
{
"status": "success",
"sessionId": "c7a2434e72e91bde27579efde0fd6dd0b74ceee29a471fd368407f273708c2e8",
"token": "ayr_ls_kJ8mQ2vX9pLnR4tYwZ6aBcD1eFgH3iJkLmN0oPqRsTu", // No url: this shape returns the bare token instead. Treat it like a password.
"expiresAt": "2026-09-02T08:03:26.838Z",
"emailSent": false, // Always false here - email needs a link to send, so it returns code: 510.
"title": "Acme Client"
}
{
"action": "link session",
"status": "error",
"code": 504,
"message": "Connect mode requires the Max Pack. Activate it on your Account page: https://app.ayrshare.com/account"
}
{
"action": "JWT",
"status": "error",
"code": 188,
"message": "Missing or incorrect privateKey, profileKey, domain, email 'to', or expiresIn fields."
}
{
"action": "JWT",
"status": "error",
"code": 189,
"message": "Error generating JWT. Check the sent parameters.",
"details": "Missing or incorrect domain."
}
{
"action": "JWT",
"status": "error",
"code": 340,
"message": "Max Pack required. Go to your dashboard to add the Max Pack."
}
किसी User Profile के लिए सोशल-लिंकिंग URL बनाएँ। लौटाया गया
ऊपर नामित हर code Link Session त्रुटियाँ संदर्भ में
है।
url अपने उपयोगकर्ता को भेजें,
और वे उसे खोलकर अपने सोशल अकाउंट कनेक्ट करते हैं।
लिंकिंग URL बनाने का यह अनुशंसित तरीका है। इसके लिए केवल आपकी API Key और एक
Profile-Key चाहिए — भेजने के लिए कोई private key नहीं है और साइन करने के लिए कुछ भी नहीं।
पहले बनाए जाने वाले लिंकिंग URL के विपरीत, link session संग्रहीत रहता है, इसलिए आप जाँच सकते हैं
कि उसका उपयोग हुआ या नहीं और समय समाप्त होने से पहले उसे रद्द कर सकते हैं।
लौटाया गया url आपके उपयोगकर्ता को उनके प्रोफ़ाइल में साइन इन कर देता है, इसलिए इसे पासवर्ड की तरह
मानें और हर लिंक केवल एक ही उपयोगकर्ता को भेजें। देखें
लिंकिंग URL भेजना।
URL डिफ़ॉल्ट रूप से 5 मिनट के लिए मान्य है। अलग अवधि सेट करने के लिए
expiresIn का उपयोग
करें, अधिकतम 2880 मिनट (48 घंटे) तक।लिंकिंग URL बनाएँ वही काम करता है और बिना बदलाव के काम करता
रहता है। यह पुराने
privateKey, base64 और verify पैरामीटर स्वीकार करता है और उन्हें
नज़रअंदाज़ कर देता है। domain किसी भी एंडपॉइंट पर नज़रअंदाज़ नहीं किया जाता — यह वैकल्पिक
बना रहता है और अब भी validate किया जाता है। नए इंटीग्रेशन के लिए यही एंडपॉइंट इस्तेमाल करें।प्रतिक्रिया में एक अंतर है: generateJWT पिछड़ी संगतता के लिए टॉप-लेवल token लौटाता है,
और यह एंडपॉइंट किसी url के साथ-साथ token नहीं लौटाता — url वाला token उसके अंदर रहता
है। यदि आप माइग्रेट कर रहे हैं और आपका कोड token पढ़ता है, तो उसकी जगह url पढ़ें।
(एम्बेडेड विजेट के लिए Connect mode ही एकमात्र आकार है जो अकेला token
लौटाता है, क्योंकि वह कोई URL नहीं लौटाता जिसमें token रह सके।)हेडर पैरामीटर
Profile-Key इस एंडपॉइंट पर एक हेडर है — कोई profileKey बॉडी पैरामीटर नहीं है। यह
अनुपस्थित होने पर आपको code: 188 मिलता है, जिसके message में privateKey, profileKey
और अन्य पुराने फ़ील्ड नाम सूचीबद्ध हैं, क्योंकि यह
लिंकिंग URL बनाएँ के साथ साझा है। इसे यों पढ़ें कि
“Profile-Key हेडर अनुपस्थित या ग़लत है”; इसमें दिए गए बाकी नामों में से कोई भी इस
एंडपॉइंट का पैरामीटर नहीं है।string
X Developer Portal से आपकी X API Key (Consumer Key)। प्रदान किए जाने पर, लिंकिंग URL
OAuth लिंकिंग के लिए आपके अपने X Developer App का उपयोग करेगा।
string
X Developer Portal से आपकी X API Secret (Consumer Secret)।
X-Twitter-OAuth1-Api-Key
प्रदान किए जाने पर आवश्यक।बॉडी पैरामीटर
string
डिफ़ॉल्ट:"grid"
यह सेशन किस लिंकिंग सरफ़ेस को चलाता है।
grid— होस्टेड लिंकिंग पेज, जो आपके अनुमत हर नेटवर्क को दिखाता है। यह डिफ़ॉल्ट है, इसलिएmodeछोड़ने वाला अनुरोध यही बनाता है।connect— एक समय में एक नेटवर्क, आपके अपने डैशबोर्ड से खोला गया। नीचे Connect Mode और डायरेक्ट मोड देखें।
origin या network पास करने से आप connect mode में नहीं आ
जाते, इसलिए कोई grid सेशन ग़लती से gated सेशन नहीं बन सकता। कोई भी अन्य मान code: 188
लौटाता है, जिसके details में दोनों के नाम होते हैं।number
डिफ़ॉल्ट:5
मिनटों में लिंक की अवधि। सीमा: 1 से 2880 मिनट तक।Max Pack आवश्यक है।अधिक जानकारी के लिए लिंक की समाप्ति देखें।
boolean
डिफ़ॉल्ट:false
वर्तमान सत्र को स्वचालित रूप से लॉग आउट करें। प्रदर्शन को प्रभावित करने के कारण उत्पादन में
उपयोग की अनुशंसा नहीं की जाती।देखें Automatic Logout of a Profile Session।
string
“Done” बटन या लोगो छवि पर क्लिक करने पर रीडायरेक्ट करने के लिए एक URL। opener window को
रीडायरेक्ट करने के लिए क्वेरी पैरामीटर
origin=true जोड़ें।array
लिंकिंग पेज पर प्रदर्शित करने के लिए सोशल नेटवर्क। यह
Social Networks पेज पर
कॉन्फ़िगर किए गए नेटवर्कों को ओवरराइड करता है।
Only display Facebook, X/Twitter, LinkedIn, and TikTok
{
"allowedSocial": ["facebook", "twitter", "linkedin", "tiktok"]
}
string
केवल connect mode। वह अकेला सोशल नेटवर्क जिसे यह सेशन कनेक्ट करता है, और यही इसे
direct-mode सेशन बनाता है। ऐसे सेशन के लिए इसे छोड़ दें जिसे आपका अपना डैशबोर्ड कई
नेटवर्कों पर चलाता है।इनमें से एक:
bluesky, facebook, gmb, instagram, instagramApi, linkedin, pinterest,
reddit, snapchat, telegram, threads, tiktok, twitter, whatsapp, x, youtube।
कुछ भी और code: 508 लौटाता है — जिसमें fbg भी शामिल है, जो यहाँ कोई link target नहीं है।allowedSocial के साथ जोड़ा नहीं जा सकता (code: 507): single-network सेशन पहले से अपनी
ख़ुद की allowlist है। जिस नेटवर्क को आपके अकाउंट ने सक्षम नहीं किया है वह code: 509 लौटाता
है, जो 508 से अलग जवाब है क्योंकि इसे आपके
Social Networks पेज पर ठीक
किया जा सकता है।Grid mode में इसे नज़रअंदाज़ किया जाता है।string
इस लिंक के लिए कौन सा Instagram लिंकिंग फ़्लो उपयोग किया जाता है, इसे ओवरराइड करें। वैध मान:
instagram: सीधा Instagram Login, कोई Facebook Page आवश्यक नहीं।facebook: कनेक्टेड Facebook Page के माध्यम से Instagram लिंक करें।
string
उस पेज का सटीक origin जिसने लिंकिंग विंडो खोली, ताकि लिंकिंग पूरी होने पर उसे बताया जा सके।सेट होने पर, लिंकिंग पेज आपके उपयोगकर्ता के हर अकाउंट कनेक्ट करते ही
window.postMessage के
साथ उस origin को events पोस्ट करता है, और आपका पेज बिना polling के प्रतिक्रिया दे सकता है।
Events केवल इसी सटीक मान को भेजे जाते हैं, इसलिए इसे आपके पेज के origin से अक्षरशः मेल खाना
चाहिए, scheme और किसी भी port समेत।तीन आकार स्वीकार किए जाते हैं: एक https origin (https://app.example.com), local development
के लिए http://localhost:3000, और एक native custom scheme (myapp://connected)। कुछ भी और —
localhost के अलावा कोई सादा http:// origin, या ऐसा कुछ जो origin है ही नहीं — इस एंडपॉइंट के
बनाए लिंक्स पर नज़रअंदाज़ किया जाता है: लिंक फिर भी काम करता है, वह बस कोई events नहीं भेजता।
यह वैकल्पिक है, इसलिए इसे छोड़ना भी कोई त्रुटि नहीं है।तीनों में से केवल पहले दो को events मिलते हैं। custom scheme मोबाइल ऐप के लिए एक वापसी target
है और उन्हें प्राप्त नहीं कर सकती, क्योंकि पोस्ट करने के लिए कोई ब्राउज़र विंडो नहीं है;
native ऐप्स इसके बजाय Link Session प्राप्त करें को poll करते
हैं।देखें Link Completion Events।Connect mode में origin आवश्यक है, और उसकी जाँच होती है। ऊपर की छूट grid-mode का व्यवहार
है। mode: "connect" के साथ, इसे छोड़ने पर code: 505 लौटता है और जो मान तीन स्वीकृत आकारों
में से एक नहीं है वह code: 506 लौटाता है, जिसके details आपके भेजे आकार को दोहराते हैं।string
वैकल्पिक। आपका लिंकिंग domain, जब आपके अकाउंट पर एक से अधिक हों। छोड़ दिए जाने पर आपके
अकाउंट का अपना domain इस्तेमाल होता है। आपके अकाउंट पर रजिस्टर्ड न होने वाला domain
अस्वीकार कर दिया जाता है।
object
लिंक ले जाने वाला Connect Accounts ईमेल भेजें, ताकि आपका उपयोगकर्ता सीधे अपने लिंकिंग पेज
तक पहुँच सके। एक
to पता आवश्यक है।Max Pack आवश्यक है। प्रतिक्रिया emailSent में परिणाम बताती है। अगर ईमेल नहीं भेजा जा सका, तब भी आपको लिंक मिलता है: प्रतिक्रिया में emailSent: false और एक emailError ऑब्जेक्ट होता है, ताकि आप लिंक को किसी और तरीके से अपने उपयोगकर्ता तक पहुँचा सकें।देखें Connect Accounts Email।Connect Mode
mode: "connect" होस्टेड लिंकिंग पेज के बजाय ऐसे लिंकिंग सरफ़ेस के लिए सेशन बनाता है जिसे आप
स्वयं होस्ट करते हैं। दो connect आकारों में से कौन सा मिलेगा यह एक ही चीज़ पर निर्भर करता है —
आप network पास करते हैं या नहीं:
| आप भेजते हैं | आपको वापस मिलता है | आप उसका क्या करते हैं |
|---|---|---|
mode: "connect" और एक network | single-network connect पेज की ओर इशारा करता url | उसे पॉपअप में खोलें — यही डायरेक्ट मोड है |
mode: "connect" और कोई network नहीं | एक token, और कोई URL नहीं | उसे अपने front end को सौंपें |
प्रतिक्रिया secret को ठीक एक बार ले जाती है। प्रतिक्रिया में या तो
url होता है या
token, कभी दोनों नहीं और कभी दो URL नहीं। direct-mode सेशन का token url के अंदर रहता है,
ठीक वैसे जैसे grid mode में; जिस सेशन के पास उसे ले जाने के लिए कोई URL नहीं है वह इसके बजाय
अकेला token लौटाता है। बाक़ी सब तीनों modes में एक जैसा है: sessionId, expiresAt,
emailSent, और जब User Profile का कोई हो तो title।Connect Mode को क्या चाहिए
इनमें से कोई भी अपने आप में कोई body फ़ील्ड नहीं है — पहला अकाउंट का entitlement है और दूसरा ऊपर काorigin पैरामीटर है, जिसे connect mode अनिवार्य बना देता है।
Max Pack। इसके बिना कॉल code: 504 लौटाती है, जिसकी जाँच connect-mode
पैरामीटरों से पहले होती है, इसलिए origin या network ठीक करने से जवाब नहीं बदलेगा। यदि आपको
बिना Max Pack वाले अकाउंट पर connect mode सक्षम कराना हो तो support से संपर्क करें।
हर सेशन पर एक origin। कोई allowlist नहीं है और कोई registration चरण नहीं — आप इसे हर कॉल
पर भेजते हैं और यह सेशन पर संग्रहीत होता है, इसलिए नए environment को हमारी तरफ़ किसी setup की
ज़रूरत नहीं। तीन आकार स्वीकार किए जाते हैं:
- एक
httpsorigin —https://app.example.com - एक native custom scheme —
myapp://connected http://localhostयाhttp://localhost:3000, local development के लिए
code: 505 लौटता है, और जो कुछ भी तीन आकारों में से एक नहीं है वह code: 506 लौटाता है।
email ऐसे सेशन के साथ इस्तेमाल नहीं किया जा सकता जिसमें कोई network नहीं है, क्योंकि ईमेल
में डालने के लिए कोई लिंक नहीं है — वह आकार आपके अपने front end के लिए token लौटाता है। कॉल
code: 510 लौटाती है। direct-mode सेशन के लिए एक network जोड़ें, जिसके पास URL होता है, या
email छोड़ दें।curl \
-H "Authorization: Bearer API_KEY" \
-H 'Content-Type: application/json' \
-H 'Profile-Key: PROFILE_KEY' \
-d '{"expiresIn": 60}' \
-X POST https://api.ayrshare.com/api/profiles/link-sessions
const API_KEY = "API_KEY";
const PROFILE_KEY = "PROFILE_KEY";
fetch("https://api.ayrshare.com/api/profiles/link-sessions", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${API_KEY}`,
"Profile-Key": PROFILE_KEY,
},
body: JSON.stringify({ expiresIn: 60 }),
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
import requests
payload = {'expiresIn': 60}
headers = {'Content-Type': 'application/json',
'Authorization': 'Bearer API_KEY',
'Profile-Key': 'PROFILE_KEY'}
response = requests.post('https://api.ayrshare.com/api/profiles/link-sessions',
json=payload, headers=headers)
print(response.json())
<?php
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/profiles/link-sessions',
[
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer API_KEY',
'Profile-Key' => 'PROFILE_KEY'
],
'json' => [
'expiresIn' => 60,
]
]
);
echo json_encode(json_decode($res->getBody()), JSON_PRETTY_PRINT);
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace CreateLinkSession_csharp
{
class CreateLinkSession
{
static async Task Main(string[] args)
{
string API_KEY = "API_KEY";
string PROFILE_KEY = "PROFILE_KEY";
string url = "https://api.ayrshare.com/api/profiles/link-sessions";
try
{
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + API_KEY);
client.DefaultRequestHeaders.Add("Profile-Key", PROFILE_KEY);
var sendData = new { expiresIn = 60 };
string jsonData = JsonConvert.SerializeObject(sendData);
var content = new StringContent(jsonData, 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($"HTTP request error: {e.Message}");
}
}
}
}
{
"status": "success",
"sessionId": "c7a2434e72e91bde27579efde0fd6dd0b74ceee29a471fd368407f273708c2e8", // Identifier for this link. Use it with Get and Revoke a Link Session.
"url": "https://profile.ayrshare.com?session=ayr_ls_kJ8mQ2vX9pLnR4tYwZ6aBcD1eFgH3iJkLmN0oPqRsTu&domain=YOUR_DOMAIN", // Send this to your user exactly as returned. The token exists only in here.
"expiresAt": "2026-09-02T08:03:26.838Z", // When the link stops working, as an ISO 8601 timestamp.
"emailSent": false, // Whether the connect-accounts email was sent. false with no emailError means no email was requested.
"title": "Acme Client" // The User Profile's title. Omitted when the profile has none.
}
{
"status": "success",
"sessionId": "c7a2434e72e91bde27579efde0fd6dd0b74ceee29a471fd368407f273708c2e8",
"url": "https://profile.ayrshare.com?session=ayr_ls_kJ8mQ2vX9pLnR4tYwZ6aBcD1eFgH3iJkLmN0oPqRsTu&domain=YOUR_DOMAIN", // Still valid. Send it to your user yourself.
"expiresAt": "2026-09-02T08:03:26.838Z",
"emailSent": false,
"emailError": { // Only present when an email was requested and could not be sent.
"code": 333,
"message": "Email failed to send. Please confirm a valid email was provided."
},
"title": "Acme Client"
}
{
"status": "success",
"sessionId": "c7a2434e72e91bde27579efde0fd6dd0b74ceee29a471fd368407f273708c2e8",
"url": "https://profile.ayrshare.com/connect?session=ayr_ls_kJ8mQ2vX9pLnR4tYwZ6aBcD1eFgH3iJkLmN0oPqRsTu", // Open this in a popup. One network, no domain parameter.
"expiresAt": "2026-09-02T08:03:26.838Z",
"emailSent": false,
"title": "Acme Client"
}
{
"status": "success",
"sessionId": "c7a2434e72e91bde27579efde0fd6dd0b74ceee29a471fd368407f273708c2e8",
"token": "ayr_ls_kJ8mQ2vX9pLnR4tYwZ6aBcD1eFgH3iJkLmN0oPqRsTu", // No url: this shape returns the bare token instead. Treat it like a password.
"expiresAt": "2026-09-02T08:03:26.838Z",
"emailSent": false, // Always false here - email needs a link to send, so it returns code: 510.
"title": "Acme Client"
}
{
"action": "link session",
"status": "error",
"code": 504,
"message": "Connect mode requires the Max Pack. Activate it on your Account page: https://app.ayrshare.com/account"
}
{
"action": "JWT",
"status": "error",
"code": 188,
"message": "Missing or incorrect privateKey, profileKey, domain, email 'to', or expiresIn fields."
}
{
"action": "JWT",
"status": "error",
"code": 189,
"message": "Error generating JWT. Check the sent parameters.",
"details": "Missing or incorrect domain."
}
{
"action": "JWT",
"status": "error",
"code": 340,
"message": "Max Pack required. Go to your dashboard to add the Max Pack."
}