REST API with XML input example

Hi there,

Please provide an example of how to create a REST API which accepts XML input. The API call is external and limits the input format to XML. I’m not sure how to build the body of the request and receiving ERROR 415: Backend Unsupported Media Type

Which as I understand, means the content type and input do not match. Any assistance will be appreciated thanks! Attached an image of the request body

1 Like

Hi @mBots_2020
What method are you using to send REST API request. ?

1 Like

Hi,
I’m using the UiPath HTTP request activity

1 Like

Hey @mBots_2020

Sorry for delayed response.
Make sure your content type is XMl , It would be great if you can share you XML.

1 Like

@mBots_2020

Have you tried using the same request in Postman or SOAPUi ?

@mBots_2020

Please use below XML and see if it works.

"<?xml version="'1.0'"?>
<authorized-return xmlns="'http://www.canadapost.ca/ws/authreturn-v2'">
<create-public-key>true</create-public-key>
<service-code>DOM.XP</service-code>
<returner><name>DFDFDFDFD</name>
<company>FDFDFDFDFDFDFDF</company>
<domestic-address><address-line-1>DFDFDFDFDF</address-line-1>
<address-line-2>DFDFDFDF</address-line-2>
<city>DFDFDFDFDFDFD</city>
<province>ON</province>
<postal-code>K0A1W0</postal-code>
</domestic-address>
</returner>
<receiver>
<name>DFDFDFDFD</name>
<company>FDFDFDFDFDFDFDF</company>
<domestic-address><address-line-1>DFDFDFDFDF</address-line-1>
<address-line-2>DFDFDFDF</address-line-2>
<city>DFDFDFDFDFDFD</city>
<province>ON</province>
<postal-code>K0A1W0</postal-code>
</domestic-address></receiver>
<print-preferences><output-format>8.5x11</output-format>
<encoding>PDF</encoding>
<show-packing-instructions>true</show-packing-instructions>
</print-preferences><settlement-info><paid-by-customer>2004381</paid-by-customer>
<contract-id>42708517</contract-id>
</settlement-info>
</authorized-return>"

@Lakshay_Verma , do you know what is the exact end point URL?

Have you ever tried in Postman ? I just want to be sure that it is working properly in Postman or SoapUI first.

I tried XML validations, seems it seems ok to me.
Yes i have exact URl but response is 500.

@Lakshay_Verma

If 500 status code returned in response from Postman , I guess there is some problem with the Server responding correctly. Even Uipath will return same 500 error code.

Can you please share the URL ?

If did try with the URL

https://ct.soa-gw.canadapost.ca/rs/{mailed by customer}/{mobo}/authorizedreturn”

I would like to know exact parameter values for mailed by customer and mobo

Hi @mzahid
Please check this link

Check Headers collection

Thank you @Lakshay_Verma I found them

I think there is something wrong here as both the parameters have exactly the same value.

If the service is provided with correct/right parameters then I think your solution will work the best.

Your solution

@mBots_2020

Please use below XML and see if it works.

Hi there,

Confirming both of these URL segments should be the same value. This URL works from Postman and Insomnia.

Please see screenshot - the XML does not work as there is no escape character for the quotation mark i.e. ". I previously used double “”
XML string

@loginerror @GBK

Could you please help us here? Postman works fine but Uipath is unable to get back a successful response

URL details are mentioned in below link

Hi @mBots_2020

Could you try loading the XML file from a text file, like this one:
input.txt (1.1 KB)

I tried your workflow with this small modification and I got a different error:

Maybe it gives you a hint.

I think this error has to do with the additional ’ - according to google this “malformed” error appears for unwarranted escape characters

I might have found the culprit, it turns out to be a bug that will be fixed in future releases.

I compared the output of the HTTP Request from Postman to the one run from. The problem is the AcceptFormat property of the HTTP Request activity:
image

It overwrites the header specified here:

As such, when you compare the output of Studio POST request and Postman POST request, the accept header that reaches the server when sent via Studio is different.

Postman:

content-type: application/vnd.cpc.authreturn-v2+xml
accept: application/vnd.cpc.authreturn-v2+xml

Studio:

content-type: application/vnd.cpc.authreturn-v2+xml
accept: application/xml

Unfortunately, there is no way around with the current Web activity package version and you will need to wait for a patch.

It is possible to achieve it if you would code your own HTTP Request by using the Invoke Code activity.

@mBots_2020
Having found the reason it doesn’t work, I would suggest you to expire your API credentials you have posted on our Forum.

2 Likes

I’m now acquiring an “illegal character” error. Noticed on the stackoverflow forum that Base64 encoding uses some characters that are not allowed in URL query parameter values (‘/’ and ‘+’). To avoid this, pass Base64.URL_SAFE as the second parameter to Base64.encodeToString() instead of Base64.DEFAULT .
So wondering if it has to do with the ‘+’ sign in the content-type/Accept format

Thanks for your efforts! From a maintenance perspective, the recommendation is to use UiPath activities so I hope the bug is resolved soon. Please can assist with writing the invoke activity - I’ll try to find a forum as well since this is my first time using it.

Note that the API credentials are publicly on the Canada Post developer program

2 Likes

@mBots_2020

Please have a look.

@loginerror
Thank you, it was good catch. Was wondering what could have gone wrong.