media

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

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

Automatically resized Instagram images with the ideal dimensions of 1080 x 1080 px are proved. Resized image names end in _1080x1080

If you already have your media accessible by an external URL, such as an S3 bucket, you can skip uploading the files to Ayrshare. Just POST to the /post endpoint with your externally accessible URL in the mediaURLs body parameter and your file will automatically be uploaded.

post
Upload 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. Your can pass the file either as a multipart form data or a a Base64 encoded file. Choose to send either the form parameters or the body parameters. Note 1: Media is available for 90 days after upload. All sent posts are unaffected. Note 2: Max size is 10 MB. See uploadUrl below for larger files. Premium or Business Plan required.
Request
Response
Request
Headers
Authorizaton
required
string
Format: Authorization: Bearer API_KEY. See Overview for more information.
Content-Type
optional
string
multipart/form-data Only use if sending a multipart form data. See below.
Form Data Parameters
file
required
object
Multipart form-data file to be uploaded.
fileName
optional
string
The name of the file for later reference.
description
optional
string
A description for later reference.
Body Parameters
file
required
string
The image or video as a Base64 encoded string as a Data URI. The string should begin with 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: 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 later 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",
"url_1080": "https://images.ayrshare.com/q3Ls85VTsrbODnGIJHpy7PaHWwA3/1167335b-6c37-4fc6-ab8a-044ed885d_1080x1080.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
Upload Large Media 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 90 days after uploaded. All sent posts are unaffected. Premium or Business Plan required.
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.png",
"accessUrl_1080": "https://images.ayrshare.com/Aswmfs3dIEbwLSdhTwnTPJq5UlV2/test_1080x1080.png"
}

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 include resized images ideal for Instagram.
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",
"url_1080": "https://images.ayrshare.com/LW8kx9Q5smXeJl5CujF7DxFAF1q1/5553a26a-cffb-4a31-bd89-dee296d35648_1080x1080.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",
"url_1080": "https://images.ayrshare.com/LW8kx9Q5smXeJl5CujF7DxFAF1q1/93383cc7-7a15-4d16-a5fa-fdda1f9bebe2_1080x1080.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);
}
}
}
}