title: Web API 2 REST Get() not receiving parameters: Angular
body: <p>I am having a problem with my REST Get() method. I am calling it with parameters from my AngularJS controller but the id parameter is not being populated correctly.</p>
  
  <p>Here is my Web API 2 controller:</p>
  
  <pre><code>public IEnumerable&lt;string&gt; Get(SearchParameters id)
  {
      // not important at the moment
      return null;
  }
  
  public struct SearchParameters
  {
      string selectedBroker;
      string brokerIsUnallocated;
      string brokerIncludeDeleted;
      string customerId;
      string businessType;
      string companyName;
      string town;
      string department;
      string contactName;
      string country;
      bool codeP;
      bool codeC;
      bool codeT;
      bool codeS;
      bool codeX;
      bool codeD;
  }
  </code></pre>
  
  <p>Here is my Angular call:</p>
  
  <pre><code>$scope.search = function() {
      $http.get("/api/customer", {
          selectedBroker: $scope.selectedBroker,
          brokerIsUnallocated: $scope.brokerIsUnallocated,
          brokerIncludeDeleted: $scope.brokerIncludeDeleted,
          customerId: $scope.customerCustomerId,
          businessType: $scope.customerBusinessType,
          companyName: $scope.customerCompanyName,
          town: $scope.customerTown,
          department: $scope.selectedDepartment,
          contactName: $scope.customerContactName,
          country: $scope.selectedCountry,
          codeP: $scope.codeP,
          codeC: $scope.codeC,
          codeT: $scope.codeT,
          codeS: $scope.codeS,
          codeX: $scope.codeX,
          codeD: $scope.codeD
      });
  }
  </code></pre>
  
  <p>Here is my routing config:</p>
  
  <pre><code>public static void Register(HttpConfiguration config)
  {
      // Web API configuration and services
      // Web API routes
      config.MapHttpAttributeRoutes();
  
      config.Routes.MapHttpRoute(
          name: "DefaultApi",
          routeTemplate: "api/{controller}/{id}",
          defaults: new { id = RouteParameter.Optional }
      );
  }
  </code></pre>
  
  <p>The problem is that the id parameter is not being populated - it has default empty strings and false booleans.</p>
  
  <p>Any ideas? I did think of trying <a href="http://victorblog.com/2012/12/20/make-angularjs-http-service-behave-like-jquery-ajax/" rel="nofollow">this</a> but I think JSON calls to my Web API controller are ok.</p>
  
  <p>Looking forward to your responses.</p>
  
  <p>M</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I have modified my call like this, but it still doesn't work:</p>
  
  <pre><code>$scope.search = function() {
      $http({
          url: '/api/customer',
          method: 'POST',
          params:
          {
              id: {
                  selectedBroker: $scope.selectedBroker,
                  brokerIsUnallocated: $scope.brokerIsUnallocated,
                  brokerIncludeDeleted: $scope.brokerIncludeDeleted,
                  customerId: $scope.customerCustomerId,
                  businessType: $scope.customerBusinessType,
                  companyName: $scope.customerCompanyName,
                  town: $scope.customerTown,
                  department: $scope.selectedDepartment,
                  contactName: $scope.customerContactName,
                  country: $scope.selectedCountry,
                  codeP: $scope.codeP,
                  codeC: $scope.codeC,
                  codeT: $scope.codeT,
                  codeS: $scope.codeS,
                  codeX: $scope.codeX,
                  codeD: $scope.codeD
              }
          }
      });
  };
  </code></pre>
  
  <p>** EDIT Fiddler showing some interesting results **</p>
  
  <p>I have modified my code like this:</p>
  
  <pre><code>$http({
      method: 'POST',
      url: '/api/customer',
      data: id,
      headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
  });
  </code></pre>
  
  <p>but Fiddler reports that only the CodeX values are being passed. Why?</p>