When performing automated operations or working in environments where the vSphere Client user interface is unavailable, administrators may need to upload files (such as ISOs, OVFs, or VMDKs) programmatically. Using the vCenter Content Library REST API allows for structured, scriptable file ingestion directly into designated content libraries.
Furthermore, this method can be leveraged to isolate underlying browser or network-layer constraints when executing uploads from jump hosts or directly from the vCenter Server Appliance.
VMware vCenter Server 8.x
Create a Content Library within your vCenter Server instance.
Navigate to your Content Library in the vSphere Client and extract the Library ID from the browser's address bar.
Example: If the URL is https://<VC_FQDN>/ui/app/content-libraries/cl/urn:vapi:com.vmware.content.Library:65e74fac-####-49a5-####-3b76d0334ee9:59d90142-..., the extracted Library ID is 65e74fac-####-49a5-####-3b76d0334ee9.
Open a secure terminal session and execute the following commands in sequence:
Define your vCenter fully qualified domain name (FQDN) and administrative credentials:
url='https://VC_FQDN' username='administrator@vsphere.local' password='########'
Establish an API session token using your predefined credentials:
session_id=`curl -X POST -k -H 'Content-Type: application/json' -u "$username:$password" "$url/rest/com/vmware/cis/session" | jq -r .value`
Generate a unique UUID identifier to guarantee request idempotency:
client_token=$(uuidgen)
Initialize a new item entry within the target library. Substitute your copied library_id in the payload if different from the example:
curl -X POST -k \
-H 'Accept: application/json' -H "Content-Type: application/json" -H "vmware-api-session-id: $session_id" \
"$url/rest/com/vmware/content/library/item" \
-d '{
"client_token": "'$client_token'",
"create_spec" : {
"description" : "test item",
"type" : "",
"version" : "1",
"content_version" : "obj-103",
"library_id" : "65e74fac-####-49a5-####-3b76d0334ee9",
"size" : 1,
"cached" : true,
"name" : "test-upload",
"id" : "obj-103",
"source_id" : "obj-103",
"metadata_version" : "string"
}
}' | jq -r ".value"
This command outputs the specific library_item_id (e.g., 86dbfd88-####-42b5-####-85b7bc854307).
Open a new active update session linked to your library_item_id generated in Step 4:
curl -X POST -k \
-H 'Accept: application/json' -H "Content-Type: application/json" -H "vmware-api-session-id: $session_id" \
"$url/rest/com/vmware/content/library/item/update-session" \
-d '{
"client_token": "'$client_token'",
"create_spec" : {
"library_item_id" : "86dbfd88-####-42b5-####-85b7bc854307",
"client_progress" : null,
"preview_info" : {
"state" : "UNAVAILABLE"
}
"id" : "12345",
"library_item_content_version" : "",
"state" : "ACTIVE"
}
}' | jq -r ".value"
This command outputs the update_session_id (e.g., e5f1abf6-####-4d0f-####-475525c1ef8a:59d90142-####-4b1b-####-4642fe2e0367).
Declare your upload parameters using the PUSH source type. Ensure the target filename retains its exact extension (e.g., .iso, .ovf, .vmdk):
curl -X POST -k \
-H 'Accept: application/json' -H "Content-Type: application/json" -H "vmware-api-session-id: $session_id" \
"$url/rest/com/vmware/content/library/item/updatesession/file/id:e5f1abf6-####-4d0f-####-475525c1ef8a:59d90142-####-4b1b-####-4642fe2e0367?~action=add" \
-d '{
"file_spec" : {
"name" : "testfileupload.iso",
"source_type" : "PUSH"
}
}' | jq -r ".value"
The response exposes the upload_endpoint URI block required for data ingestion.
Transmit the local binary file to the specific URI endpoint generated in Step 6 via an HTTP PUT operation:
curl --location -g --request PUT 'https://VC_FQDN:443/cls/data/20d85d75###########459693b/testfileupload.iso' -k \ --header 'Content-type: multipart/form-data' \ --form 'form-data=@"/Users/xxx/Downloads/small.iso"'
Poll the update session status to ensure the binary transfer completes successfully:
curl -X POST -k \
-H 'Accept: application/json' -H "Content-Type: application/json" -H "vmware-api-session-id: $session_id" \
"$url/rest/com/vmware/content/library/item/updatesession/file/id:e5f1abf6-####-4d0f-####-475525c1ef8a:59d90142-####-4b1b-####-4642fe2e0367?~action=get" \
-d '{
"file_name" : "testfileupload.iso"
}' | jq -r ".value"
Verify that the tracking parameter returns status: READY before proceeding.
Explicitly commit the finalized state.
CRITICAL WARNING: This session complete action must be executed within 5 minutes of reaching a READY state. Failure to do so will cause the session to expire, invalidating the data transfer.
curl -X POST -k \ -H 'Accept: application/json' -H "Content-Type: application/json" -H "vmware-api-session-id: $session_id" \ "$url/rest/com/vmware/content/library/item/update-session/id:e5f1abf6-####-4d0f-8f02-####
For complete REST API endpoint schemas, refer to the Broadcom Developer Portal.