JDownloader Community - Appwork GmbH
 

Reply
 
Thread Tools Display Modes
  #1  
Old 15.05.2018, 12:09
contertulio
Guest
 
Posts: n/a
Default Call removeLinks in API

I have a problem trying to call the function removeLinks through the API. I am currently using the MYJDAPI library (**External links are only visible to Support Staff****External links are only visible to Support Staff**) using PHP code.

In this library there is a function called callAction to make the call to the API. I use the following call:

Code:
$this->callAction("/downloadsV2/removeLinks",$links);
I have tried other possibilities, but I still do not succeed. Can you help me to call removeLinks option using PHP code?
Reply With Quote
  #2  
Old 15.05.2018, 13:58
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,524
Default

can you please share full code that we can use for testing? for example what is $links in your case?
__________________
JD-Dev & Server-Admin
Reply With Quote
  #3  
Old 16.05.2018, 07:59
contertulio
Guest
 
Posts: n/a
Default

Code:
$links="1526450046583";//UUID for delete
$this->callAction("/downloadsV2/removeLinks",$links);

function callAction( $action, $params = false) {
        if( !is_array( $this -> devices)) {
            $this -> enumerateDevices();
        }
        if( !is_array( $this -> devices) || ( count( $this -> devices) == 0)) {
            return false;
        }
        foreach( $this -> devices as $i => &$ivalue) {
            if( $this -> devices[$i]["name"] == $this->getDeviceName()) {
                $device_id = $this -> devices[$i]["id"];
            }
        }
        if( !isset( $device_id)) {
            return false;
        }
        $query = "/t_".urlencode( $this -> sessiontoken)."_".urlencode( $device_id).$action;
        if( $params != "") {
            if(is_array($params)) {
                $params = str_replace('"', '\"', substr(json_encode($params),1,-1));
            }
            $json_data = '{"url":"'.$action.'","params":["{'.$params.'}"],"rid":'.$this -> getUniqueRid().',"apiVer":'.$this -> apiVer.'}';
        } else {
            $json_data = '{"url":"'.$action.'","rid":'.$this -> getUniqueRid().',"apiVer":'.$this -> apiVer.'}';
        }
        $json_data = $this -> encrypt( $json_data, $this -> deviceEncryptionToken);
        $url = $this -> api_url.$query;
        $res = $this -> postQuery( $url, $json_data, $this -> deviceEncryptionToken);
        if( $res === false) {
            return false;
        }
        $content_json = json_decode( $res, true);
        if( $content_json["rid"] != $this -> rid_counter) {
            return false;
        }
        return $content_json;
    }
function postQuery( $url, $postfields = false, $iv_key = false) {
        $ch = curl_init();
        curl_setopt( $ch, CURLOPT_URL, $url);
        curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);
        if( $postfields) {
            $headers[] = "Content-Type: application/aesjson-jd; charset=utf-8";
            curl_setopt( $ch, CURLOPT_POST, true);
            curl_setopt( $ch, CURLOPT_POSTFIELDS, $postfields);
            curl_setopt( $ch, CURLOPT_HEADER, true);
            curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
        }
        $response = array();
        $response["text"] = curl_exec( $ch);
        $response["info"] = curl_getinfo( $ch);
        $response["code"] = $response["info"]["http_code"];
        if( $response["code"] != 200) {
            return false;
        }
        if( $postfields) {
            $response["body"] = substr( $response["text"], $response["info"]["header_size"]);
        } else {
            $response["body"] = $response["text"];
        }
        if( $iv_key) {
            $response["body"] = $this -> decrypt( $response["body"], $iv_key);
        }
        curl_close( $ch);
        return $response["body"];
    }

Last edited by contertulio; 16.05.2018 at 08:01.
Reply With Quote
  #4  
Old 16.05.2018, 08:54
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,524
Default

https://my.jdownloader.org/developers/#tag_147
check /downloadsV2/removeLinks
it expects two long arrays and not a single String
1 - linkIds (long[])
2 - packageIds (long[])
Call /downloadsV2/removeLinks?linkIds&packageIds

As far as I remember this client does not support parametes correct as it always merges the param into a single object
This part is wrong!
"params":["{'.$params.'}"] < it will put all params within a single object {}
This must be changed/fixed to use the original param object, for example like

callAction("/downloadsV2/removeLinks",[[1526450046583],[]]);
params is an array of objects, in this case an array of two long arrays

and then modify the callAction method to convert this object into json string
__________________
JD-Dev & Server-Admin
Reply With Quote
  #5  
Old 16.05.2018, 09:55
contertulio
Guest
 
Posts: n/a
Default

Perfect, that works like a charm!! Thank you
Reply With Quote
  #6  
Old 16.05.2018, 09:58
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,524
Default

did you modify the callAction method or what did you do to make it work? would be nice if you can share your fix/change for others
__________________
JD-Dev & Server-Admin
Reply With Quote
  #7  
Old 16.05.2018, 12:30
contertulio
Guest
 
Posts: n/a
Default

I modify:
PHP Code:
$params json_encode(array(array('"'.$links.'"'),array()));
$res $this -> callAction("/downloadsV2/removeLinks"$paramstrue); 
And I changed the callServer function removing red text:
$json_data = '{"url":"'.$action.'","params":["{'.$params.'}"],"rid":'.$this -> getUniqueRid().',"apiVer":'.$this -> apiVer.'}';
Reply With Quote
  #8  
Old 16.05.2018, 12:43
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 79,524
Default

Thanks for the feedback! Whenever you have questions about api or need help, please don't hesitate and contact us again
__________________
JD-Dev & Server-Admin
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT +2. The time now is 01:55.
Provided By AppWork GmbH | Privacy | Imprint
Parts of the Design are used from Kirsch designed by Andrew & Austin
Powered by vBulletin® Version 3.8.10 Beta 1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.