Announcement

Collapse
No announcement yet.

API PHP implementation DELETE call

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • API PHP implementation DELETE call

    Hi there,

    I am using the PHP implementation from the documentation and i am stumbling on the delete call. It does not work and i guess the problem is that the CURLOPT_CUSTOMREQUEST is never set to DELETE, if i am not having a payload, which i do not really need. Also worth mentioning is that it is behaving like it is a READ call since the default method is GET. So i guess my URL-building (and the rest) is correct, since it shows the correct dataset.

  • #2
    Okay the big question is: Am I doing something wrong? Or is it actually the case that I am right?

    Comment


    • #3
      Maybe I should mention that my problem is/was in the request function. My solution is to take the CURLOPT_CUSTOMREQUEST assignment out of the if-tree and put it above to the other curlopt assignments

      before:
      PHP Code:
      public function request($method$action, array $data null)
      {
        ...
        
      curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
        if (
      $this->userName) {
          
      curl_setopt($chCURLOPT_USERPWD$this->userName.':'.$this->password);
          
      curl_setopt($chCURLOPT_HTTPAUTHCURLAUTH_BASIC);
        }
        
      curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
        
      curl_setopt($chCURLOPT_FOLLOWLOCATIONtrue);
        
      curl_setopt($chCURLOPT_USERAGENT$this->userAgent);
        
      curl_setopt($chCURLOPT_HEADERtrue);

        if (isset(
      $data)) {
          if (
      $method == 'GET') {
            
      curl_setopt($chCURLOPT_URL$url'?' http_build_query($data));
          } else {
            
      $payload json_encode($data);
            
      curl_setopt($chCURLOPT_CUSTOMREQUEST$method); //line in question
            
      curl_setopt($chCURLOPT_POSTFIELDS$payload);
            
      curl_setopt($chCURLOPT_HTTPHEADER, array(
              
      'Content-Type: application/json',
              
      'Content-Length: ' strlen($payload))
            );
          }
        }
        ...
      }
      //getting read as result 

      after:
      PHP Code:
      public function request($method$action, array $data null)
      {
        ...
        
      curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
        if (
      $this->userName) {
          
      curl_setopt($chCURLOPT_USERPWD$this->userName.':'.$this->password);
          
      curl_setopt($chCURLOPT_HTTPAUTHCURLAUTH_BASIC);
        }
        
      curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
        
      curl_setopt($chCURLOPT_FOLLOWLOCATIONtrue);
        
      curl_setopt($chCURLOPT_USERAGENT$this->userAgent);
        
      curl_setopt($chCURLOPT_HEADERtrue);
        
      curl_setopt($chCURLOPT_CUSTOMREQUEST$method); //the line got moved here

        
      if (isset($data)) {
          if (
      $method == 'GET') {
            
      curl_setopt($chCURLOPT_URL$url'?' http_build_query($data));
          } else {
            
      $payload json_encode($data);
            
      curl_setopt($chCURLOPT_POSTFIELDS$payload);
            
      curl_setopt($chCURLOPT_HTTPHEADER, array(
              
      'Content-Type: application/json',
              
      'Content-Length: ' strlen($payload))
            );
          }
        }
        ...
      }
      //doing what its supposed to do 

      But my initial questions still need answers, since this is only my workaround. Also if I was actually right, the documentation for the api php implementation has to be updated (not necessarily with my solution but with what you think is best).

      Comment


      • #4
        Hi,

        Your fix seems to be fine. We will fix the doc. Thanks.

        Comment

        Working...
        X