Ideas en bits

Creating a Videoask with media question through the API

This is an example of how to create a simple form with an open question type, sending the media to be translated. I'm going to use Python with the requests library for HTTP requests, and boto3 for S3 connections.

1. Create the Form

import os

from requests import request


bearer_token = os.getenv("API_TOKEN")
headers = {
    "Authorization": f"Bearer {bearer_token}",
}

forms_url = "https://api.videoask.com/forms"
payload = {"title": "My Custom Videoask"}

response = request("POST", forms_url, headers=headers, json=payload)

-> Response of previous requests will look like

{
  "form_id": "ef611898-de6c-46d0-9109-3f28189ee265",
  "organization_id": "5209e520-0abd-488e-85c9-5383456e1aee",
  "title": "My Custom Videoask",
  "requires_contact_info": false,
  "requires_contact_email": false,
  "requires_contact_name": false,
  "requires_contact_phone_number": false,
  "requires_consent": false,
  "show_contact_name": false,
  "show_contact_email": false,
  "show_contact_phone_number": false,
  "show_consent": false,
  "hide_branding": false,
  "share_id": "fx3nb31hw",
  "share_url": "https://www.videoask.com/fx3nb31hw",
  "created_at": "2020-12-24T08:59:32.110770Z",
  "updated_at": "2020-12-24T08:59:32.111496Z",
  "respondents_count": 0,
  "author_id": "deda849c-dbf5-47a4-9826-243cb1e6f874",
  "questions": [],
  "are_answers_public": false,
  "are_messages_public": false,
  "notifications": { "send_contact_message_emails": true },
  "responses_share_id": "r9dee382bxa1apa3isua15xqj0krqgwjnj11sxcz",
  "responses_share_url": "https://www.videoask.com/r9dee382bxa1apa3isua15xqj0krqgwjnj11sxcz",
  "tag_share_id": "zef4qztmy76rqoezu289o4jhejjyp7ub3x1sh3md",
  "tag_share_url": "https://www.videoask.com/zef4qztmy76rqoezu289o4jhejjyp7ub3x1sh3md"
}

2. Create an Open question

In this case we will create an open question that will accept audio, video and text as responses. Given we are going to upload a custom video, we should specify media_type and media_mime_type (within the thumbnail_mime_type). The request will looks like:

import os

from requests import request


bearer_token = os.getenv("API_TOKEN")
headers = {
    "Authorization": f"Bearer {bearer_token}",
}

questions_url = "https://api.videoask.com/questions"
payload = {
    # ID obtained from previous step
    "form_id": "<form-id>", 
    "media_type": "video",
    "media_mime_type": "video/webm",
    "thumbnail_mime_type": "image/jpeg",
    "allowed_answer_media_types": ["video", "audio", "text"],
}
response = request(
    "POST", questions_url, headers=headers, json=payload
)

-> The response of this request will look like

{
  "allowed_answer_media_types": ["video", "audio", "text"],
  "created_at": "2020-12-24T09:17:09.822748Z",
  "form_id": "<form-id>",
  "media_id": "<media-id>",
  "media_type": "video",
  "media_upload": {
    "credentials": {
      "AccessKeyId": "<Access Key>",
      "SecretAccessKey": "<Access Secret Key>",
      "SessionToken": "<Access Session Key>",
      "Expiration": "2020-12-24T09:32:09Z"
    },
    "object_key": "raw/1458c406-7ee6-4e6e-a583-60f8824d4b1f/video.webm",
    "thumbnail_object_key": "raw/1458c406-7ee6-4e6e-a583-60f8824d4b1f/thumbnail.jpeg",
    "bucket": "videoask-uploads",
    "region": "us-east-1",
    "mime_type": "video/webm"
  },
  "media_url": "https://media.videoask.com/raw/1458c406-7ee6-4e6e-a583-60f8824d4b1f/video.webm?token===",
  "allow_multiple_selection": false,
  "question_id": "<question-id>",
  "share_id": "fx3nb31hw",
  "share_url": "https://www.videoask.com/fx3nb31hw",
  "thumbnail": "https://media.videoask.com/raw/1458c406-7ee6-4e6e-a583-60f8824d4b1f/thumbnail.jpeg",
  "transcode_status": "upload_pending",
  "transcribe_status": "pending",
  "type": "standard",
  "updated_at": "2020-12-24T09:17:09.823193Z"
}

3. Upload a Video

Now we have created the question, and we receive S3 credentials to upload the file, this information comes in this part of the response object:

 "media_upload": {
    "credentials": {
      "AccessKeyId": "<Access Key>",
      "SecretAccessKey": "<Access Secret Key>",
      "SessionToken": "<Access Session Key>",
      "Expiration": "2020-12-24T09:32:09Z"
    },
    "object_key": "raw/1458c406-7ee6-4e6e-a583-60f8824d4b1f/video.webm",
    "thumbnail_object_key": "raw/1458c406-7ee6-4e6e-a583-60f8824d4b1f/thumbnail.jpeg",
    "bucket": "videoask-uploads",
    "region": "us-east-1",
    "mime_type": "video/webm"
  }

And now using boto3 and having a local file (in this case saved in resources/media_example.webm) we could upload the video by doing:

import boto3
from botocore.exceptions import NoCredentialsError

# Following data is obtained from `media_upload` object received in last step
ACCESS_KEY = ""
SECRET_KEY = ""
SESSION_TOKEN = ""
BUCKET = ""
REGION = ""
OBJECT_KEY = ""

# Instantiate S3 client
s3 = boto3.client(
    "s3",
    region_name=REGION,
    aws_access_key_id=ACCESS_KEY,
    aws_secret_access_key=SECRET_KEY,
    aws_session_token=SESSION_TOKEN,
)

# Upload local file
s3.upload_file("resources/media_example.webm", BUCKET, OBJECT_KEY)