End and Delete a Live Video
Learn how to end and delete a live video.
End a live video
To end a live video on Facebook using the Facebook Graph API, we need to make a POST
request to the live video's terminate endpoint. The base URL of the endpoint is:
https://graph.facebook.com/v16.0/{{live_video_id}}/live_videos?end_live_video=true
Request parameters
The request parameters for the endpoint are given below.
Parameter | Type | Category | Description |
| String | Mandatory | This is the token that we received after app authentication and authorization. |
| String | Mandatory | This is the ID of the live video. Note that this is a path parameter. |
| Boolean | Mandatory | This is the boolean value that must be set to |
The code below uses the endpoint above to end a live video. Click the “Run” button to see the response.
Note: This endpoint will only work if there is a live video running on the created live video broadcast.
// Importing libraries hereimport fetch from "node-fetch"// Define endpoint URL hereconst endpointUrl = new URL("https://graph.facebook.com/v16.0/{{LIVE_VIDEO_ID}}/live_videos");const headerParameters = {contentType: "application/json",};// Setting API call optionsconst options = {method: "POST",headers: headerParameters,};// Define Query Parameters hereconst queryParameters = new URLSearchParams({access_token: '{{USER_ACCESS_TOKEN}}',end_live_video: true});// Function to make API callasync function endBroadcast() {try {endpointUrl.search = queryParameters;const response = await fetch(endpointUrl, options);// Printing responseprintResponse(response);} catch (error) {// Printing error messageprintError(error);}}// Calling function to make API callendBroadcast();
In the code widget above:
Line 5: We define the endpoint URL in the
endpointUrl
variable.Lines 18–21: We add the
access_token
and setend_live_video
totrue
in thequeryParameters
variable.Line 27: We use the
fetch
function to make the API call.
Response fields
The following are the response fields for the above endpoint.
Name | Type | Description |
| String | This is the ID of the live video. |
| String | This is the current status of the live video; it can be either |
| String | This is the title of the live video. |
| String | This is the URL of the live video's stream. |
| String | This is the secure URL of the live video's stream. |
| String | This is the URL of the live video on Facebook. |
| Boolean | This indicates whether the live video has been published or not. |
| DateTime | This is the time the live video was created. The time is in ISO 8601 format. |
| DateTime | This is the time the live video was updated. The time is in ISO 8601 format. |
| String | This is the HTML code to embed the live video on another website. |
| DateTime | This is the time when the live video was started. The time is in ISO 8601 format. |
| DateTime | This is the time when the live video was ended. The time is in ISO 8601 format. |
Note: Please note that the above fields aren't guaranteed to be returned in every request, and some fields may be added or removed in future versions of the API.
Delete a live video
To delete a live video on Facebook using the Graph API, we must make a DELETE
request to the video's endpoint. The base URL for the endpoint is:
https://graph.facebook.com/v16.0/{{live_video_id}}
Request parameters
The request parameters for the endpoint are given below.
Parameter | Type | Category | Description |
| String | Mandatory | This is the token that we received after app authentication and authorization. |
| String | Mandatory | This is the ID of the live video. Note that this is a path parameter. |
The code below uses the endpoint above to delete a live video. Click the “Run” button to see the response.
// Importing libraries hereimport fetch from "node-fetch"// Define endpoint URL hereconst endpointUrl = new URL("https://graph.facebook.com/v16.0/{{LIVE_VIDEO_ID}}");const headerParameters = {contentType: "application/json",};// Setting API call optionsconst options = {method: "DELETE",headers: headerParameters,};// Define Query Parameters hereconst queryParameters = new URLSearchParams({access_token: '{{USER_ACCESS_TOKEN}}',});// Function to make API callasync function deleteLiveVideo() {try {endpointUrl.search = queryParameters;const response = await fetch(endpointUrl, options);// Printing responseprintResponse(response);} catch (error) {// Printing error messageprintError(error);}}// Calling function to make API calldeleteLiveVideo();
In the code widget above:
Line 5: We define the endpoint URL in the
endpointUrl
variable.Line 13: We set the method to
DELETE
.Lines 18–20: We add the
access_token
in thequeryParameters
variable.Line 26: We use the
fetch
function to make the API call.
Response fields
The following are the response fields for the above endpoint.
Name | Type | Description |
| Boolean | This is the boolean value indicating whether the deletion was successful or not. |
| String | This is the ID of the deleted live video, if the deletion was successful. |
Note: Once a live video is deleted, it can't be recovered again.