REST POST using Json

2
I am using the Rest Services module from the appstore to create a connection with another application. I want to create a person in the other application, by posting a request. The Rest Services module turns my post request's body into some sort of HTML parameterized code. This isn't compatible with the receiving end, because it needs to be json. This is an example of what the Rest Services module puts in the body: Email=test%40test.nl&Insertion=Dhr&Address=Teststraat+12&Initials=P.&Mobile=0612345678&FirstName=Pietje&FacebookAccount=facebookaccount&TravelMaximum=100&LastName=Puk&Zipcode=1234AB&BirthDate=1980-10-10&City=Den+Bosch&Sex=m It needs to look like this: {"sex":"m","initials":"C. M.","firstname":"Piet","insertion":"van","lastname":"Beek","address":"xxx","zipcode":"xxx","city":"Amsterdam","phone":"","mobile":"xxx","email":"xxx@gmail.com","birthdate":"23-01-1923","birthplace":"Den Haag","nationality":"NL","establishmentId":"37"} How can I achieve this? Is it possible to edit the Java code and encode the body to json in some way? EDIT 9-11-2015 16:19: In response to Anthony: That's a great idea! I have added the header, and it comes up with a different error message: Uncaught exception 'Exception' with message 'Content-type could not be produced: 'application/json, application/json', Use: 'application/json|application/xml' instead' It seems as though there already is a header attached with the value 'application/json'. I have changed the value to 'application/json|application/xml', but this still generates the above error message. Any ideas?
asked
2 answers
1

The shared microflow contains an action addHeaderToNextRequest with params accept|application/json. Try to change this to Content-type|application/json

answered
1

Hi,

Did you try to use the 'request' java action and set the method to POST? I think that is the preferred way to do this. This action is included in the 1.5.0 version of the REST Services module. You can find this Java action in

RestServices -> CONSUME -> request

  • Method: POST
  • URL: the endpoint your resource is located
  • optRequestData: pass your request object here.
  • optResponseData: can be empty
  • sendWithFormEncoding: false
answered