Skip to main content

Create Files API

This API is used to create files in modules of courses or batches in LMS

Request URL: (Self Paced Course)

https://people.zoho.com/api/v1/courses/<courseId>/modules/<moduleId>/files?fileData={"name" : <name>, "file" : <file>, "duration" :<duration>, "description" : <description>, "isMandatory" : <isMandatory>, "isIntroFile" : <isIntroFile>,  "enableDownload" : <enableDownload>, "lockUntil" : <lockUntil>}

Request URL: (Blended Learning Course)

https://people.zoho.com/api/v1/courses/<courseId>/batches/<batchId>/modules/<moduleId>/files?fileData={"name" : <name>,  "file" : <file>, "duration" :<duration>, "description" : <description>, "isMandatory" : <isMandatory>, "isIntroFile" : <isIntroFile>,  "enableDownload" : <enableDownload>, "lockUntil" : <lockUntil>}

Scope:

ZOHOPEOPLE.training.ALL
OR
ZOHOPEOPLE.training.CREATE

Possible Operation Types:

ALL - Complete access to data
CREATE - Only to create data

Method:

POST

Request Parameters

ParametersValues AllowedDefault ValueDescription
*fileData <parameters in JSON Object> JSON Input

 

ParametersValues AllowedDefault ValueDescription
*name<file name><Mandatory>Specify the file name
*file<File><Mandatory>Specify the file
duration<Duration in minutes>-Specify the duration
description<Description>-Specify the description
isMandatory<true|false>trueSpecify if the file is mandatory or not
isIntroFile<true|false>falseSpecify if the file is intro file or not
enableDownload<true|false>trueSpecify if the file can be downloaded or not
lockUntil<lockUntil date in DD-MM-YYYY format>-Specify the lockUntil date
resources<files>-Specify resources

*mandatory parameters

Error Codes and Descriptions

Status CodesDescription
400Invalid parameter value/input parameter missing
403Sorry! You are not authorized to do this operation
404Not found
422Maximum limit exceeded
500Sorry! Server error occured

View complete list of LMS API error codes

Threshold Limit: 30 requests | Lock period: 5 minutes

Threshold Limit - Number of API calls allowed within a minute.
Lock Period - Wait time before consecutive API requests.

Request

Copiedimport java.io.File;
import okhttp3.*;

public class Main {
    public static void main(String[] args) throws Exception {
        OkHttpClient client = new OkHttpClient();

        MediaType mediaType = MediaType.parse("application/pdf");
        File file = new File("D:/Import/1.pdf");

        RequestBody fileBody = RequestBody.create(mediaType, file);
        MultipartBody requestBody = new MultipartBody.Builder()
            .setType(MultipartBody.FORM)
            .addFormDataPart("file", "1.pdf", fileBody)
            .build();

        Request request = new Request.Builder()
            .url("https://people.zoho.com/api/v1/courses/478346000019007001/modules/478346000019007013/files?fileData={\"name\":\"File API Testing\",\"duration\":100,\"description\":\"File API testing\",\"isMandatory\":true,\"isIntroFile\":true,\"enableDownload\":true}")
            .post(requestBody)
            .addHeader("Authorization", "Zoho-oauthtoken YOUR_ACCESS_TOKEN")
            .build();

        Response response = client.newCall(request).execute();
        System.out.println(response.body().string());
    }
}
Copiedconst url = "https://people.zoho.com/api/v1/courses/478346000019007001/modules/478346000019007013/files?fileData=" + 
    encodeURIComponent(JSON.stringify({
        "name": "File API Testing",
        "duration": 100,
        "description": "File API testing",
        "isMandatory": true,
        "isIntroFile": true,
        "enableDownload": true
    }));

const fileInput = document.createElement("input");
fileInput.type = "file";

fileInput.addEventListener("change", function () {
    const file = fileInput.files[0];
    const formData = new FormData();
    formData.append("file", file, file.name);

    fetch(url, {
        method: "POST",
        headers: {
            "Authorization": "Zoho-oauthtoken YOUR_ACCESS_TOKEN"
        },
        body: formData
    })
    .then(response => response.text())
    .then(data => console.log(data))
    .catch(error => console.error(error));
});

document.body.appendChild(fileInput);
Copiedcurl -X POST "https://people.zoho.com/api/v1/courses/478346000019007001/modules/478346000019007013/files?fileData={\"name\":\"File API Testing\",\"duration\":100,\"description\":\"File API testing\",\"isMandatory\":true,\"isIntroFile\":true,\"enableDownload\":true}" \
-H "Authorization: Zoho-oauthtoken YOUR_ACCESS_TOKEN" \
-F "file=@D:/Import/1.pdf;type=application/pdf"
Copiedurl = "https://people.zoho.com/api/v1/courses/478346000019007001/modules/478346000019007013/files";

headers = map();
headers.put("Authorization", "Zoho-oauthtoken YOUR_ACCESS_TOKEN");

file_details = {"name":"File API Testing","duration":100,"description":"File API testing","isMandatory":true,"isIntroFile":true,"enableDownload":true};

params = map();
params.put("fileData", file_details);

file_var = invokeurl
[
    url : url
    type : POST
    headers: headers
    parameters: params
    file: ("/D:/Import/1.pdf", "application/pdf")
];

info file_var;
Copiedimport requests

url = "https://people.zoho.com/api/v1/courses/478346000019007001/modules/478346000019007013/files"
params = {
    "fileData": '{"name":"File API Testing","duration":100,"description":"File API testing","isMandatory":true,"isIntroFile":true,"enableDownload":true}'
}

files = {
    'file': ('1.pdf', open('D:/Import/1.pdf', 'rb'), 'application/pdf')
}

headers = {
    "Authorization": "Zoho-oauthtoken YOUR_ACCESS_TOKEN"
}

response = requests.post(url, headers=headers, params=params, files=files)

print(response.text)

Show full

Show less

Header

CopiedAuthorization: Zoho-oauthtoken 1000.8cb99dxxxxxxxx9be93.9b8xxxxxxf

Response

Copied{
    "code": 200,
    "file": {
        "isMandatoryFile": true,
        "fileName": "File one",
        "previewURL": "",
        "canMarkAsComplete": 0,
        "description": "Description for File",
        "resources": [],
        "canUserDelete": true,
        "duration": "100 Mins",
        "lockUntil": "27-12-2021",
        "isDownloadable": true,
        "isIntroFile": true,
        "isLocked": true,
        "canUserEdit": true,
        "moduleId": "219225000000648001",
        "fileId": "219225000000648115"
    },
    "message": "success"
}

Show full

Show less