Someone on Facebook mentioned needing to work with Australia Posts API for getting prices calculated, so I figured I'd have a go!
It took me about a half hour but my simple test works fine.
First you need to sign up for an account and an API key, you can't get the API key without an account, and you need your API key when talking to their API server.
The test code is very very simple:
Here we're calculating the cost for a domestic parcel, going from postcode 2128 to postcode 6000, the package has a length of 96cm, width of 8cm, height of 5cm and a weight of 1.5 kilos.
You will receive an XML response with lots of nice info such as the price, just do a cfdump if you want to take a look at the return.
You can find the full API doc here: http://auspost.com.au/devcentre/assets/pdfs/pac-pcs-technical-specification.pdf
Hopefully someone will have use for this simple example!
--Edit with update--
I've ran the following code on CF 9.0.2 and it runs just fine:
Hey i've tried your code and it's giving me a "Content is not allowed in prolog." error any ideas why?
ReplyDeleteHi Sebastien, I just tried the code on OpenBD 2.0.1 and it's working fine for me, what engine and version are you using?
ReplyDeleteDid you put your API key in the cfhttpparam?
I haven't seen that error before, but google suggests it has something to do with the underlying JAVA code not liking the XML, are you forcing a certain encoding?
Hey Marcus, strange i've tried the same code locally on CF10 server and seems to work, but when i try it on the live CF9 server it doesn't odd,
ReplyDeleteAnyway i've parsed the XML successfully locally but having issues when trying to extract some of the XML data e.g. (xmlSearch(MyXML, "services/service")) keeps saying "Complex object types cannot be converted to simple values" any pointers? i've used this code before to extract XML data but never had these issues
Thanks for your help
Hi Freelance,
DeleteYay for the differences between CF versions.
On CF9 if I remember you have to be more explicit, services contains the whole shebang, so if you want to pull let's say the price, try changing your service/services to services/service/price (It should work, but I don't have a CF9 server handy to test it out on)
I'm trying to grab a CF9 dev download to test it out with, I'll post an update here when I test it (Feel free to try it and post too)
As a sidenote, on OpenBD I can just do:
Delete#XmlParse(xmlsource).services.service.price#
That just pulls the price and outputs as text, I don't think that'll work on CF9 but I'll test that too once I found a download.
Just figured it out i ended up using this code
Delete----------------------------------------------------------------
#xmlDoc#
That seems to work on my local CF10 server but i have yet to try it on CF9 fingers crossed!
And in classic Coldfusion style, the code just spits out "Content is not allowed in prolog." on CF9
ReplyDeleteSebastien, I've updated the post with my CF9 code test.
ReplyDeleteHey Marcus i finally figured it out the CFHTTP request had to have charset="UTF-8" parameter!
ReplyDeleteSebastien, that's great :)
DeleteMy server (And dev box) use UTF-8 as default so I didn't run into that, glad you figured it out!
Thanks for your help! Greatly appreciated!
ReplyDeleteNo problem, but you figured it out yourself :)
Delete