Professional Web Applications Themes

XML post and Get - Coldfusion - Advanced Techniques

I am trying to integrate DHL API with my coldfusion code creating an xml file and posting it and getting the responce. I used the following code but it doesn't seem to work. Please help me someone. Let me know whats wrong. <cfsavecontent variable="returnitesportsxml"> <cfoutput> <?xml version="1.0" encoding="utf-8"?> <Ecommerce action='Request' version="1.1"> <Requestor> <ID>ESPOR_9192</ID> <Password>MPM605D75Y</Password> </Requestor> <ReturnShipment action='GenerateLabel' version='1.0'> <ShippingCredentials> <ShippingKey>5A233F2B2C4150424D57515A5651305341485 0444156545D5D</ShippingK ey> <AccountNbr>850892633</AccountNbr> </ShippingCredentials> <ShipmentDetail> <Service> <Code>E</Code> </Service> <ShipmentType> <Code>P</Code> </ShipmentType> <Weight>3</Weight> <ContentDesc>Test description</ContentDesc> <ShipperReference>11111</ShipperReference> <Dimensions> <Length>3</Length> <Width>5</Width> <Height>10</Height> </Dimensions> <AdditionalProtection> <Code>AP</Code> <Value>1500</Value> </AdditionalProtection> </ShipmentDetail> <Billing> <Party> <Code>R</Code> </Party> <AccountNbr>850892633</AccountNbr> </Billing> <Sender> <Address> <CompanyName>Merlyn</CompanyName> <SuiteDepartmentName>HR</SuiteDepartmentName> <Street>4034 N.Story Rd</Street> <StreetLine2>xx212</StreetLine2> <City>Irving</City> ...

  1. #1

    Default XML post and Get

    I am trying to integrate DHL API with my coldfusion code creating an xml file
    and posting it and getting the responce. I used the following code but it
    doesn't seem to work. Please help me someone. Let me know whats wrong.

    <cfsavecontent variable="returnitesportsxml">
    <cfoutput>
    <?xml version="1.0" encoding="utf-8"?>
    <Ecommerce action='Request' version="1.1">
    <Requestor>
    <ID>ESPOR_9192</ID>
    <Password>MPM605D75Y</Password>
    </Requestor>
    <ReturnShipment action='GenerateLabel' version='1.0'>
    <ShippingCredentials>

    <ShippingKey>5A233F2B2C4150424D57515A5651305341485 0444156545D5D</ShippingK
    ey>
    <AccountNbr>850892633</AccountNbr>
    </ShippingCredentials>
    <ShipmentDetail>
    <Service>
    <Code>E</Code>
    </Service>
    <ShipmentType>
    <Code>P</Code>
    </ShipmentType>
    <Weight>3</Weight>
    <ContentDesc>Test description</ContentDesc>
    <ShipperReference>11111</ShipperReference>
    <Dimensions>
    <Length>3</Length>
    <Width>5</Width>
    <Height>10</Height>
    </Dimensions>
    <AdditionalProtection>
    <Code>AP</Code>
    <Value>1500</Value>
    </AdditionalProtection>
    </ShipmentDetail>
    <Billing>
    <Party>
    <Code>R</Code>
    </Party>
    <AccountNbr>850892633</AccountNbr>
    </Billing>
    <Sender>
    <Address>
    <CompanyName>Merlyn</CompanyName>
    <SuiteDepartmentName>HR</SuiteDepartmentName>
    <Street>4034 N.Story Rd</Street>
    <StreetLine2>xx212</StreetLine2>
    <City>Irving</City>
    <State>TX</State>
    <PostalCode>75038</PostalCode>
    <Country>USA</Country>
    </Address>
    </Sender>
    <Receiver>
    <Address>
    <CompanyName>Esports Partners</CompanyName>
    <SuiteDepartmentName>IT</SuiteDepartmentName>
    <Street>700 Freeport Parkway</Street>
    <StreetLine2>x</StreetLine2>
    <City>Coppel</City>
    <State>TX</State>
    <PostalCode>75019</PostalCode>
    <Country>USA</Country>
    </Address>
    <AccountNbr>850892633</AccountNbr>
    <AttnTo>Mamta</AttnTo>
    <PhoneNbr>214-550-7955</PhoneNbr>
    </Receiver>
    <ShipmentProcessingInstructions>
    <Label>
    <IncludeReceipt>Yes</IncludeReceipt>
    <Size>8.5x11</Size>
    <ImageType>GIF</ImageType>
    </Label>
    </ShipmentProcessingInstructions>
    <TransactionTrace>Example Return Shipment Request</TransactionTrace>
    </ReturnShipment>
    </Ecommerce>
    </cfoutput>
    </cfsavecontent>
    <cftry>
    <cfset xmlobj = tostring(#returnitesportsxml#)>
    <cfhttp method="post"
    url="HTTPS://eCommerce.airborne.com/ApiLandingTest.asp"
    throwonerror="yes" username="ESPOR_9192" password="MPM605D75Y">
    <cfhttpparam type="xml" name="esportsrequest" value="#xmlobj#">
    </cfhttp>
    <cfcatch type="Any">
    <P>Failure!<cfabort>
    </cfcatch>
    </cftry>
    <P>Success!
    <cfoutput>#cfhttp.FileContent#</cfoutput>
    </form>

    Merlyn Guest

  2. #2

    Default Re: XML post and Get

    I would do it using cfxml to render your xml file then post your xml file to the url.
    Abinidi Guest

  3. #3

    Default Re: XML post and Get

    I'm working on the same project with DHL, been having a hard time and
    they are sloooow to respond with any kind of help.

    I can post and get a response, but with errors :-( Here's what I'm
    doing:

    <cfsetting enablecfoutputonly="Yes" showdebugoutput="No">
    <cfoutput>
    <cfhttp method="post"
    url="https://ecommerce.airborne.com/apilandingtest.asp">
    <?xml version='1.0'?><ECommerce action='Request' version='1.1'>
    <Requestor>
    <ID>#form.ID#</ID>
    <Password>#form.Password#</Password>
    </Requestor>
    <Shipment action = 'GenerateLabel' version = '1.0'>
    <ShippingCredentials>
    <ShippingKey>#form.ShippingKey#</ShippingKey>
    <AccountNbr>#form.AccountNumber#</AccountNbr>
    </ShippingCredentials>
    <ShipmentDetail>
    <ShipDate>#dateformat(form.ShipDate,"yyyy-mm-dd")#</ShipDate>
    <Service>
    <Code>#left(form.Service,1)#</Code>
    </Service>
    <cfif form.Service eq "E1030">
    <SpecialServices>
    <Specialservice>1030</Specialservice>
    </SpecialServices>
    <cfelseif form.Service eq "ESAT">
    <SpecialServices>
    <Specialservice>SAT</Specialservice>
    </SpecialServices>
    </cfif>
    <ShipmentType>
    <Code>#form.Type#</Code>
    </ShipmentType>
    <cfif form.Type eq "P">
    <Weight>#form.PWeight#</Weight>
    </cfif>
    <ContentDesc>#xmlformat(form.Desc)#</ContentDesc>
    <ShipperReference>#xmlformat(form.Reference)#</ShipperReference>
    <cfif form.Type eq "P">
    <Dimensions>
    <Length>#form.PLength#</Length>
    <Width>#form.PWidth#</Width>
    <Height>#form.PHeight#</Height>
    </Dimensions>
    </cfif>
    </ShipmentDetail>
    <Billing>
    <Party>
    <Code>S</Code>
    </Party>
    </Billing>
    <Sender>
    <SentBy>#xmlformat(form.SentBy)#</SentBy>
    <PhoneNbr>#xmlformat(form.SenderPhone)#</PhoneNbr>
    </Sender>
    <Receiver>
    <Address>
    <CompanyName>#xmlformat(form.CompanyName)#</CompanyName>
    <Street>#xmlformat(form.Street)#</Street>
    <StreetLine2>#xmlformat(form.Street2)#</StreetLine2>
    <City>#xmlformat(form.City)#</City>
    <State>#xmlformat(form.State)#</State>
    <PostalCode>#xmlformat(form.PostalCode)#</PostalCode>
    <Country>US</Country>
    </Address>
    <AttnTo>#xmlformat(form.AttnTo)#</AttnTo>
    <PhoneNbr>#xmlformat(form.PhoneNbr)#</PhoneNbr>
    </Receiver>
    <ShipmentProcessingInstructions>
    <Label>
    <ImageType>JPEG</ImageType>
    </Label>
    <Notification>
    <Notify>
    <EmailAddress>#xmlformat(form.Email)#</EmailAddress>
    </Notify>
    </Notification>
    </ShipmentProcessingInstructions>
    </Shipment>
    </ECommerce>
    <cfhttpparam name="xml" type="formfield" value="hello">
    </cfhttp>
    </cfoutput>

    Would love to keep in touch Meryl... com

    Houston Guest

  4. #4

    Default Re: XML post and Get

    Can you explain a little more about what's not working? Are you able to submit
    and get a response? If so what is the response?

    I'm working on this exact same project, I am able to post the XML and get a
    response, but I'm getting:
    "DOM Doent Error Code = -1072896680, Line = 0, Posn = 0, Reason = XML
    doent must have a top level element."

    I sent in my stuff to DHL, but they are really slow to respond with help.
    They will support the XML questions, but no programming!

    -James

    ChillerD Guest

  5. #5

    Default Re: XML post and Get

    I got the same error when I created the xml doent using cfxml as the API
    requires <?xml version="1.0" encoding="utf-8"?>
    top level element. So, i used <cfsavecontent>. I was able to make the
    connection but its giving me the fault 'Invalid shipping Key' I called DHL
    people but I haven't heard from them yet.

    Anyways, how are you going to convert the image into HTMLL output?? Please let
    me know.

    Merlyn Guest

  6. #6

    Default Re: XML post and Get

    If I could get this to work I might have an idea on the image, but nothing so
    far! As I'm sure you see, DHL's "Customer Service is Back" campaign does not
    really apply to the API dept! It took them two weeks to get me an account that
    I could use to develop with, and that's with me calling them every day or two.
    But I digress...

    I will try to submit the way you are doing it to see if I have any luck, I'd
    be interested in staying in touch with you to compare notes, right now we are
    just 'evaluating' to see if this will even work for us.

    Has anyone else done this DHL API?

    (Sorry about the name change, I finally remembered my password to my original
    account!)

    -James

    Chiller Guest

  7. #7

    Default Re: XML post and Get

    Hi James,

    I was just wondering if there was any progress. I'm still waiting on DHL people to give the correct shipping id
    Merlyn Guest

  8. #8

    Default Re: XML post and Get

    Try this...

    <cfsavecontent variable="returnitesportsxml"><cfoutput><?xml version="1.0"
    encoding="utf-8"?>
    <bla bla bla/>
    <cfsavecontent>

    I had problems with the extra blank line before the XML declaration.

    ScottyMTL Guest

  9. #9

    Default Re: XML post and Get

    Thanks for your response.

    I received the response from DHL but I was just wondering how can I show the
    label in HTML format ? I got the base64 encoded image. Please let me know how
    can I output an image?

    Thank you.

    Merlyn Guest

  10. #10

    Default Re: XML post and Get

    Sorry, I've been out a few days...

    I finally got my XML packages to get a valid response, but I keep getting
    "Required element/node is missing.,
    Shipment/ProcessingInstructions/Notification/Message"

    Hey Merlyn, can you post your XML? I compared mine to yours are they are
    almost identicle, I can't see where I'm going wrong, and DHL takes forever to
    respond :-(

    You can also reach me at com

    Chiller Guest

  11. #11

    Default Re: XML post and Get

    <ShipmentProcessingInstructions>
    <Label>
    <IncludeReceipt>Yes</IncludeReceipt>
    <Size>8.5x11</Size>
    <ImageType>GIF</ImageType>
    </Label>
    </ShipmentProcessingInstructions>


    Your ShipmentProcessingInstructions[/] node is missing Notification and
    Message sub nodes... what does it says in your doc, are they mandatory?

    ScottyMTL Guest

  12. #12

    Default Re: XML post and Get

    The doc say optional for the Message node, but I put it in and it works!

    I got a good response, even the email notification, now to figure out how to convert the binary to image...
    Chiller Guest

  13. #13

    Default Re: XML post and Get

    OK, got it, this worked for me to convert the XML to a useable image:

    <cfset BinaryImage =
    ToBinary(pdXML.ECommerce.Shipment.Label.Image. xmltext)>
    <cffile action="write" file="D:\somepath\imagetest.gif"
    output="#BinaryImage#">


    Chiller Guest

Similar Threads

  1. redirect but with post data - mimick form post behaviour
    By LuckyNinja in forum Coldfusion - Advanced Techniques
    Replies: 4
    Last Post: April 14th, 05:58 PM
  2. How to post some data in form of POST action of forms in asp?
    By Mehdi Mousavi in forum ASP Components
    Replies: 1
    Last Post: September 19th, 05:16 PM
  3. post data, then post again..
    By JT in forum ASP
    Replies: 1
    Last Post: September 5th, 11:14 PM
  4. PHP HTTPS POST Como hacer un POST https con PHP
    By Ing. Angel León in forum PHP Development
    Replies: 0
    Last Post: September 5th, 03:45 AM
  5. ASP, FORMS, POST METHOD And Post with out form(???)
    By Don Glover the younger in forum ASP
    Replies: 2
    Last Post: July 13th, 03:27 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139