REST Post API to SAP returns Status 0

Hi everyone,

I am getting an error whenever I am using the activity “HTTP Request” to connect to SAP. I have already tried what it is written in this link, unfortunately it is not working.

https://forum.uipath.com/t/api-post-request-giving-0-as-status-code/149970/8

I have also tried to create a Library but it didn’t work either
https://forum.uipath.com/t/http-request-activity-returns-status-code-0-and-empty-response-but-works-in-soapui/111930/8

This is a simple authorization with user and password. I have tried the process in SOAPUI and it works correctly. First, I call a GET (in the header I have argument “X-CSRF-Token” with “Fetch”) and I get back the token (x-csrf-token) and the cookie.

Then, I call POST ( “X-CSRF-Token” with the info retrieved in GET, and “cookie” with the value retrieved in get “SAP_SESSIONID…” ) and I see that there was a connection with SAP.

With UIPath I do the following steps:

1.- Create a HTTP Request for GET.

Header: x-csrf-token = “Fetch”

I get in the header the x-csrf-token and the cookie that I will use in the Post

2.- Create a HTTP Request for POST

Header:

x-csrf-token =

cookie = <cookie received from GET, only the substring starting with SAP_SESSIONID…>

As I described, this combination works in SOAPUI. Unfortunately in UIPATH it doesn’t work.

The GET is working correctly returning the token and the cookie.

The POST get a Status 0. It seems that there is no connection with the system at all, I cannot see the request in SAP.

If I only pass the token, without the cookie, then I get a Status 403. There is connection to SAP, I can see the request in SAP. Since the cookie is not provided then I get the error.

Did anyone able to solve this problem?

Any info will be more than welcome.

Thanks very much.

There is no status like 0 from any server, it may be because the client aborts or failed to send back the response. I hope the request may have some issues which server won’t able to process. Can you check the same request in postman and let us know if it is working fine there @Alejandro_Montero.

Hi HareeshMR,

thanks for your reply.
Unfortunately it works with Postman as well as with SoapUI.
If the cookie is not set I get a 403 status error. If in UIPath I set the received cookie in the header then I don’t get any response.

Best regards,
Alejandro

You need to set the cookie to let the request know that you are authenticated. so you must pass it. When you mean, you are not getting any response, what is the status of the request? Please run the workflow and check instead of preview response

Hi Hareesh,

in the POST request header I am passing:

  • x-csrf-token with the token received from the GET request
  • cookie with the cookie received from GET (I am only take the part starting with SAP_SESSION…)

I have tried it manually in SOAPUI and in POSTMAN and it works fine. First, I request the Token and the cookie with GET. Then I fill the token and the cookie in the POST Header.

Unfortunately UIPath returns Status 0.

In SAP I can see the GET request and the POST request from SOAPUI and from POSTMAN. In the case of UIPath I only see the GET request. This is what you say in your previous message (it is not able to authenticate).

In UIPath there are only three returning parameters (Output) for the HTTP Request activity. In Header, I don’t get any result and in StatusCode I receive 0. How can I see the response preview?

Thanks again for your help.

BR
Alejandro

The result will be the response from the server if you are going to get anything from server and status will be the response code by the server. Are you getting anything in the result?

I don’t get anything in the response.
Result and Headers are empty and in Status Code I get 0.

The REST service works with SOAPUI and Postman, this is the reason I don’t understand why with UIPath is not working. It might be a argument that needs to be added somewhere in the request.

As I said, I am passing the Token and the cookie in the header, same as in the other tools. Unfortunately with different results

Can you post the screenshots of how you are trying to send the request in UiPath? Same screenshot of postman is also helpful :slight_smile:

Following are the Postman Screenshots

GET Request Postman

POST Request Postman

And the following are the UIPath Screenshots
Workflow Process

GET Request UIPath

POST Request UIPath

Hi,

has anyone solve that problem?

Regards,
Alejandro

Hi Alejandro,

Were you able to solve this problem? I’m having the exact same issue with a 403 response and have tried all different combinations of sending cookies, headers, etc.

Works fine in postman but can’t get it to work in UiPath.

Hi,
unfortunately I was not able to solve the problem. It seems that the cookies info are not beeing correctly passed.
In the meantime I found a workaround. There is the possibility to work with BAPIs (SAP Remote Function Modules), so I just used them. Anyway if somebody is able to solve the problem I would be interested for a future solution.

Regards
Alejandro

This is the link to the BAPI explanation BAPI Functionality in UI Path - #29 by balkishan

@StefanSchnell any inputs / thoughts from your side here? Thanks, Lev

1 Like

Has this got a solution yet? I have a similar issue

Sorry guys,

I just stopped with that development. It was only for demo purposes. Unfortunately I didn’t have the time to continue researching.

As I wrote I was having some problems with the cookies, somehow it was working for me from Postman and SoapUI but not from UIPath.
SOAP Webservices weren’t working either, the WSDL was also working in SOAPUI but in UIPath was not generating the right parameters.

Finally I found the possibility to connect using the BAPI activity. This was working correctly and it was very easy to configure.
You can just follow the instructions describe in the link to use the activities: https://docs.uipath.com/activities/docs/about-the-sap-bapi-activities-pack#section-installation-prerequisites

Anyway, if you fing a solution for that error I would be interested to now how you solved it.

Regards,
Alejandro

Hi guys,

So I was having the same problem last week, it gave return status 0 and I solved mine.
I made the timeout time longer and it worked.
I don’t know if this would solve yours but worth the try.

Regards,
Thery Tendyan

1 Like

@LevKushnir @Alejandro_Montero

Hello Lev and Alejandro,
I am no expert in http requests, but it seems that the header field name cookie is reserved.

I tried this ABAP class:

"-Begin-----------------------------------------------------------------

CLASS z_post DEFINITION
  PUBLIC
  CREATE PUBLIC .
  PUBLIC SECTION.
    interfaces IF_HTTP_EXTENSION .
  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.

CLASS z_post IMPLEMENTATION.

  METHOD if_http_extension~handle_request."-----------------------------

    DATA:
      lv_verb        TYPE string,
      lv_csrf_token  TYPE string,
      lv_keks        TYPE string,
      lv_cookie      TYPE string,
      lv_return      Type string.

    lv_verb = server->request->get_header_field( name = '~request_method' ).
    CASE lv_verb.
      WHEN 'GET'.
        server->response->set_cdata( data = 'GET Request' ).
        lv_csrf_token = server->request->get_header_field( 'x-csrf-token' ).
        IF lv_csrf_token = 'fetch'.
          server->response->set_header_field( name = 'x-csrf-token' value = 'KbyUmhTLMpYj7CD2di7JKP1P3qmLlkPt').
        ENDIF.
        server->response->set_status( code = 200 reason = 'Ok' ).
      WHEN 'POST'.
        lv_return = 'POST Request' && cl_abap_char_utilities=>cr_lf.
        lv_csrf_token = server->request->get_header_field( 'x-csrf-token' ).
        lv_return = lv_return && lv_csrf_token && cl_abap_char_utilities=>cr_lf.
        lv_keks = `keks = ` && server->request->get_header_field( 'keks' ).
        lv_return = lv_return && lv_keks && cl_abap_char_utilities=>cr_lf.
        lv_cookie = `cookie = ` && server->request->get_header_field( 'cookie' ).
        lv_return = lv_return && lv_cookie && cl_abap_char_utilities=>cr_lf.
        server->response->set_cdata( data = lv_return ).
        server->response->set_status( code = 200 reason = 'Ok' ).
    ENDCASE.

  ENDMETHOD.

ENDCLASS.

"-End-------------------------------------------------------------------

And here the result in Postman:

The header field keks (German for cookie) works perfect, but cookie doesn’t works. Please try another header field name and let us know your results.

Best regards
Stefan

1 Like

Hi, may I check how long the timeout time you extended to?

hi,
I just randomly put a bigger timeout to see if its working.
I set it to 500.000 and still haven’t lower it…