Retrieve response from REST API | Community
Skip to main content
Level 3
Aug 7, 2017 6:55 PM UTC
Solved

Retrieve response from REST API

When using an adaptive form, is it possible to retrieve the response from the rest service I'm invoking?  My adaptive form is invoking a sling servlet which then invoked my 3rd party rest api.  The rest api is returning a payload but I'm unable to access the payload when looking at the guideResultObject that is returned.  Any pointers would be helpful.

Thanks!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
smacdonald2008
smacdonald2008Accepted solution
Level 10
Aug 10, 2017 1:44 PM UTC

So in the object that is returned - you are not seeing the data correct?

"It doesn't have the response in the data property"

Looks like a bug - i recommend opening a bug and report this. ANother apprach you can take is to write the form as an HTL component and then use WCMUsePojo and call the service. Then you can update your form fields with the returned data set.

18 replies

Level 3
Aug 11, 2017 11:03 AM UTC

That's correct.  I'll open a Daycare ticket.  Unfortunately for this effort, we need to use Adobe Forms (assuming it works as expected).

Translate
smacdonald2008
smacdonald2008Accepted solution
Level 10
Aug 10, 2017 1:44 PM UTC

So in the object that is returned - you are not seeing the data correct?

"It doesn't have the response in the data property"

Looks like a bug - i recommend opening a bug and report this. ANother apprach you can take is to write the form as an HTL component and then use WCMUsePojo and call the service. Then you can update your form fields with the returned data set.

Translate
Level 3
Aug 10, 2017 2:55 AM UTC

lesutton1,

Any further thoughts? 

Translate
Level 3
Aug 8, 2017 7:22 PM UTC

You could see below the guideResultObject being returned.  It doesn't have the response in the data property.

Translate
Employee
Aug 8, 2017 5:34 PM UTC

Can you debug further and take a look at what the object is that is in your data? Sounds like instead of straight XML you're getting an object with more than one message in it.

Translate
Level 3
Aug 8, 2017 5:27 PM UTC

Correct, when I add this console.log: console.log('guideResultObject.data: ' + guideResultObject.data);, the following prints in Chrome's console:

guideResultObject.data: [object Object]

Translate
Level 3
Aug 8, 2017 5:19 PM UTC

Yes.  The adaptive form is invoking a Sling Servlet, which is then calling my 3rd party service.  I'm looking to surface the response of the 3rd party service in my window.guideBridge.submit success callback function.

Translate
Employee
Aug 8, 2017 5:19 PM UTC

Assuming the .data property of the guideResultObject is empty?

Translate
Level 3
Aug 8, 2017 5:17 PM UTC

My REST service is returning JSON.  Here is the response I'm logging in my Sling Servlet.  I want to be able to acccess the leadId in the success callback handler.

{"status":"OK","encoding":null,"data":{"leadId":"3dc2eb71-d40a-4bdd-a16d-510636098b1d"},"apiErrorList":null}

Translate
Employee
Aug 8, 2017 5:16 PM UTC

it should contain any error messages but is your rest call taking place server side? i.e.: you're populating the response object and looking for those results in your form?

Translate