• Resolved herb morris

    (@48hmorris)


    I’m trying to use the /wp-json/filebird/public/v1/folder/set-attachment restapi endpoint to add an array of ids. The API documentation for the API:

    ids number The attachment ID, it could be a number or an array

    If I send a single id, the call works fine. If I send a json encoded javascript array, filebird returns success but no ids are added to folders.

    Do you have example javascript code that converts a javascript array to PHP array format expected by this call?

    If I send a json encoded javascript array and change the filebird code to use json.decode() the javascript json encoded array everything works fine.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Bruce

    (@ninjateamwp)

    Hi @48hmorris ,

    Thanks for coming today!
    Here is an example code using jQuery:

    var form = new FormData();
    form.append("folder", "17");
    form.append("ids[]", "30");
    form.append("ids[]", "26");
    
    var settings = {
      "url": "https://wpfree.test/wp-json/filebird/public/v1/folder/set-attachment",
      "method": "POST",
      "timeout": 0,
      "headers": {
        "Authorization": "Bearer YYfJnbtjSTvTEcQYxZn0pJMHQmnxSDyvLPLw7EtJ"
      },
      "processData": false,
      "mimeType": "multipart/form-data",
      "contentType": false,
      "data": form
    };
    
    $.ajax(settings).done(function (response) {
      console.log(response);
    });

    Here is an example using only JavaScript:

    var myHeaders = new Headers();
    myHeaders.append("Authorization", "Bearer YYfJnbtjSTvTEcQYxZn0pJMHQmnxSDyvLPLw7EtJ");
    
    var formdata = new FormData();
    formdata.append("folder", "17");
    formdata.append("ids[]", "30");
    formdata.append("ids[]", "26");
    
    var requestOptions = {
      method: 'POST',
      headers: myHeaders,
      body: formdata,
      redirect: 'follow'
    };
    
    fetch("https://wpfree.test/wp-json/filebird/public/v1/folder/set-attachment", requestOptions)
      .then(response => response.text())
      .then(result => console.log(result))
      .catch(error => console.log('error', error));

    Kind regards,
    -Bruce-

    Thread Starter herb morris

    (@48hmorris)

    Bruce,
    Thanks for the quick reply – the only JavaScript example works like a champ.

    Plugin Support Bruce

    (@ninjateamwp)

    Hi @48hmorris ,

    Good to know that and thanks so much and could you please motivate the developers team with a 5 star ratings, so they could do more prompt jobs in future 😉

    https://ww.wp.xz.cn/support/plugin/filebird/reviews/

    Kind regards,
    -Bruce-`

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘api question’ is closed to new replies.