Seema Sharma
Seema Sharma

Reputation: 89

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.

Upvotes: 8

Views: 2445

Answers (2)

Bik
Bik

Reputation: 553

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;
});

Upvotes: 7

Ismael Fuentes
Ismael Fuentes

Reputation: 250

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.

Upvotes: 2

Related Questions