Types
Resources are essentially files stored on the server and are used in almost all requests. They can be of 5 types:
- Text: A text file resource of extension
txt
.
- Image: An image file of extension
jpg
, jpeg
or png
.
- Audio: An audio file of extension
mp3
, wav
.
- Video: A video file of extension
mp4
.
- 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
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')
}
data = {
'resource_name': 'workshop-content',
'resource_type': 'text'
}
response = requests.post(
base_url + "/resources/upload",
files=files,
params=data,
headers=headers
)
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())
Creating an image resource
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',
'resource_type': 'image'
}
response = requests.post(
base_url + "/resources/upload",
files=files,
params=data,
headers=headers
)
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())
Creating an audio resource
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',
'resource_type': 'audio'
}
response = requests.post(
base_url + "/resources/upload",
files=files,
params=data,
headers=headers
)
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())
Creating a video resource
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',
'resource_type': 'video'
}
response = requests.post(
base_url + "/resources/upload",
files=files,
params=data,
headers=headers
)
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())
Creating a csv resource
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',
'resource_type': 'csv'
}
response = requests.post(
base_url + "/resources/upload",
files=files,
params=data,
headers=headers
)
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())
List resources
You can list all resources owned by you using the following code snippet.
import sys
import requests
base_url = "https://api.verbalia.net"
headers = {"X-API-Key": "<api_key>"}
response = requests.get(base_url + "/resources", headers=headers)
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())