GET with setBody possible?

33 views
Skip to first unread message

Iain Argent

unread,
Apr 27, 2014, 3:51:15 AM4/27/14
to dispatc...@googlegroups.com
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 -'{userEmail}:{userApiToken}' --X GET -'Content-Type: application/xml' -'result.xml' -'<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

Nathan Hamblen

unread,
Apr 27, 2014, 10:33:01 AM4/27/14
to dispatc...@googlegroups.com
On 04/27/2014 03:51 AM, Iain Argent wrote:
> 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:

GET requests don't normally have a body. Are you sure it's not looking
for a PUT or POST?

Nathan

Iain Argent

unread,
Apr 27, 2014, 11:06:52 AM4/27/14
to dispatc...@googlegroups.com


On Sunday, April 27, 2014 3:33:01 PM UTC+1, n8han wrote:

GET requests don't normally have a body. Are you sure it's not looking
for a PUT or POST?

Nathan

I was surprised, too! I copied the curl example from the section "List" on this page:

http://norada.com/crm-software/external_api_reference_contacts

The curl example they give uses "-X GET" with "-d ...". As far as I can tell this makes curl do a GET with a body, but I might be confused!

How does Dispatch behave if you try to make it do the same thing?
Reply all
Reply to author
Forward
0 new messages