Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue with HTTP Request with Patch method in Angular JS

Following is my code:

  $http({
      url: 'https://apistage.dealsignal.com/api/v0/company_watchlists/' + wishlist_id,
      method: 'PATCH',
      params: {
          list: {
              add_company_ids: ['61737'],
              name: 'My Wishlist'
          },
          api_key: 'CtxY3Kpc7ZDL8VDfLmPt9wss'
      }
  })
      .success(function(response) {
          console.log(response);
      }).
  error(function(response) {
      console.log(response);
      return false;
  });

I am getting bad request error but same request with patch method is working in REST CLIENT on chrome.

like image 412
Seema Sharma Avatar asked Sep 15 '15 10:09

Seema Sharma


2 Answers

Please see the Angular Doc. This will be Data not params.

$http({
  url: 'https://apistage.dealsignal.com/api/v0/company_watchlists/' + wishlist_id,
  method: 'PATCH',
  data: {
      list: {
          add_company_ids: ['61737'],
          name: 'My Wishlist'
      },
      api_key: 'CtxY3Kpc7ZDL8VDfLmPt9wss'
  }
}).success(function(response) {
      console.log(response);
  }).
  error(function(response) {
  console.log(response);
  return false;
});
like image 94
Bik Avatar answered Sep 20 '22 06:09

Bik


I am not sure about it, but may be the problem is that the parameter "params" should be named "data", as when you make a POST request.

Hope it helps.

like image 25
Ismael Fuentes Avatar answered Sep 19 '22 06:09

Ismael Fuentes