title: Alamofire syntax for ecobee request
body: <p>I'm trying to find the correct syntax for calling ecobee's API from Swift 4 using Alamofire.</p>
  
  <p>Their cURL example:</p>
  
  <pre><code>curl -H "Content-Type: text/json" -H "Authorization: Bearer ACCESS_TOKEN" 'https://api.ecobee.com/1/thermostat?format=json&amp;body=\{"selection":\{"selectionType":"registered","selectionMatch":"","includeRuntime":true\}\}'
  </code></pre>
  
  <p>The closest I've been to a solution is this</p>
  
  <pre><code>func doRequest() {
      guard let url = URL(string: "https://api.ecobee.com/1/thermostat?format=json") else { return }
  
      let parameters: Parameters = [
          "selection": [
              "selectionType": "registered",
              "selectionMatch": ""
          ]
      ]
  
      let headers: HTTPHeaders = [
          "Content-Type": "text/json",
          "Authorization": "Bearer \(core.accessToken)"
      ]
  
      let req = AF.request(url, method: .get, parameters: parameters, encoding: JSONEncoding.default, headers: headers)
          .responseJSON { response in
              print("Error:", response.error?.localizedDescription ?? "no error")
              print("Data:", String(data: response.data!, encoding: .utf8)!)
      }
  
      debugPrint(req)
  }
  </code></pre>
  
  <p>When I run this, the call ultimately fails with status code 408, a server timeout.</p>
  
  <p>When I change the HTTP method to use .post, the call completes, but the response is an internal status 3 with message "Update failed due to a communication error."</p>
  
  <p>Can anyone help me figure out what I'm doing wrong before I waste another day trying to hack my way through it?</p>