media

Upload and manage your images and videos. Starter, Premium or Business Plan required.

Manage your image and video gallery by uploading and retrieving images and videos.

If you already have your media accessible by an external URL, you can skip uploading the files to Ayrshare. POST to the /post endpoint with your externally accessible URL in the mediaURLs body parameter.

post
Upload an image or video

https://app.ayrshare.com/api/media/upload
This endpoint allows you to upload a file or an image or video to include in your post. Returned will be the URL to the image that can be used in a post or HTML page. You can also directly include an image or video hosted at a URL with the media_urls parameter in the /post endpoint.
Request
Response
Request
Headers
Authorization
required
string
Format: Authorization: Bearer API_KEY. See Overview for more information.
Query Parameters
file
required
string
The image or video as a Base64 encoded string: Data URI - data:content/type;base64 Example encoding with Output Format Data URI: Image: https://base64.guru/converter/encode/image Video: https://base64.guru/converter/encode/video Note 1: Max size for video is 10 MB and images 5 MB. Note 2: The /post endpoint accepts larger files via an external URL with the media_urls parameter.
fileName
optional
string
The name of the file for later reference.
description
optional
string
A description for your reference.
Response
200: OK
Return the URL of the uploaded image, id of the image, and metadata provided.
{
"id": "1167335b-6c37-4fc6-ab8a-044e0005d335-jpeg",
"url": "https://images.ayrshare.com/q3Ls85VTsrbODnGIJHpy7PaHWwA3/1167335b-6c37-4fc6-ab8a-044ed885d-jpeg.jpeg",
"fileName": "fun.jpg",
"description": "good times"
}

Request Examples

cURL
Node JS
Python
PHP
cURL
curl \
-H "Authorization: Bearer API_KEY" \
-H 'Content-Type: application/json' \
-d '{"file": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQ...", "fileName": "test.png", "description": "best image"}' \
-X POST https://app.ayrshare.com/api/upload
Node JS
const fetch = require("node-fetch");
const API_KEY = "API_KEY";
const base64 = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQ...";
fetch("https://app.ayrshare.com/api/upload", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${API_KEY}`
},
body: JSON.stringify({
file: base64,
fileName: "test.png",
description: "best image"
}),
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
Python
import requests
payload = {'file': 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQ...',
'fileName': "test.png",
'description': "best image"}
headers = {'Content-Type': 'application/json',
'Authorization': 'Bearer API_KEY'}
r = requests.post('https://app.ayrshare.com/api/upload',
json=payload,
headers=headers)
print(r.json())
PHP
<?php
require 'vendor/autoload.php'; // Composer auto-loader
$client = new GuzzleHttp\Client();
$res = $client->request(
'POST',
'https://app.ayrshare.com/api/upload',
[
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer API_KEY'
],
'file' => 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQ...',
'fileName' => "test.png",
'description' => "best image"
]
);
echo json_encode(json_decode($res->getBody()), JSON_PRETTY_PRINT);

get
Get Upload URL for Larger Files

https://app.ayrshare.com/api/media/uploadUrl
For file uploads greater than 10 MB, obtain a URL to upload a file. Note: - Maximum file upload size 5 GB. - Upload URL valid for 30 minutes after being generated. - Access URL available for 30 days file uploaded. After 30 days the file is deleted. All sent posts are unaffected. - Only available for Premium and Business Plan accounts.
Request
Response
Request
Path Parameters
Authorization
required
string
Format: Authorization: Bearer API_KEY. See Overview for more information.
Query Parameters
fileName
optional
string
Name of the file to be uploaded. Must include an extension such as .png, .jpg, .mov, .mp4, etc.
Response
200: OK
An upload URL and access URL
{
"uploadUrl": "https://storage.googleapis.com/...",
"accessUrl": "https://images.ayrshare.com/Aswmfs3dIEbwLSdhTwnTPJq5UlV2/test.mov"
}

Request Examples

cURL
Node.js
Python
PHP
C#
cURL
curl \
-H "Authorization: Bearer [API Key]" \
-X GET https://app.ayrshare.com/api/media/uploadUrl?filename=test.mov
Node.js
const fetch = require("node-fetch");
const API_KEY = "Your API Key";
fetch("https://app.ayrshare.com/api/media/uploadUrl?filename=test.mov", {
method: "GET",
headers: {
"Authorization": `Bearer ${API_KEY}`
}
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
Python
import requests
headers = {'Authorization': 'Bearer [API_KEY]'}
r = requests.get('https://app.ayrshare.com/api/media/uploadUrl?filename=test.mov', headers=headers)
print(r.json())
PHP
<?php
require 'vendor/autoload.php'; // Composer auto-loader
$client = new GuzzleHttp\Client();
$res = $client->request(
'GET',
'https://app.ayrshare.com/api/media/uploadUrl?filename=test.mov',
[
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer API_KEY'
]
]
);
echo json_encode(json_decode($res->getBody()), JSON_PRETTY_PRINT);
C#
using System;
using System.Net;
using System.IO;
namespace MediaGETRequest_charp
{
class Media
{
static void Main(string[] args)
{
string API_KEY = "API_KEY";
string url = "https://app.ayrshare.com/api/media/uploadUrl?filename=test.mov";
var httpWebRequest = WebRequest.CreateHttp(url);
httpWebRequest.ContentType = "application/json";
httpWebRequest.Headers.Add("Authorization", "Bearer " + API_KEY);
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var response = streamReader.ReadToEnd();
Console.WriteLine(response);
}
}
}
}
  • uploadUrl is the URL used to PUT the media file.

  • accessUrl is the URL to access the media file after upload.

Additional Endpoint Examples

The process to upload larger files:

  • Obtain an upload URL and access URL via the /media/uploadUrl endpoint.

  • Upload the file via a PUT with Content-Type application/octet-stream

  • After uploading the media file, POST to the /post endpoint with the accessUrl in the mediaUrls body parameter.

curl -X PUT \
-H 'Content-Type: application/octet-stream' \
--upload-file test.mov 'uploadUrl'
https://app.ayrshare.com/api/media
Retrieve all the images uploaded to the image gallery.
Request
Response
Request
Headers
Authorization
required
string
Format: Authorization: Bearer [API Key] See Overview for more information.
Response
200: OK
Returns an array of images in the image gallery.
[
{
"id": "5553a26a-cffb-4a31-bd89-dee296d35648-jpeg",
"timeCreated": "2020-07-30T20:23:49.774Z",
"size": "223340",
"url": "https://images.ayrshare.com/LW8kx9Q5smXeJl5CujF7DxFAF1q1/5553a26a-cffb-4a31-bd89-dee296d35648-jpeg.jpeg",
"fileName": "test1.jpeg",
"description": "Test1"
},
{
"id": "93383cc7-7a15-4d16-a5fa-fdda1f9bebe2-jpeg",
"timeCreated": "2020-07-30T20:24:57.421Z",
"size": "223340",
"url": "https://images.ayrshare.com/LW8kx9Q5smXeJl5CujF7DxFAF1q1/93383cc7-7a15-4d16-a5fa-fdda1f9bebe2-jpeg.jpeg",
"fileName": "test2.jpeg",
"description": "Test2"
}
]

Request Header

cURL
Node JS
Python
PHP
C#
cURL
curl \
-H "Authorization: Bearer [API Key]" \
-X GET https://app.ayrshare.com/api/media
Node JS
const fetch = require("node-fetch");
const API_KEY = "Your API Key";
fetch("https://app.ayrshare.com/api/media", {
method: "GET",
headers: {
"Authorization": `Bearer ${API_KEY}`
}
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
Python
import requests
headers = {'Authorization': 'Bearer [API_KEY]'}
r = requests.get('https://app.ayrshare.com/api/media', headers=headers)
print(r.json())
PHP
<?php
require 'vendor/autoload.php'; // Composer auto-loader
$client = new GuzzleHttp\Client();
$res = $client->request(
'GET',
'https://app.ayrshare.com/api/media',
[
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer API_KEY'
]
]
);
echo json_encode(json_decode($res->getBody()), JSON_PRETTY_PRINT);
C#
using System;
using System.Net;
using System.IO;
namespace MediaGETRequest_charp
{
class Media
{
static void Main(string[] args)
{
string API_KEY = "API_KEY";
string url = "https://app.ayrshare.com/api/media";
var httpWebRequest = WebRequest.CreateHttp(url);
httpWebRequest.ContentType = "application/json";
httpWebRequest.Headers.Add("Authorization", "Bearer " + API_KEY);
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var response = streamReader.ReadToEnd();
Console.WriteLine(response);
}
}
}
}