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. Please be sure to verify the media URL before using it to post.
Recommendation: 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.
Upload Image or Video
POSThttps://app.ayrshare.com/api/media/upload
This endpoint allows you to upload a file or an image or small video to include in your post. Returned will be the URL to the image that can be used in the /post endpoint.
Your can pass the file either as a multipart form data as a form parameter or a Base64 encoded file as a body parameter.
Note 1: Media is available for 90 days after upload. All sent posts are unaffected.
Note 2: Max size is 10 MB. See uploadUrl API endpoint below for larger files.
Premium or Business Plan required.
Headers
Name
Type
Description
Authorization*
string
Format: Authorization: Bearer API_KEY. See Overview for more information.
Content-Type*
string
multipart/form-data if sending a multipart form data - see below. Otherwise, send the standard application/json.
Request Body
Name
Type
Description
file*
string or object
Send as Base64
Send the media file as a Base64 encoded string as a Data URI string. 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 mediaUrls parameter.
Send as Multipart Form-Data
Send the media file as a multipart form-data object. Please be sure to specify the Content-Type as mentioned above.
{"action":"request","status":"error","code":101, "message": "Missing or incorrect parameters. Please verify with the docs. https://docs.ayrshare.com/rest-api/endpoints"
}
<?phprequire 'vendor/autoload.php';// Composer auto-loader using Guzzle. See https://docs.guzzlephp.org/en/stable/overview.html
$client =newGuzzleHttp\Client();$res = $client->request('POST','https://app.ayrshare.com/api/media/upload', ['headers'=> ['Content-Type'=>'application/json','Authorization'=>'Bearer API_KEY' ],'file'=>'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQ...','fileName'=>"test.png",'description'=>"best image" ]);echojson_encode(json_decode($res->getBody()), JSON_PRETTY_PRINT);
Upload Large Media Files
GEThttps://app.ayrshare.com/api/media/uploadUrl
For file uploads greater than 10 MB, obtain a presigned URL to upload a file.
Note:
- Maximum file upload size 5 GB.
- Upload presigned URL valid for 30 minutes after being generated.
- Access URL available for 30 days after uploaded. All sent posts are unaffected.
Premium or Business Plan required.
Query Parameters
Name
Type
Description
fileName*
string
If the contentType is not present, required.
Name of the file to be uploaded. Must include an extension such as .png, .jpg, .mov, .mp4, etc.
contentType*
string
The content-type of the media being uploaded. Valid formats include: mp4, quicktime, png, jpg, or jpeg.
If not present, application/octet-stream will be used.
Headers
Name
Type
Description
Authorization*
string
Format: Authorization: Bearer API_KEY. See Overview for more information.
accessUrl is the URL to access the media file after upload.
contentType is the content-type set for the media being upload. Use this in the Content-Type header when uploading the media.
uploadUrl is the URL used to PUT the media file. Please see below.
Additional Endpoint Examples
The process to upload larger files:
Obtain an uploadURL and accessURL via the /media/uploadUrl endpoint. Please see above.
Upload the file via a PUT with Content-Type set to the returned contentType.
Upload the media by using the --upload-file with a media file and the uploadUrl.
After uploading the media file, POST to the /post endpoint with the accessUrl in the mediaUrls body parameter.
The presigned upload URL may only be uploaded to once. If you sent a bad file you must create a new upload URL. No error response will occur if the file is not successfully uploaded. See below of verifying the URL exists.
Please be sure that the contentType set when creating the uploadUrl matches the Content-Type and the file type when PUTing the file. For example, if you set the contentType to "image/png" when creating the uploadUrl, be sure to set the "Content-Type: image/png" and the uploaded file ends in ".png".
Example Upload File Binary in Node.js
Here is an example of uploading a binary media file using Node with JavaScript:
You may also use Postman to upload the binary file to the uploadUrl.
In Postman:
Select the HTTP Method PUT.
Paste your uploadUrl in the url field. Note, the url will expire after an hour and may only be used once. If you make a call and it fails, you must regenerate the uploadUrl.
In Headers set the Content-Type to be the content type returned in the /uploadUrl endpoint. For example: Content-Type: image/png.
Select Body -> binary and select the file to upload.
Press Send.
Important: No return response will occur, so you should check if the upload was successful by opening the accessUrl returned from the /uploadUrl endpoint in a browser. You may also use the verify URL endpoint.
Verify Media URL Exists
POSThttps://app.ayrshare.com/api/media/urlExists
Verify that the media file exists when uploaded. It should be used in conjunction with the /media/uploadUrl endpoint.
Headers
Name
Type
Description
Authorization*
string
Format: Authorization: Bearer API_KEY. See Overview for more information.
The social networks have specific requirements for social media images. The resize endpoint allows you to choose a social network compatible image size, add watermarks, change backgrounds, add effects, and more.
By default resizing will change the dimensions of an image, but not crop the image. You may instead crop the image. See below for details.
Headers
Name
Type
Description
Authorization*
string
Authorization: Bearer API_KEY See Overview for more information.
Request Body
Name
Type
Description
imageUrl*
string
URL of image to be resized. Must begin with https://
file
object
Send the media file as a multipart form-data object. Required if imageUrl not present.
watermarkUrl
string
URL of watermark to be applied to resized image. The watermark will appear in the lower right corner of the image. Please see below for details.
platform*
string
Social media platform for which the URL will be resized. Please see below for details.
effects
object
Change opacity, colors, etc. Please see below for details.
dimensions
object
Object specifying width and height for resizing. If cropping optionally specify the center x and y coordinates. Default is the center of the image.
E.g:
{
“width”: 500,
“height”: 500,
"xCoordinate: 35, // optional for crop mode
"yCoordinate": 50 // optional for crop mode
}
Width and height required if platform is not specified.
mode
string
Value: blur or crop. Default: resize. Please see below for details.
{"action":"resize","status":"error","code":312, "message": "Invalid extension type. Extension: null. Please verify the extension is one of the following: png, jpg, jpeg and the file is accessible."
}
Specify a platform as a String to use predefined dimensions of the image. Or you may specify your own with dimension field.
For example "platform": "facebook" will set the dimension of the image as width 1200px and height 630px.
facebook: 1200px width, 630px height.
instagram: 1080px width, 1080px height.
instagram_landscape: 1080px width, 680px height.
instagram_portrait: 1080px width, 1350px height.
instagram_special: 1080px width, 800px height.
linkedin: 1200px width, 627px height.
pinterest: 1080px width, 1920px height.
twitter: 1600px width, 900px height.
Mode
Crop
Crop will cut off "crop" the image to the specified dimensions. By default the center coordinate will be the center of the image. You may also specify your own x/y coordinates.
For example:
{"dimensions": {// If no width and height the platform dimensions will be used, for example Instagram"width":1080,"height":1080,"xCoordinates":35,"yCoordinates":50 }}
Either the platform or the dimensions field width and height must be specified.
For square crops, if width or height are less than the dimensions of the provided image, the small of the width or height will be used. For example, if the image is 1200x800 and the crop requested is 1080x1080, the image returned will be 800x800.
Blur
Blur effect will duplicate the image as a background and blur.
You may add a watermark to the image by providing a URL, which must begin with https://. The watermark will appear in the bottom right corner of the image. We recommend a PNG with a transparent background.
You made change the primary image color by specifying grayscale, sepia, or invert. The field "blur": true is not required and should not be used if you do not want a background.
Set the opacity of the image. Number value range: 0 - 1. For example: "opacity": 0.2
Quality
For JPG or JEPG images specify the quality, or amount of compression, of the image. The lower the number the more compressed, but lower the image quality. The higher the number the less compressed, but the higher the image quality. Number value range: 0 - 100. For example: "quality": 20
Metadata on a media file
GEThttps://app.ayrshare.com/api/media/meta
Get the metadata on a provided media file URL.
Query Parameters
Name
Type
Description
url*
string
Encoded URI of the externally accessible media file URL.
Headers
Name
Type
Description
Authorization*
string
Format: Authorization: Bearer API_KEY. See Overview for more information.
{"codec":"h264","duration":28.24,// In seconds"filename":"https://img.ayrshare.com/random/landscape16.mp4","format":"QuickTime / MOV","height":1080,"size":16275959,// In bytes"type":"video","width":1920}
{"action":"post","status":"error","code":229,"message":"Error validating video. Please check the video or URL."}
Request Examples
GET https://app.ayrshare.com/api/media/meta?url=https%3A%2F%2Fimg.ayrshare.com%2Frandom%2Flandscape16.mp4