Types

Resources are essentially files stored on the server and are used in almost all requests. They can be of 5 types:

  1. Text: A text file resource of extension txt.
  2. Image: An image file of extension jpg, jpeg or png.
  3. Audio: An audio file of extension mp3, wav.
  4. Video: A video file of extension mp4.
  5. Csv: A csv file of extension csv.
If you need other file types, please contact us.

Prerequisites

  • You have an API key. If not, you can get one by contacting us.
  • You have python installed on your machine along with the requests library.

Upload resources

For files smaller than 5MB, you can directly upload the file using the API as follows. For larger files, follow the Large Resources guide.

Creating a text resource

Python
import sys
import requests

base_url = "https://api.verbalia.net"

headers = {"X-API-Key": "<api_key>"}

files = {
  'file': ('text.txt', bytes('Welcome to Verbalia\'s workshop...', 'utf-8'), 'text/plain')
}
# If you want to load a txt file from disk, comment out the above line
# and uncomment the below line
# files = {'file': ('text.txt', open('text.txt', 'rb'), 'text/plain')}

data = {
    'resource_name': 'workshop-content', # Descriptive name
    'resource_type': 'text' # One of the 5 types
}

# Make the POST request
response = requests.post(
  base_url + "/resources/upload",
  files=files,
  params=data,
  headers=headers
)

# Check the response
if response.status_code != 200:
    print(f'Failed to upload file. Status code: {response.status_code}')
    print('Response:', response.text)
    sys.exit(1)
print('Upload successful', response.json())
# Contains resource_id which should be noted

Creating an image resource

Python
import sys
import requests

base_url = "https://api.verbalia.net"

headers = {"X-API-Key": "<api_key>"}

files = {
  'file': ('image.jpg', open('image.jpg', 'rb'), 'image/jpeg')
}

data = {
    'resource_name': 'workshop-image', # Descriptive name
    'resource_type': 'image' # One of the 5 types
}

# Make the POST request
response = requests.post(
  base_url + "/resources/upload",
  files=files,
  params=data,
  headers=headers
)

# Check the response
if response.status_code != 200:
    print(f'Failed to upload file. Status code: {response.status_code}')
    print('Response:', response.text)
    sys.exit(1)
print('Upload successful', response.json())
# Contains resource_id which should be noted

Creating an audio resource

Python
import sys
import requests

base_url = "https://api.verbalia.net"

headers = {"X-API-Key": "<api_key>"}
files = {
  'file': ('audio.mp3', open('audio.mp3', 'rb'), 'audio/mpeg')
}

data = {
    'resource_name': 'workshop-audio', # Descriptive name
    'resource_type': 'audio' # One of the 5 types
}

# Make the POST request
response = requests.post(
  base_url + "/resources/upload",
  files=files,
  params=data,
  headers=headers
)

# Check the response
if response.status_code != 200:
    print(f'Failed to upload file. Status code: {response.status_code}')
    print('Response:', response.text)
    sys.exit(1)
print('Upload successful', response.json())
# Contains resource_id which should be noted

Creating a video resource

Python
import sys
import requests

base_url = "https://api.verbalia.net"

headers = {"X-API-Key": "<api_key>"}

files = {
  'file': ('video.mp4', open('video.mp4', 'rb'), 'video/mp4')
}

data = {
    'resource_name': 'workshop-video', # Descriptive name
    'resource_type': 'video' # One of the 5 types
}

# Make the POST request

response = requests.post(
  base_url + "/resources/upload",
  files=files,
  params=data,
  headers=headers
)

# Check the response
if response.status_code != 200:
    print(f'Failed to upload file. Status code: {response.status_code}')
    print('Response:', response.text)
    sys.exit(1)
print('Upload successful', response.json())
# Contains resource_id which should be noted

Creating a csv resource

Python
import sys
import requests

base_url = "https://api.verbalia.net"

headers = {"X-API-Key": "<api_key>"}

files = {
  'file': ('sales.csv', open('sales.csv', 'rb'), 'text/csv')
}

data = {
    'resource_name': 'sales-prospects-v1', # Descriptive name
    'resource_type': 'csv' # One of the 5 types
}

# Make the POST request
response = requests.post(
  base_url + "/resources/upload",
  files=files,
  params=data,
  headers=headers
)

# Check the response
if response.status_code != 200:
    print(f'Failed to upload file. Status code: {response.status_code}')
    print('Response:', response.text)
    sys.exit(1)
print('Upload successful', response.json())
# Contains resource_id which should be noted

List resources

You can list all resources owned by you using the following code snippet.

Python
import sys
import requests

base_url = "https://api.verbalia.net"

headers = {"X-API-Key": "<api_key>"}

# Make the GET request
response = requests.get(base_url + "/resources", headers=headers)

# Check the response
if response.status_code != 200:
    print(f'Failed to get resources. Status code: {response.status_code}')
    print('Response:', response.text)
    sys.exit(1)

print('Get successful', response.json())