I am fairly new to this, but it appears that the API I am using requires adding a body to a GET request. Here is their curl example:
curl -u '{userEmail}:{userApiToken}' -v -X GET -H 'Content-Type: application/xml' -o 'result.xml' -d '<request><layout>1</layout><searchmode>Cany</searchmode><searchvalue>aaron</searchvalue><filtermode></filtermode><filtervalue></filtervalue><special></special><limit>100</limit><start></start><sortfield></sortfield><sortdir></sortdir></request>' https://secure.solve360.com/contacts
I am trying (and failing) to recreate this using Dispatch:
val myHost = host("secure.solve360.com").secure
val myRequest = myHost / "contacts"
val data="<request><layout>1</layout><searchmode>Cany</searchmode><searchvalue>aaron</searchvalue><filtermode></filtermode><filtervalue></filtervalue><special></special><limit>3</limit><start></start><sortfield></sortfield><sortdir></sortdir></request>"
val secReq = myRequest.as_!("username", "API_key")
.setHeader("Content-Type", "application/xml")
.setBody(data)
val result = Http(secReq OK as.xml.Elem).either
result() match {
case Right(content) => println("Content: " + content)
case Left(StatusCode(401)) => println("Invalid credentials")
case Left(StatusCode(404)) => println("Not found")
case Left(StatusCode(code)) => println("Some other code: " + code.toString)
}
Http.shutdown
The "content" I get back is the same irrespective of whether I comment out the ".setBody(data)" line.
I expect to get back XML representations of at most 3 "contacts" with the name "Aaron". Instead I get back the first 100 contacts irrespective of name.
I realise that giving a body meaning in a GET request breaks HTTP/1.1 but this is an API I am forced to use. Am I doing something wrong or does Dispatch simply strip out the body in a GET request?
The content of this email (and any attachment) is confidential. It may also be legally privileged or otherwise protected from disclosure.
This email should not be used by anyone who is not an original intended recipient, nor may it be copied or disclosed to anyone who is not an original intended recipient.
If you have received this email by mistake please notify us by emailing the sender, and then delete the email and any copies from your system.
All views and opinions expressed in this electronic message and its attachments are those of the sender and do not necessarily reflect the views and opinions of SAM Learning Ltd.
SAM Learning Ltd Registered in England No 2826785 Registered Office Webber House, 26-28 Market Street, Altrincham, Cheshire WA14 1PF