About EasyMorph Tutorials & Examples Web-help

Debugging Web Request

I am getting the following error on a REST/Odata POST message. The connection “TESTs” ok.

Error: Server returns non successful status code: 400 (Bad Request)
Source: action “Iterate Web request”, table “TGIN-IMU.csv”

I would love to provide more info, but I am not seeing the outgoing HTTP packet., nor the response (I.e. I don’t see how to get this info from EasyMorph). I am going to try to see if I can see it with Fiddler.

I provide a screen shot of the Iterative Web request. (I do know that it is supposed to be a JSON body, with each of these columns).

I can also tell you that is is really painful to put in 7+ fields by selecting column for both the Name and Value. Should there not be a way to say that the incoming table is the body of the POST request in JSON format? (I already removed all extraneous columns).

Ok,Fiddler shows some of the issues. Gotta change this to a JSON body, not a webForm.

POST https://pwsepicorapp.draper.com/ERP10.2Test/api/v1/Ice.BO.UD18Svc/UD18s HTTP/1.1
Access-Control-Allow-Origin: *
x-api-key: 0HXJZgldKZjKIXNgIycD4c4DPqSrzn2UFCPHbiR1aY7IW
Authorization: Basic <removed for the post to this forum>
Content-Type: application/x-www-form-urlencoded
Host: pwsepicorapp.draper.com
Content-Length: 83
Expect: 100-continue
Accept-Encoding: gzip, deflate
Connection: Keep-Alive

TRI=TRI&+1001=+1001&+1001=+1001&+1001=+1001&+1001=+1001&+1001=+1001&+1001=+1001&A=A

Yes, the Form mode uses x-www-form-urlencoded for data encoding. You probably need to construct a JSON in a new column using text concatenation, then use the column as the request body.

I guess you are saying Fiddler is the debug method of choice.

Also, I saw your JSON module, but it does not directly fit the problem here either, I could mod it,
But my solution looks like something non-programmers would not want to do either:

‘{’ &
" Company: " & “’” & [Company] & "’, " &
" Key1: " & “’” & [Key1] & "’, " &
" Key2: " & “’” & [Key2] & "’, " &
" Key3: " & “’” & [Key3] & "’, " &
" Key4: " & “’” & [Key4] & "’, " &
" Key5: " & “’” & [Key5] & "’, " &
" RowMod: " & “’” & [RowMod] & "’, " &
" SerialLot_c: " & “’” & [SerialLot_c] & "’ " &
‘}’

Looks like a simple transform function could be added to the set of things you have already.
Something like RowAsJSON()

We will be adding an action for constructing JSONs in version 4.1. It will work as follows: convert a row into a JSON. If a row value is already a JSON, make it a nested JSON.

Meanwhile, you can use the Table2json module from this example: https://community.easymorph.com/t/example-constructing-json/1279. It basically performs the same construction described above.

Thank you very much for the quick and timely replies. It looks like you guys are on a good path.

BTW: I have been using the SAFE FME (https://www.safe.com/) from vancouver for years for GeoSpatial ETL (and championed it’s use in a lot of projects at our company and in the Air Force). I mention it because they grew from a small company to a pretty large privately owned company and they might have some good lessons for you. (as well as a very friendly ETL tool for Geospatial, which might complement your work).

Thanks for your feedback.
Actually, there is a way how to investigate the request body and headers, as well as server response. You should activate “Return response as the action result” and “Add columns with request headers, body” on Response Tab of WebRequest action.

Any ideas on how we might extract certain fields from the Response - items such as VIEWSTATE ID’s, EVENTSTATE ID’s, or Cookie information for later form posting?

I’m looking at iterating some web requests by building up a POST form and changing certain form fields (i.e date ranges) and downloading/parsing the results.

I’ve got most of the data to build the payload from fiddler, but I think I need to perform a GET on the page first, and then try to inject the authorisation tokens (i.e Viewstate) into the request body prior to the POST.

@jaws2k thanks for your question.
If I undertood you correctly, you’re trying to interact with a classic ASP.NET application.

Parsing and posting
First of all, setup IterateWebRequest action and enable “Return response as the action result” (Response tab) . Thats will create a new column named Response-Body.

A sample response:

<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value=""     />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="MEWFNTAm/8bEuMZaLk3LhgHJ1stgbqFmmw8lqghrR6eJgEpvBUvP00+F0Mlox2Lj2UUDtRoTFA9Zbk4OdmOcTjL+sW/9BxnGJh9dXhWqwH8=" />

Next, caclulate a new column named __VIEWSTATE:

keepbefore(keepafter(keepbefore(keepafter([Response-Body],'id="__VIEWSTATE"'),'/>'),'"'),'"')

To send VIEWSTATE back, create another IterateWebRequest action. Set Request method to POST. Configure action Body to Form and add new values. Set __VIEWSTATE as name and bind it to __VIEWSTATE column calculated on a previour step.
Add other required fields.

Pay attention that large viewstate could be chunked into multiple hidden fields by your server.

Cookies.
Transfering cookies from server to client carried out by header Set-Cookie. Respectively, a new column Set-Cookie will be added to the table.

cookie_name=value; path=/

All cookies that were set by the server are automatically sent back from the client on each request. For that purposes a special CookieContainer is used. But CookieContainer will be recreated after each call of Run/RunAction/ReloadNRun, so you should start all actions (Reload and run) together and not one-by-one, otherwise container will be empty. For now, there is no way to set a custom cookie defined by user (even by using header ‘Cookie’).

Many thanks @ckononenko - using these steps I was able to successfully get the values. This has many potential applications…

Thanks again!

***** moved from #lounge to #uncategorized

Hi,
I’m trying to connect to one of our service providers web service - Initially I need to get a token, which I use for the next hour trying to look up statuses on our orders.
However, I’m not able to get an expected response. As I’m quite new in these web requests, I’m not sure what goes wrong and where…

In the example below, I add a username in the header containing a backslash (\) - In the preview, this is shown as a double backslash (\\).
When Sending the request, I don’t get the response I’m looking for…
Trying to send a request through Postman using the same values, I get the response I need - in Postman, the username and single backslash (\) is shown as expected … Is this the cause of the error? - If so, how do I force EM to only contain a single backslash?

EasyMorph shows the second backslash correctly - a backslash must be escaped with another backslash according to the HTTP specification.

The problem is with the body type in your request. You specified “Body is JSON”, and therefore EasyMorph sends the body as JSON even despite you tried to overwrite the Content-Type header explicitly to application/x-www-formuriencoded which indicates a web-form.

Content-Type application/x-www-formuriencoded in Postman indicates that the request body is not a JSON, but instead a web-form. Also, if you look closely at the request body in Postman you will see that it’s not a JSON (no brackets).

Therefore you need to change body type from JSON to Form. In this case EasyMorph will add Content-Type application/x-www-formuriencoded automatically. No need to explicitly state Content-Type in the Headers tab.

1 Like

That works!

Thank you - Still new and learning on the go :slight_smile:

So do we :slight_smile:


The topic is now closed. Please open new topics for cases related to Web Request in EasyMorph.

To learn more about EasyMorph visit easymorph.com.