Search code examples
ajaxapicoldfusionvimeovimeo-api

How i can send delete request for to delete video in AJAX, its returning 204 status


I'm trying to delete my vimeo video by using AJAX request but its always returning 204 status code, and video is not deleting from account. Here is code example.

$(".js-delete").click(function(){
    var videoID = $(this).data("target");// /videos/2332
    $.ajax({
         type: "post",
         url: "https://api.vimeo.com/me/videos",
         headers: {
           "Authorization": "bearer xxxxxxxxxxxxxxx"
         },
         data: {
            url: "https://api.vimeo.com/me"+videoID,
            method: "DELETE"
         },
         dataType: "json"
         success: function(response){
            console.log(response); //will print the whole JSON
        },
        error: function(){
            console.log('Request Failed.');
        }
    });
});

Can anyone please suggest some changes required for this?

Thanks in advance


Solution

  • You are sending

    • a HTTP POST
    • to the URL https://api.vimeo.com/me/videos
    • with the Bearer token as a header
      • Note that it should be Bearer <token> (uppercase B), not bearer <token>.
    • with a data packet that contains another URL and HTTP method.

    But according to the Vimeo API docs to Delete a Video, the request should be

    DELETE https://api.vimeo.com/videos/{video_id}
    

    with a note:

    This method requires a token with the "delete" scope.

    A jQuery ajax request should look something like this if the bearer token is correct:

    $(".js-delete").click(function(){
        var videoID = $(this).data("target");// /videos/2332
        $.ajax({
            type: 'DELETE',
            url: 'https://api.vimeo.com/videos/' + videoID,
            headers: {
            "Authorization": "Bearer xxxxxxxxxxxxxxx"
            },
            success: function(response){
                console.log(response); //will print the whole JSON
            },
            error: function(){
                console.log('Request Failed.');
            }
        });
    });
    

    You should be able to test this request using https://www.getpostman.com/ to verify the request and bearer token works outside of your CF app.