Skip to main content
POST
/
media
JavaScript
import Telnyx from 'telnyx';

const client = new Telnyx({
  apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted
});

const response = await client.media.upload({ media_url: 'http://www.example.com/audio.mp3' });

console.log(response.data);
import os
from telnyx import Telnyx

client = Telnyx(
    api_key=os.environ.get("TELNYX_API_KEY"),  # This is the default and can be omitted
)
response = client.media.upload(
    media_url="http://www.example.com/audio.mp3",
)
print(response.data)
package main

import (
	"context"
	"fmt"

	"github.com/team-telnyx/telnyx-go"
	"github.com/team-telnyx/telnyx-go/option"
)

func main() {
	client := telnyx.NewClient(
		option.WithAPIKey("My API Key"),
	)
	response, err := client.Media.Upload(context.TODO(), telnyx.MediaUploadParams{
		MediaURL: "http://www.example.com/audio.mp3",
	})
	if err != nil {
		panic(err.Error())
	}
	fmt.Printf("%+v\n", response.Data)
}
package com.telnyx.sdk.example;

import com.telnyx.sdk.client.TelnyxClient;
import com.telnyx.sdk.client.okhttp.TelnyxOkHttpClient;
import com.telnyx.sdk.models.media.MediaUploadParams;
import com.telnyx.sdk.models.media.MediaUploadResponse;

public final class Main {
    private Main() {}

    public static void main(String[] args) {
        TelnyxClient client = TelnyxOkHttpClient.fromEnv();

        MediaUploadParams params = MediaUploadParams.builder()
            .mediaUrl("http://www.example.com/audio.mp3")
            .build();
        MediaUploadResponse response = client.media().upload(params);
    }
}
require "telnyx"

telnyx = Telnyx::Client.new(api_key: "My API Key")

response = telnyx.media.upload(media_url: "http://www.example.com/audio.mp3")

puts(response)
<?php

require_once dirname(__DIR__) . '/vendor/autoload.php';

use Telnyx\Client;
use Telnyx\Core\Exceptions\APIException;

$client = new Client(apiKey: getenv('TELNYX_API_KEY') ?: 'My API Key');

try {
  $response = $client->media->upload(
    mediaURL: 'http://www.example.com/audio.mp3',
    mediaName: 'my-file',
    ttlSecs: 86400,
  );

  var_dump($response);
} catch (APIException $e) {
  echo $e->getMessage();
}
telnyx media upload \
  --api-key 'My API Key' \
  --media-url http://www.example.com/audio.mp3
curl --request POST \
  --url https://api.telnyx.com/v2/media \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "media_url": "http://www.example.com/audio.mp3",
  "ttl_secs": 86400,
  "media_name": "my-file"
}
'
{
  "data": {
    "media_name": "f5586561-8ff0-4291-a0ac-84fe544797bd",
    "expires_at": "2020-01-23T18:10:02.574Z",
    "created_at": "2019-01-23T18:10:02.574Z",
    "updated_at": "2019-01-23T18:10:02.574Z",
    "content_type": "application/xml"
  }
}
{
  "errors": [
    {
      "code": "<string>",
      "title": "<string>",
      "detail": "<string>",
      "source": {
        "pointer": "<string>",
        "parameter": "<string>"
      },
      "meta": {}
    }
  ]
}
{
  "errors": [
    {
      "code": "<string>",
      "title": "<string>",
      "detail": "<string>",
      "source": {
        "pointer": "<string>",
        "parameter": "<string>"
      },
      "meta": {}
    }
  ]
}
{
  "errors": [
    {
      "code": "<string>",
      "title": "<string>",
      "detail": "<string>",
      "source": {
        "pointer": "<string>",
        "parameter": "<string>"
      },
      "meta": {}
    }
  ]
}

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Body

Upload media request

media_url
string
required

The URL where the media to be stored in Telnyx network is currently hosted. The maximum allowed size is 20 MB.

Example:

"http://www.example.com/audio.mp3"

ttl_secs
integer

The number of seconds after which the media resource will be deleted, defaults to 2 days. The maximum allowed vale is 630720000, which translates to 20 years.

Example:

86400

media_name
string

The unique identifier of a file.

Example:

"my_file"

Response

A response describing a media resource

data
Media Resource · object
Example:
{
  "media_name": "f5586561-8ff0-4291-a0ac-84fe544797bd",
  "expires_at": "2020-01-23T18:10:02.574Z",
  "created_at": "2019-01-23T18:10:02.574Z",
  "updated_at": "2019-01-23T18:10:02.574Z",
  "content_type": "application/xml"
}