Solved

IFS Workflow REST API Response Handling

  • 8 November 2023
  • 10 replies
  • 386 views

Badge +3

Hi,

I'm trying to implement a workflow in which I will be invoking multiple REST API calls to create a nested folder structure in SharePoint. To achieve this, I have used a GET API call to check whether the folder I'm attempting to create already exists in the path. However, using the Response and the Output variables did not yield the desired results in fetching the HTTP Status Code, as the workflow would not continue after the initial GET call.

Is this the correct approach to achieve the desired outcome, or is there an alternative way to implement this scenario?


 

 




 

icon

Best answer by Buddhi Gunasekara 10 November 2023, 06:16

View original

10 replies

Userlevel 3
Badge +5

Does the Response_ variables has any values? Also check the getCustLetterUrl variables content have any escape characters(As it is a url).

Badge +3

Hi Buddhi,

I verified the URL with the Postman and it works fine. As for the _Response variable I’m not able to check the value since it seems like the flow would not continue after the API call. I modified the variable as $._Response which I believe is the correct format but it seems like the issue right now is that after the API call everything comes to a halt.

Badge +3

@Buddhi Gunasekara I was able to modify the Workflow without using the REST Response, now it will work perfectly if the HTTP response is successful but I want the Workflow to continue and move on to the next step, even if I get an error response for the API call, it seems like using an output variable didn’t help because it would not continue to the gateway in case of a failure response to make use of the output variable. Do you have any suggestions on this?

Userlevel 3
Badge +5

You can identify what alternative response codes you want to handle and select them in “Add/Modify Response Codes”. Then workflow execution will move forward  for selected response codes in addition to standard “Ok” responses. Keep in mind that you get a values to _Response variable only when there is a deviation from standard ok responses. This behavior is important if you’re using “_Response” variable in a gateway. Make sure to check for existence of variable in the execution before using. 

Badge +3

@Buddhi Gunasekara Thank you! This worked for me.

Badge +4

@Buddhi Gunasekara I am having a similar issue that I’m hoping you may be able to help me with. I have two situations at the moment:

  1. Valid Request
    1. “response” output key is populated with the JSON response.
    2. “ResponseCode” response variable is empty/undefined.
  2. Invalid Request
    1. “response” output key is empty/undefined.
    2. “ResponseCode” response variable is “400”.

My issue is that I’d like the workflow to continue when there is an error code provided in the response, but I’d also like to access the response values so that I can display the error message to the user. Additionally, I’d like to have the ResponseCode when it is a successful request too so I can include different paths based on response type. Basically, I would like to have both values in both situations, as you would normally have in any web response. Is this possible?

 

Thanks in advance,

Dylan

 

 

Userlevel 3
Badge +5

@dritter Only the scenarios you described are implemented atm. If there’s an error code, rest call doesn’t assign the error message to a variable and for http status codes < 300, status code is not recorded into a variable. Please do a request to IFS if you feel this is a feature you like to see in future releases.

Badge +4

I will submit a request. I suppose in the meantime I will have to write the web requests in JavaScript so I can store both the response body and the response code into variables. Thank you for the help!

Userlevel 5
Badge +17

I will submit a request. I suppose in the meantime I will have to write the web requests in JavaScript so I can store both the response body and the response code into variables. Thank you for the help!

I would like to know how you write the web requests in JavaScript?  Would you mind sharing this if you get it to work?  I have the same need.  Thank you!

Also, if you made that request as an ‘Idea’ here in IFS Community, would you mind linking it in this thread so we can upvote it?  Again, thank you!

Badge +4

Hi @Mike The FSM TechnoGeek

 

I thought I’d be able to use fetch() or the XMLHttpRequest() object, but since the workflows run on the Nashorn engine, it doesn’t seem possible. We would have to edit the server-side Java to create an HTTP connection method, but I don’t think we have access to that.

 

I created an idea here. Please give it an upvote or a comment if you think it’s a good idea!


Thanks,

Dylan

Reply