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

access_token

String

Mandatory

This is the token that we received after app authentication and authorization.

live_video_id

String

Mandatory

This is the ID of the live video. Note that this is a path parameter.

end_live_video

Boolean

Mandatory

This is the boolean value that must be set to true to end the live video.

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.

Press + to interact
// Importing libraries here
import fetch from "node-fetch"
// Define endpoint URL here
const endpointUrl = new URL("https://graph.facebook.com/v16.0/{{LIVE_VIDEO_ID}}/live_videos");
const headerParameters = {
contentType: "application/json",
};
// Setting API call options
const options = {
method: "POST",
headers: headerParameters,
};
// Define Query Parameters here
const queryParameters = new URLSearchParams({
access_token: '{{USER_ACCESS_TOKEN}}',
end_live_video: true
});
// Function to make API call
async function endBroadcast() {
try {
endpointUrl.search = queryParameters;
const response = await fetch(endpointUrl, options);
// Printing response
printResponse(response);
} catch (error) {
// Printing error message
printError(error);
}
}
// Calling function to make API call
endBroadcast();

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 set end_live_video to true in the queryParameters 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

id

String

This is the ID of the live video.

status

String

This is the current status of the live video; it can be either LIVE_NOW, SCHEDULED_UNPUBLISHED, or SCHEDULED_PUBLISHED.

title

String

This is the title of the live video.

stream_url

String

This is the URL of the live video's stream.

secure_stream_url

String

This is the secure URL of the live video's stream.

permalink_url

String

This is the URL of the live video on Facebook.

published

Boolean

This indicates whether the live video has been published or not.

created_time

DateTime

This is the time the live video was created. The time is in ISO 8601 format.

updated_time

DateTime

This is the time the live video was updated. The time is in ISO 8601 format.

embed_html

String

This is the HTML code to embed the live video on another website.

start_time

DateTime

This is the time when the live video was started. The time is in ISO 8601 format.

end_time

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

access_token

String

Mandatory

This is the token that we received after app authentication and authorization.

live_video_id

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.

Press + to interact
// Importing libraries here
import fetch from "node-fetch"
// Define endpoint URL here
const endpointUrl = new URL("https://graph.facebook.com/v16.0/{{LIVE_VIDEO_ID}}");
const headerParameters = {
contentType: "application/json",
};
// Setting API call options
const options = {
method: "DELETE",
headers: headerParameters,
};
// Define Query Parameters here
const queryParameters = new URLSearchParams({
access_token: '{{USER_ACCESS_TOKEN}}',
});
// Function to make API call
async function deleteLiveVideo() {
try {
endpointUrl.search = queryParameters;
const response = await fetch(endpointUrl, options);
// Printing response
printResponse(response);
} catch (error) {
// Printing error message
printError(error);
}
}
// Calling function to make API call
deleteLiveVideo();

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 the queryParameters 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

success

Boolean

This is the boolean value indicating whether the deletion was successful or not.

id

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.