Sidebar Menu

CreateMediaFromUrl

This method adds a media file to a license key from the media's URL.

Endpoint

POST:
https://messaging.esendex.us/Messaging.svc/CreateMediaFromUrl

Syntax

CreateMediaFromUrl(Request)

Request Parameters

Parameter Name Description Data Type Required Sample Value
FileName

Name of the media file to create.

String True MonkeyPic.jpg
LicenseKey

Your license key.

GUID True 00000000-0000-0000-0000-000000000000
Tags

Category of the media file.

Array of String values False animal
Url

Web location of the file to create.

String True https://esendex.us/img/docs/example.jpg

Response

Returns: MediaMetadata object

Code Samples

You can use any programming language you want with our API, as long as it can make a REST or SOAP call. Here are examples for some of the most common platforms.

// https://messaging.esendex.us/Messaging.svc?wsdl was added as a Service Reference and given the name WSDL

using WSDL;

var client = new MessagingClient(MessagingClient.EndpointConfiguration.mms2wsHttpBindingSecure);

var request = new CreateMediaUrlRequest
{
    Filename = "MyPhoto.jpg",
    LicenseKey = YOUR_LICENSE_KEY,
    Tags = new[] { "Photo" },
    Url = "https://esendex.us/img/docs/example.jpg"
};

var media = await client.CreateMediaFromUrlAsync(request);

if (media is null)
{
    Console.WriteLine("The media could not be created.");
    return;
}

Console.WriteLine(
    "UTC File Date: " + media.FileDate + Environment.NewLine +
    "File Name: " + media.FileName + Environment.NewLine +
    "File Size: " + media.FileSize + Environment.NewLine +
    "Media ID: " + media.MediaId + Environment.NewLine +
    "Mime Type: " + media.MimeType
);

foreach (var tag in media.Tags)
{
    Console.WriteLine("Tags: " + tag);
}
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URL;

public final class CreateMediaFromUrl {

    public static void main(String[] args) throws Exception {
        String responseContent = "";
        String response = "";

        URL url = new URL("https://messaging.esendex.us/Messaging.svc/CreateMediaFromUrl");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();

        StringBuilder sb = new StringBuilder("<CreateMediaUrlRequest xmlns=\"https://messaging.esendex.us\">");
        sb.append("<Filename>JavaMonkey.jpg</Filename>");
        sb.append("<LicenseKey>00000000-0000-0000-0000-000000000000</LicenseKey>");
        sb.append("<Tags>");
        sb.append("<string xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">Monkey</string>");
        sb.append("</Tags>");
        sb.append("<Url>https://picsum.photos/id/0/100</Url>");
        sb.append("</CreateMediaUrlRequest>");

        connection.setRequestProperty("Content-Length", String.valueOf(sb.toString().length()));
        connection.setRequestProperty("Content-Type", "text/xml");
        connection.setRequestProperty("Connection", "Close");
        connection.setRequestProperty("SoapAction", "");
        connection.setRequestMethod("POST");
        connection.setDoInput(true);
        connection.setDoOutput(true);

        PrintWriter pw = new PrintWriter(connection.getOutputStream());
        pw.write(sb.toString());
        pw.flush();
        connection.connect();

        System.out.println(sb.toString());
        BufferedReader br;

        if (connection.getResponseCode() == 200) {
            br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        } else {
            br = new BufferedReader(new InputStreamReader(connection.getErrorStream()));
        }

        while ((responseContent = br.readLine()) != null) {
            response += responseContent;
        }
        System.out.println(response);
    }
}
const url = 'https://messaging.esendex.us/Messaging.svc/CreateMediaFromUrl';
const response = await fetch(url, {
    headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({
        'Filename': 'MyPhoto.jpg',
        'LicenseKey': '00000000-0000-0000-0000-000000000000',
        'Tags': ['Photo'],
        'Url': 'https://esendex.us/img/docs/example.jpg'
    }),
    method: 'POST'
});
const media = await response.json();

console.log(media);
<?php

$json = '{
  "Filename" : "monkeycURL.jpg",
  "LicenseKey" : "00000000-0000-0000-0000-000000000000",
  "Tags" : ["Monkey"],
  "Url" : "https://picsum.photos/id/0/100"
}';

$url = 'https://messaging.esendex.us/Messaging.svc/CreateMediaFromUrl';
$cURL = curl_init();

curl_setopt($cURL, CURLOPT_URL, $url);
curl_setopt($cURL, CURLOPT_POST, true);
curl_setopt($cURL, CURLOPT_POSTFIELDS, $json);
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true);

curl_setopt($cURL, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Accept: application/json'));
// If you desire your results in XML format, use the following line for your HTTP headers and comment out the HTTP headers code line above.
// curl_setopt($cURL, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));

$result = curl_exec($cURL);
curl_close($cURL);
$array = json_decode($result, true);

// print_r($json);
// print_r("\n\n\n\n");
print_r($array);

?>
import httpx

headers = {"Accept": "application/json"}
url = "https://messaging.esendex.us/Messaging.svc/CreateMediaFromUrl"

request = {
    "Filename": "MyPhoto.jpg",
    "LicenseKey": "00000000-0000-0000-0000-000000000000",
    "Tags": ["Photo"],
    "Url": "https://esendex.us/img/docs/example.jpg",
}

with httpx.Client(headers=headers) as client:
    response = client.post(url=url, json=request)

response.raise_for_status()

if response.text == "":
    raise RuntimeError("The media could not be created.")

print(response.json())
require 'json'
require 'net/http'

headers = { Accept: 'application/json', 'Content-Type': 'application/json' }
uri = URI('https://messaging.esendex.us/Messaging.svc/CreateMediaFromUrl')

data = {
  'Filename': 'MyPhoto.jpg',
  'LicenseKey': '00000000-0000-0000-0000-000000000000',
  'Tags': ['Photo'],
  'Url': 'https://esendex.us/img/docs/example.jpg'
}.to_json

response = Net::HTTP.post(uri, data, headers)
raise response.message if response.is_a?(Net::HTTPClientError) || response.is_a?(Net::HTTPServerError)
raise 'The media could not be created.' if response.body == ''

puts JSON.parse(response.body)
{
	"Filename": "String content",
	"LicenseKey": "1627aea5-8e0a-4371-9022-9b504344e724",
	"Tags": [
		"String content"
	],
	"Url": "String content"
}
{
    "FileDate": "\/Date(928164000000-0400)\/",
    "FileName": "String content",
    "FileSize": 9223372036854775807,
    "MediaId": 9223372036854775807,
    "MimeType": "String content",
    "Tags": [
        "String content"
    ]
}
<CreateMediaUrlRequest xmlns="http://sms2.cdyne.com">
  <Filename>String content</Filename>
  <LicenseKey>1627aea5-8e0a-4371-9022-9b504344e724</LicenseKey>
  <Tags>
    <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">String content</string>
    <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">String content</string>
  </Tags>
  <Url>String content</Url>
</CreateMediaUrlRequest>
<MediaMetadata xmlns="http://sms2.cdyne.com">
    <FileDate>1999-05-31T11:20:00</FileDate>
    <FileName>String content</FileName>
    <FileSize>9223372036854775807</FileSize>
    <MediaId>9223372036854775807</MediaId>
    <MimeType>String content</MimeType>
    <Tags>
        <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">String content</string>
        <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">String content</string>
    </Tags>
</MediaMetadata>