Posting SOAP/XML calls through wappler's native API call does not recognise '<' charcater

Hello, I am aware that wappler’s API call module does not officially support SOAP/XML calls, but since the text body options is present I haven’t come across any issues yet, up until now. I have seen a similar post couple of years back using PHP, but since I’m using node, I thought I’d create a new one instead.

Basically what I am trying to do is make a POST call to ebay’s UploadSiteHostedPictures service, which is a traditional API SOAP or xml based call, with values:

Url: https://api.ebay.com/ws/api.dll
Text Data: <?xml version="1.0" encoding="utf-8"?> <UploadSiteHostedPicturesRequest xmlns="urn:ebay:apis:eBLBaseComponents"> <ErrorLanguage>en_US</ErrorLanguage> <WarningLevel>High</WarningLevel> <!--Enter your ExternalPictureURL address --> <ExternalPictureURL>https://images.pexels.com/photos/1000366/pexels-photo-1000366.jpeg</ExternalPictureURL> <PictureName>Developer Page Banner</PictureName> </UploadSiteHostedPicturesRequest>

Headers: X-EBAY-API-SITEID:3 X-EBAY-API-COMPATIBILITY-LEVEL:967 X-EBAY-API-CALL-NAME:UploadSiteHostedPictures X-EBAY-API-IAF-TOKEN:--TOKEN GOES HERE

P.S. Auth token isn’t require to reproduce the error, as the error happens before the post call is actually initiated.
And once I try to fetch or define schema it results to:

`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2023-08-06T09:30:26.874Z Failure XML Parse error. XML Error Text: "{0}". 5 Error RequestError 0 mediasvcs-5.0.29_20230720192304011 2 ` Ebay documentation states that error is : ` XML parse errors are typically caused by unrecognized characters. The offending characters are often hidden and were likely added inadvertently when copying content from another program into eBay. When you view the text in Notepad, the offending characters appear as small squares. Delete the squares, save the file, and resubmit the template to eBay.`

Wappler produces something similar


but presumably it’s the error at the wappler’s end, as Insomnia or POSTMAN returns data without any issues:

Now I wonder has anyone came across similar issue where ‘<’ value would not be recognised and whether there’s a workaround for it?

I am considering building separate axios script to create the very same call, however, in local environment axios has not returned anything through RunJS module, or nor the out of wappler hosted nodejs application, so I thought I’d ask whether anyone has any ideas before i jump into custom module/RunJS code rabbit hole. :man_shrugging:

Wappler schema parsing is for JSON only (as far as I know), the error you see is to be expected, as the < character is not a valid JSON start. However, this error does not prevent you from actually performing the request nor getting a reply back, you just miss on the schema and have to treat the response as a string.

I’m not familiar with the procedure to convert a XML string to an object (JSON equivalent) in Wappler, but I’m sure someone else has done this before (hopefully someone is able to help you)

Lots of NPMs dealing with xml to json and back. Should be possible to write an server connect extension to parse the output

Perfect! Thank you for your both response, I am going to use your pointers and see what I can do! :innocent:

Tried using xmldom package to change xml value to json object, and post it inside json body, unfortunately the same error persists, figured it makes sense since ebay is expecting xml? and then i realised, I already have a POST action that is sending message responses via the same TRADING API as text body, and it is working perfectly! So I’m not entirely sure why that specific call isn’t working in wappler, yet using postman or insomnia it gets posted. :man_shrugging: Thank you for your inputs tho! back to brainstorming…

Yes! The XML to JSON conversion should only be done on the API response, only for your own application. You’re not supposed to send JSON to an API expecting XML, you’re supposed to convert the XML response you get to JSON so you can work with it within Wappler

Use a mock HTTP server and send the request there, such as:


So you can see exactly the HTTP request Wappler makes, and then do it from Postman or Insomnia and compare the requests

Brilliant! I never knew these tools existed! I’ll dig deeper to find the root of this! :clap:

Looks like the xml error was only for when fetching the schema, as once fetching the schema beeceptor receives empty body, where the load in browser send the values, which error telling me to contact support.

Also looks like the major differences between insomnia and wappler api is that i forces content type as application/text (presumably because it’s chosen as the post data type)

Wappler call headers:
"user-agent": "car_parts_hub/1.6.0", "content-length": "434", "accept": "application/json", "content-type": "application/text", "x-ebay-api-call-name": "UploadSiteHostedPictures", "x-ebay-api-compatibility-level": "967", "x-ebay-api-iaf-token": 'code here'

Insomnia post call:
"user-agent": "insomnia/2023.4.0", "content-length": "434", "accept": "*/*", "content-type": "application/xml", "x-ebay-api-call-name": "UploadSiteHostedPictures", "x-ebay-api-compatibility-level": "967", "x-ebay-api-iaf-token": code_here

i’ve tried applying content-type as a header, but my best guess is that they were being overwritten. Not sure what are the next steps but starting to consider to learn ebay-api package and use it instead :thinking:

Please open a bug report for not being able to overwrite the header

Hi. You cannot use the native API Action step to call a SOAP API that returns XML.
You will have to create a separate custom extension to call XML APIs.

You can refer this API File Upload Action I had created some time ago, for reference.

Great, thank you for your help!

I have actually been playing around the runJs extension, simple because I’m performing a single action once in a while and creating an extension would most likely take much longer to set up(Which I’m willing and will most likely digest into for further knowledge), but the code I am using for simple axios post action in RunJS extension is:

const axios = require(‘axios’);

function performPostRequest() {
const url = ‘https://api.ebay.com/ws/api.dll’;
const xmlData = <?xml version="1.0" encoding="utf-8"?> <UploadSiteHostedPicturesRequest xmlns="urn:ebay:apis:eBLBaseComponents"> <ErrorLanguage>en_US</ErrorLanguage> <WarningLevel>High</WarningLevel> <ExternalPictureURL>https://images.pexels.com/photos/1000366/pexels-photo-1000366.jpeg</ExternalPictureURL> <PictureName>Developer Page Banner</PictureName> </UploadSiteHostedPicturesRequest>;

const headers = {
‘X-EBAY-API-SITEID’: ‘3’,
‘X-EBAY-API-COMPATIBILITY-LEVEL’: ‘967’,
‘X-EBAY-API-CALL-NAME’: ‘UploadSiteHostedPictures’,
‘X-EBAY-API-IAF-TOKEN’: ‘’
};

return axios.post(url, xmlData, { headers })
.then(response => {
return response.data;
})
.catch(error => {
throw error;
});
}

performPostRequest()
.then(data => {
console.log(data);
// Handle the response data here
})
.catch(error => {
console.error(error);
// Handle any errors that occurred during the request
});

Using it with express server it returns values inside insomnia, however I guess since my lack of knowledge catching the response my browser returns empty data, pressumably because I need to map it here


I have tried using console.log(data) as a value, but without any luck, Would you have any suggestions or pointers how to capture post reponse from the server using axios? :thinking:

Or wait, is the data only for mapping variables inside the code and is not meant to receive response? :sweat_smile:

You should see console log in the logs in Wappler, not in the browser.
There are also options to throw error… Which would help identify the problem in the code before console log.

Oh great, I see the response in server logs!

.......  
............. 
server-connect:app   forward_console: true,
      server-connect:app   async_function: true
      server-connect:app } +0ms
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <UploadSiteHostedPicturesResponse xmlns="urn:ebay:apis:eBLBaseComponents">
        <Timestamp>2023-08-08T20:40:26.539Z</Timestamp>
        <Ack>Success</Ack>
        <Version>0</Version>
        <Build>mediasvcs-5.0.29_20230720192304011</Build>
        <PictureSystemVersion>2</PictureSystemVersion>
        <SiteHostedPictureDetails>
            <PictureName>Developer Page Banner</PictureName>
            <PictureSet>Standard</PictureSet>
            <PictureFormat>JPG</PictureFormat>
            <FullURL>https://i.ebayimg.com/00/s/MTA2N1gxNjAw/z/0SIAAOSwqItk0qg6/$_1.JPG?set_id=2</FullURL>
            <BaseURL>https://i.ebayimg.com/00/s/MTA2N1gxNjAw/z/0SIAAOSwqItk0qg6/$_</BaseURL>
            <PictureSetMember>
                <MemberURL>https://i.ebayimg.com/00/s/MTA2N1gxNjAw/z/0SIAAOSwqItk0qg6/$_1.JPG</MemberURL>
                <PictureHeight>266</PictureHeight>
                <PictureWidth>400</PictureWidth>
            </PictureSetMember>
            <ExternalPictureURL>https://images.pexels.com/photos/1000366/pexels-photo-1000366.jpeg</ExternalPictureURL>
            <UseByDate>2023-09-07T20:40:25.061Z</UseByDate>
        </SiteHostedPictureDetails>
    </UploadSiteHostedPicturesResponse>

So If I understood it correctly from other forums posts, I can capture console.log within the response action? :thinking:

May I suggest you start using the async/await syntax for better JS code clarity? You can check it on the following blog post :slight_smile:

Your question is very badly worded :stuck_out_tongue:
Using RunJS you can return data, so yes, you can return the response and deal with it in other Wappler steps.

Thank you I’ll have a look into it! :smiley: