media
Media API Endpoint: Upload and manage your images and videos. Premium or Business Plan required.

Media API Endpoint

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 provided. See the response example in the /media/upload below. 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.
Click the β€Ί in the endpoint to view details.
post
https://app.ayrshare.com/api
/media/upload
Upload Image or Video
​

Request Examples

cURL
Node JS
Python
PHP
1
curl \
2
-H "Authorization: Bearer API_KEY" \
3
-H 'Content-Type: application/json' \
4
-d '{"file": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQ...", "fileName": "test.png", "description": "best image"}' \
5
-X POST https://app.ayrshare.com/api/media/upload
Copied!
1
const fetch = require("node-fetch");
2
const API_KEY = "API_KEY";
3
const base64 = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQ...";
4
​
5
fetch("https://app.ayrshare.com/api/media/upload", {
6
method: "POST",
7
headers: {
8
"Content-Type": "application/json",
9
"Authorization": `Bearer ${API_KEY}`
10
},
11
body: JSON.stringify({
12
file: base64,
13
fileName: "test.png",
14
description: "best image"
15
}),
16
})
17
.then((res) => res.json())
18
.then((json) => console.log(json))
19
.catch(console.error);
Copied!
1
import requests
2
​
3
payload = {'file': 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQ...',
4
'fileName': "test.png",
5
'description': "best image"}
6
headers = {'Content-Type': 'application/json',
7
'Authorization': 'Bearer API_KEY'}
8
​
9
r = requests.post('https://app.ayrshare.com/api/media/upload',
10
json=payload,
11
headers=headers)
12
13
print(r.json())
Copied!
1
<?php
2
require 'vendor/autoload.php';// Composer auto-loader using Guzzle. See https://docs.guzzlephp.org/en/stable/overview.html
3
​
4
$client = new GuzzleHttp\Client();
5
$res = $client->request(
6
'POST',
7
'https://app.ayrshare.com/api/media/upload',
8
[
9
'headers' => [
10
'Content-Type' => 'application/json',
11
'Authorization' => 'Bearer API_KEY'
12
],
13
'file' => 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQ...',
14
'fileName' => "test.png",
15
'description' => "best image"
16
]
17
);
18
​
19
echo json_encode(json_decode($res->getBody()), JSON_PRETTY_PRINT);
Copied!
​
get
https://app.ayrshare.com/api
/media/uploadUrl
Upload Large Media Files

Request Examples

cURL
Node.js
Python
PHP
C#
1
curl \
2
-H "Authorization: Bearer [API Key]" \
3
-X GET https://app.ayrshare.com/api/media/uploadUrl?fileName=test.mov
Copied!
1
const fetch = require("node-fetch");
2
const API_KEY = "Your API Key";
3
​
4
fetch("https://app.ayrshare.com/api/media/uploadUrl?fileName=test.mov", {
5
method: "GET",
6
headers: {
7
"Authorization": `Bearer ${API_KEY}`
8
}
9
})
10
.then((res) => res.json())
11
.then((json) => console.log(json))
12
.catch(console.error);
Copied!
1
import requests
2
​
3
headers = {'Authorization': 'Bearer [API_KEY]'}
4
​
5
r = requests.get('https://app.ayrshare.com/api/media/uploadUrl?fileName=test.mov', headers=headers)
6
7
print(r.json())
Copied!
1
<?php
2
require 'vendor/autoload.php'; // Composer auto-loader using Guzzle. See https://docs.guzzlephp.org/en/stable/overview.html
3
​
4
$client = new GuzzleHttp\Client();
5
$res = $client->request(
6
'GET',
7
'https://app.ayrshare.com/api/media/uploadUrl?fileName=test.mov',
8
[
9
'headers' => [
10
'Content-Type' => 'application/json',
11
'Authorization' => 'Bearer API_KEY'
12
]
13
]
14
);
15
​
16
echo json_encode(json_decode($res->getBody()), JSON_PRETTY_PRINT);
Copied!
1
using System;
2
using System.Net;
3
using System.IO;
4
​
5
namespace MediaGETRequest_charp
6
{
7
class Media
8
{
9
static void Main(string[] args)
10
{
11
string API_KEY = "API_KEY";
12
string url = "https://app.ayrshare.com/api/media/uploadUrl?fileName=test.mov";
13
​
14
var httpWebRequest = WebRequest.CreateHttp(url);
15
httpWebRequest.ContentType = "application/json";
16
httpWebRequest.Headers.Add("Authorization", "Bearer " + API_KEY);
17
​
18
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
19
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
20
{
21
var response = streamReader.ReadToEnd();
22
Console.WriteLine(response);
23
}
24
}
25
}
26
}
Copied!
  • 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.
1
curl -X PUT \
2
-H 'Content-Type: application/octet-stream' \
3
--upload-file test.mov 'uploadUrl'
Copied!
​
​

Request Header

cURL
Node JS
Python
PHP
C#
1
curl \
2
-H "Authorization: Bearer [API Key]" \
3
-X GET https://app.ayrshare.com/api/media
Copied!
1
const fetch = require("node-fetch");
2
const API_KEY = "Your API Key";
3
​
4
fetch("https://app.ayrshare.com/api/media", {
5
method: "GET",
6
headers: {
7
"Authorization": `Bearer ${API_KEY}`
8
}
9
})
10
.then((res) => res.json())
11
.then((json) => console.log(json))
12
.catch(console.error);
Copied!
1
import requests
2
​
3
headers = {'Authorization': 'Bearer [API_KEY]'}
4
​
5
r = requests.get('https://app.ayrshare.com/api/media', headers=headers)
6
7
print(r.json())
Copied!
1
<?php
2
require 'vendor/autoload.php'; // Composer auto-loader using Guzzle. See https://docs.guzzlephp.org/en/stable/overview.html
3
​
4
$client = new GuzzleHttp\Client();
5
$res = $client->request(
6
'GET',
7
'https://app.ayrshare.com/api/media',
8
[
9
'headers' => [
10
'Content-Type' => 'application/json',
11
'Authorization' => 'Bearer API_KEY'
12
]
13
]
14
);
15
​
16
echo json_encode(json_decode($res->getBody()), JSON_PRETTY_PRINT);
Copied!
1
using System;
2
using System.Net;
3
using System.IO;
4
​
5
namespace MediaGETRequest_charp
6
{
7
class Media
8
{
9
static void Main(string[] args)
10
{
11
string API_KEY = "API_KEY";
12
string url = "https://app.ayrshare.com/api/media";
13
​
14
var httpWebRequest = WebRequest.CreateHttp(url);
15
httpWebRequest.ContentType = "application/json";
16
httpWebRequest.Headers.Add("Authorization", "Bearer " + API_KEY);
17
​
18
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
19
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
20
{
21
var response = streamReader.ReadToEnd();
22
Console.WriteLine(response);
23
}
24
}
25
}
26
}
Copied!
Last modified 5d ago