# 3Speak.tv API Usage Guide
## How to log in?
- Send a get request
- https://studio.3speak.tv/mobile/login?username=sagarkothari88
- Here replace `sagarkothari88` with other hive username.
- In response, you'll get encoded memo.
- Decode it using user's private posting key
- You can use [HiveKeychains's `requestVerifyKey` method](requestVerifyKey) to decode it.
- If you're able to decode it, you're considered logged in.
- This is JWT token. Use it in the headers of next requests
- ``'Authorization: Bearer DecodedToken'``
## How to get all videos uploaded by a user?
- API Endpoint - https://studio.3speak.tv/mobile/api/my-videos
- HTTP Headers
- Content-Type: application/json
- Authorization: Bearer DecodedJWToken
- HTTP Method - GET
- In response, you'll get an array of video objects
- Please review the `status` attribute carefully.
- It can have following values
- `uploaded` - 0 - video was just uploaded
- `encoding_queued` - 1 - video is now queued for encoding
- `encoding` - 2 - video is now being encoded by encoder node
- `encoding_failed` - 3 - video encoding failed after 5 attempts from different encoder nodes.
- `deleted` - 4 - user can mark this video as deleted.
- `publish_manual` - 5 - video is ready to be published.
- `published` - 6 - video was published.
## How to upload Video / Thumbnail to 3Speak Infra?
- https://uploads.3speak.tv/files
- Use above URL to initiate tus connection.
- https://tus.io/
- https://github.com/tus/tus-js-client
- Use above specified TUS library to upload content using Resumable upload protocol.
- Upon hitting the `onComplete` method of TUS, Client gets a url
```
onSuccess: function() {
console.log("Download %s from %s", upload.file.name, upload.url)
}
```
- Grab the Upload URL & replace it with 3Speak infra URL.
```
let fileUrl = upload.url.replace('https://uploads.3speak.tv/files, '')
```
## Create a 3Speak Video Object
- Once done uploading the video, grab the upload url as specified in previous step.
- Use following API to create a 3Speak Video Object
- Request body as json
```
{
'filename': filename, // string
'oFilename': oFilename, // string
'size': size, // int in bytes
'duration': duration, // int in seconds
'thumbnail': thumbnail, // string - fileUrl specified above
'owner': owner, // string - hive username
}
```
- API Endpoint - https://studio.3speak.tv/mobile/api/upload_info?app=ecency
- queryParam - set `app` = `yourFancyAppName`
- HTTP Headers
- Content-Type: application/json
- Authorization: Bearer DecodedJWToken
- HTTP Method - POST
- In response, You'll get the Video Object.
## Update MetaData of Video
- Request body as json
```
{
'videoid': videoid, // String - you get this from video object
'title': title, // String
'description': description, // String
'isNsfwContent': false,
'tags': tags, // String - comma separated
'thumbnail': thumbnail, // String - fileUrl specified above
}
```
- API Endpoint - https://studio.3speak.tv/mobile/api/update_info
- HTTP Headers
- Content-Type: application/json
- Authorization: Bearer DecodedJWToken
- HTTP Method - POST
## Publishing on Hive
- Video Status
- You can use any of the video with status `publish_manual`.
- Permlink
- Use the permlink from the video object while publishing on hive.
- Bebeficiaries
- Make sure to add all beneficiaries specified in the video object.
- You'll find an attribute called beneficiaries
- Also, don't forget to add following beneficiaries
- spk.beneficiary - 900 weight (9.0%)
- threespeakleader - 100 weight (1.0%)
- In following example, you can see that you're suppose to set 1.00% beneficiary to vaultec as he encoded the video.
```
"beneficiaries": "[{\"account\":\"vaultec\",\"weight\":100,\"src\":\"ENCODER_PAY\"}]",
```
- Making Video available
- Once you publish the post on hive, use following API to make the video available & playable.
- Make sure that the post is available via Hive RPC nodes.
- This API will verify if post contains right set of beneficiaries or not.
- Upon finding valid beneficiaries, 3Speak will make the video available & playable.
- Request body as json
```
{
'videoId': videoid,
}
```
- API Endpoint - https://studio.3speak.tv/mobile/api/my-videos/iPublished
- HTTP Headers
- Content-Type: application/json
- Authorization: Bearer DecodedJWToken
- HTTP Method - POST