DPD SOAP API

Post Reply
User avatar
bkromer
Member
Posts: 72
Joined: Thu Jul 11, 2019 10:41 am
Location: Germany

DPD SOAP API

Post by bkromer » Mon Jul 13, 2020 10:38 am

Hello,

I try to understand how we can make requests to a SOAP API within Enfocus Switch.
I want to test the DPD SOAP API https://esolutions.dpd.com/ they have a sandbox for testing purposes.
Image

For those who don't know DPD is a famous Parcel delivery service in Germany.

The first CALL we have to make is to get an Auth Token at: https://public-ws-stage.dpd.com/service ... V2_0/?wsdl

We have to provide the DelisID: sandboxdpd and password: xMmshh1 and also a MessageLanguage format like "en_EN".
I tried this in Integromat and it worked.
Image
Now I want to make the same call in Switch Scripter.
By reading the documentation ( https://www.enfocus.com/manuals/Develop ... class.html ) I find even with the scripting examples, it's really hard to understand what's really going on.

Does somebody have experience with SOAP API´s and could give me a hint on how to set this up?

Code: Select all

//  DPD SOAP API
function jobArrived( s : Switch, job : Job )
{
	
	SOAP.request("https://public-ws-stage.dpd.com/services/LoginService/V2_0/?wsdl")
}
Attachments
Bildschirmfoto 2020-07-13 um 10.20.41.png
Bildschirmfoto 2020-07-13 um 10.20.41.png (56.31 KiB) Viewed 3489 times
Benjamin Kromer

freddyp
Advanced member
Posts: 587
Joined: Thu Feb 09, 2012 3:53 pm

Re: DPD SOAP API

Post by freddyp » Mon Jul 13, 2020 12:06 pm

SOAP is sometimes referred to as "XML over HTTP". There is nothing you can do with the SOAP class that you cannot do with the HTTP class, but the reverse is not true!! In the HTTP class you can manipulate the headers of the request for example, something that is not possible in the SOAP class. The SOAP class was there long before the HTTP class and it is of course still there for compatibility reasons, but if you start from scratch forget about the SOAP class and go for the HTTP class.

This being said, I was somewhat surprised that a parcel delivery service would not also have a REST API so I simply searched for that and found this: https://api.dpd.ro/web-api.html. This is going to be a lot easier to implement than a SOAP-based communication.

User avatar
bkromer
Member
Posts: 72
Joined: Thu Jul 11, 2019 10:41 am
Location: Germany

Re: DPD SOAP API

Post by bkromer » Mon Jul 13, 2020 12:18 pm

freddyp wrote:
Mon Jul 13, 2020 12:06 pm
....The SOAP class was there long before the HTTP class and it is of course still there for compatibility reasons, but if you start from scratch forget about the SOAP class and go for the HTTP class.
You are right. Let's try this with the HTTP class then.
...This being said, I was somewhat surprised that a parcel delivery service would not also have a REST API so I simply searched for that and found this: https://api.dpd.ro/web-api.html. This is going to be a lot easier to implement than SOAP-based communication.
Yes I know I have also found this. Unfortunately, it's for Romania and cant be used in Germany... :(
In the german API, you can make the first call for the token as REST API Call sending a json with the credentials and language format and the next call for the shipmentService you need to make as SOAP. :|
Benjamin Kromer

freddyp
Advanced member
Posts: 587
Joined: Thu Feb 09, 2012 3:53 pm

Re: DPD SOAP API

Post by freddyp » Mon Jul 13, 2020 12:52 pm

Using SOAP is not that different. Instead of building a JSON you have to build an XML and post that and the result will of course also be XML and not JSON. That makes it sound easy, but unfortunately that is not always the case.

There is usually a WSDL file (this is in XML) that describes everything that is possible. Based on the number of calls in the REST API, I fear the WSDL will be somewhat intimidating so I hope the documentation has slimmed down samples for specific requests.

SOAP requests use XML namespaces. If you are not familiar with those, that adds a layer of complexity.

User avatar
bkromer
Member
Posts: 72
Joined: Thu Jul 11, 2019 10:41 am
Location: Germany

Re: DPD SOAP API

Post by bkromer » Sun Aug 02, 2020 2:46 pm

freddyp wrote:
Mon Jul 13, 2020 12:52 pm
Using SOAP is not that different. Instead of building a JSON you have to build an XML and post that and the result will of course also be XML and not JSON. That makes it sound easy, but unfortunately that is not always the case.

There is usually a WSDL file (this is in XML) that describes everything that is possible. Based on the number of calls in the REST API, I fear the WSDL will be somewhat intimidating so I hope the documentation has slimmed down samples for specific requests.

SOAP requests use XML namespaces. If you are not familiar with those, that adds a layer of complexity.
Well maybe you can help me getting started with this.
In the Enfocus docs there is the SOAP Class
SOAP ( in-path : String )
Constructs a new SOAP request and reads the SOAP envelope from the specified XML file.
The XML for the DPD loginService looks like this:

Code: Select all

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:ns="http://dpd.com/common/service/types/LoginService/2.0">
 <soapenv:Header/>
 <soapenv:Body>
 <ns:getAuth>
 <delisId>sandboxdpd</delisId>
 <password>xMmshh1</password>
 <messageLanguage>de_DE</messageLanguage>
 </ns:getAuth>
 </soapenv:Body>
<soapenv:Envelope>
And the WSDL Link is the following: https://public-ws-stage.dpd.com/service ... V2_0/?wsdl
When I throw the XML this doesnt work.

Code: Select all

function jobArrived( s : Switch, job : Job )
{
	var response = SOAP( job.getPath() ).send("https://public-ws-stage.dpd.com/services/LoginService/V2_0/?wsdl");
}
Can you help?
Benjamin Kromer

freddyp
Advanced member
Posts: 587
Joined: Thu Feb 09, 2012 3:53 pm

Re: DPD SOAP API

Post by freddyp » Mon Aug 03, 2020 11:08 am

When you read in the documentation that something is a constructor:
SOAP ( in-path : String )
Constructs a new SOAP request and reads the SOAP envelope from the specified XML file.
then the usage is:

Code: Select all

var soapRequest = new SOAP(inPath);
whereby inPath is not job.getPath(), but the path to the XML that constitutes the SOAP-request.

As to the send function, it is in the documentation listed as a static function, or in different words, a class method. The usage is:

Code: Select all

SOAP.send( url, soapRequest, "Some action");
You have to specify 3 parameters, but you only specify 1. Moreover, the documentation says that the function is called without waiting for a response. In other words, it is called asynchronously, you will want it to behave synchronously, so you have to use the request function instead. And the "action" that is expected as a third parameter is not clear either. The request function does not require this third parameter.

You seem to insist on using the SOAP class rather than using the HTTP class. Fine by me, but if you cannot make it work, do not say I did not tell you so :).

There is apparently a Node.js package for the DPD service: https://www.npmjs.com/package/dpd. My final word of advice on this is: use that package in a Switch 2020 Node.js-based script.

User avatar
bkromer
Member
Posts: 72
Joined: Thu Jul 11, 2019 10:41 am
Location: Germany

Re: DPD SOAP API

Post by bkromer » Mon Aug 03, 2020 10:11 pm

Wow the node.js package is something I will give it a try but atm we have not updated our server. But we will in the near future.

I would love to use http instead but I have no clue on how to get started.

Lets say I create a http object and as URL i specifie the wsdl link.
How should i send the XML file? With setAttachedFile()?
Wich Method should I use, post?
2020-08-03 22_07_12-SwitchScripter - soapXMLdpd.sscript.png
2020-08-03 22_07_12-SwitchScripter - soapXMLdpd.sscript.png (73.08 KiB) Viewed 3263 times
Benjamin Kromer

freddyp
Advanced member
Posts: 587
Joined: Thu Feb 09, 2012 3:53 pm

Re: DPD SOAP API

Post by freddyp » Tue Aug 04, 2020 10:35 am

Whether you have to POST or GET are things you have to find in the DPD documentation. SOAP API's generally use POST, but GET is technically allowed. Also the content of the HTTP headers you have to send is something you will find there. Whether you have to upload a file (setAttachedFile) or place the XML in the body (setPostData), whether you have to use MIME encoding or not -> documentation. And what do you have to do with the answer? I cannot help you further without studying the DPD API and running some tests. I am sure you will understand that this is over and beyond the effort acceptable for a forum.

My advice: DPD package in Node.js. At least you will not have to worry about the technical details of the API implementation.

A word from my own experience about Node.js and this is meant for everybody on the forum who is working with legacy scripting and who is thinking of moving to Node.js: the ability to work with all these packages opens up a whole host of new possibilities that were (very) difficult to realize with legacy scripting. I love it and it has already allowed me to accomplish things that I had not even considered before. But be warned about the packages too. Looking at a package's documentation may give you the impression that you can simply copy and paste a couple of lines of code and it automagically works. I have to disappoint you. It is not always that simple, partly because the documentation is not always that good, partly because there are things about the version of Javascript in Node.js that are very different from the version of Javascript used in the legacy scripting. If the terms "(a)synchronous behavior", "callbacks", "promisify" are not familiar to you, then you should get acquainted with them if you want to move to Node.js successfully.

And may I draw everybody's attention to the "Node.js scripting" part of the forum for questions specifically related to the new scripting environment.

freddyp
Advanced member
Posts: 587
Joined: Thu Feb 09, 2012 3:53 pm

Re: DPD SOAP API

Post by freddyp » Tue Aug 04, 2020 10:35 am

Whether you have to POST or GET are things you have to find in the DPD documentation. SOAP API's generally use POST, but GET is technically allowed. Also the content of the HTTP headers you have to send is something you will find there. Whether you have to upload a file (setAttachedFile) or place the XML in the body (setPostData), whether you have to use MIME encoding or not -> documentation. And what do you have to do with the answer? I cannot help you further without studying the DPD API and running some tests. I am sure you will understand that this is over and beyond the effort acceptable for a forum.

My advice: DPD package in Node.js. At least you will not have to worry about the technical details of the API implementation.

A word from my own experience about Node.js and this is meant for everybody on the forum who is working with legacy scripting and who is thinking of moving to Node.js: the ability to work with all these packages opens up a whole host of new possibilities that were (very) difficult to realize with legacy scripting. I love it and it has already allowed me to accomplish things that I had not even considered before. But be warned about the packages too. Looking at a package's documentation may give you the impression that you can simply copy and paste a couple of lines of code and it automagically works. I have to disappoint you. It is not always that simple, partly because the documentation is not always that good, partly because there are things about the version of Javascript in Node.js that are very different from the version of Javascript used in the legacy scripting. If the terms "(a)synchronous behavior", "callbacks", "promisify" are not familiar to you, then you should get acquainted with them if you want to move to Node.js successfully.

And may I draw everybody's attention to the "Node.js scripting" part of the forum for questions specifically related to the new scripting environment.

rowen
Newbie
Posts: 3
Joined: Fri Oct 12, 2018 10:16 am

Re: DPD SOAP API

Post by rowen » Fri Aug 07, 2020 12:46 pm

We've been integrating with DPD as well (Portugal), and it will be different, but maybe some of this can be helpful.
DPD Portugal still doesn't have a REST API, as far as I know, so we've been using SOAP as well.

We ended up using a script (still legacy) to build the XML file, according to the documentation, and then outputting the file to the flow and using the "HTTP request" flow element to handle the call to DPD's servers.
It's not the neatest way to handle it, since you'll be getting the response in an opaque dataset, but for our level of programming skills, it worked alright.

Maybe this could be a starting point for you.
Letting Switch handle the details of the request implementation at first and once you have it working, trying to build it yourself in the script.

This is all a high-level kind of advice… As freddyp mentioned, getting the full documentation and perhaps some sample files will be most helpful.

User avatar
bkromer
Member
Posts: 72
Joined: Thu Jul 11, 2019 10:41 am
Location: Germany

Re: DPD SOAP API

Post by bkromer » Fri Nov 20, 2020 10:25 am

rowen wrote:
Fri Aug 07, 2020 12:46 pm
We've been integrating with DPD as well (Portugal), and it will be different, but maybe some of this can be helpful.
DPD Portugal still doesn't have a REST API, as far as I know, so we've been using SOAP as well.

We ended up using a script (still legacy) to build the XML file, according to the documentation, and then outputting the file to the flow and using the "HTTP request" flow element to handle the call to DPD's servers.
It's not the neatest way to handle it, since you'll be getting the response in an opaque dataset, but for our level of programming skills, it worked alright.

Maybe this could be a starting point for you.
Letting Switch handle the details of the request implementation at first and once you have it working, trying to build it yourself in the script.

This is all a high-level kind of advice… As freddyp mentioned, getting the full documentation and perhaps some sample files will be most helpful.
Are u willing to share your code with the community and maybe your Flow? This would be great.
Benjamin Kromer

Post Reply