homepage Welcome to WebmasterWorld Guest from 107.21.187.131
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / XML Development
Forum Library, Charter, Moderators: httpwebwitch

XML Development Forum

    
USPS V 4 API Error
Only with LARGE and ALL
rocknbil




msg:4411118
 4:30 pm on Jan 26, 2012 (gmt 0)

An older site that needed updating. Using the USPS Rate Calculator V4 API, the problem is only when the package type is LARGE and the requested rates are ALL. The usage is I first request all, which outputs a list of available services from which the user chooses.

The current XML I send to USPS:

<RateV4Request USERID="THIS-USER">
<Revision>2</Revision>
<Package ID="1ST">
<Service>All</Service>
<ZipOrigination>91942</ZipOrigination>
<ZipDestination>97526</ZipDestination>
<Pounds>59</Pounds>
<Ounces>4</Ounces>
<Container>RECTANGULAR</Container>
<Size>Large</Size>
<Machinable>FALSE</Machinable>
<Width>6.00</Width>
<Length>36.00</Length>
<Height>30.00</Height>
<ReturnLocations>91942</ReturnLocations>
<ReturnServiceInfo>blah blah</ReturnServiceInfo>
<ShipDate>30-Jan-2012</ShipDate>
</Package>
</RateV4Request>


These are test values you may drop into a test and sub out your user id. The program properly uses the production URL and the RateV4 domestic API.

The error:

Invalid XML Element content is invalid according to the DTD/Schema. Expecting: ReturnLocations, ReturnServiceInfo, ShipDate. line= 11 pos= 10


- Line 11 is the machinable line (right?) :-\
- The documentation claims all three of those are optional. The documentation is really sparse, and see no indication that these three are required for large packages in combination with all services.
- Note I've added dummy values for the three missing attributes. Same error.
- I have tried it with and without a Girth value, no difference.
- Selecting a single service (such as priority mail, example) functions fine. It's only in combination with packages large and all services.
- This post only comes after hours of searching on the web and this board.

Not that it matters, it's programmed in Perl and was functioning fine in versions 2 and 3.

Any ideas?

 

httpwebwitch




msg:4411143
 5:07 pm on Jan 26, 2012 (gmt 0)

>> Expecting: ReturnLocations, ReturnServiceInfo, ShipDate

ie all values that appear after the <Height> element. Is there something wrong with the <Height>? Is the XML being truncated?

where is the DTD/Schema defined... can you take a look at it? That error wouldn't happen if those elements are truly optional as the documentation suggests.

Were you me I would be on the phone with USPS... or maybe on hold with USPS (sadLOL)

sun818




msg:4411151
 5:16 pm on Jan 26, 2012 (gmt 0)

I will ask my pc postage developer contact and see what he has to say.

Try playing around with MACHINABLE as true or false.

Meanwhile, read this and see if you get any inspiration from it:

https://www.usps.com/webtools/htm/Rate-Calculators-v1-3.htm

rocknbil




msg:4411183
 6:17 pm on Jan 26, 2012 (gmt 0)

ie all values that appear after the <Height> element. Is there something wrong with the <Height>? Is the XML being truncated?


Don't think so, those both generate different errors if they are malformed. You can figure out how I know that. :-P

I just tried forcing the L/W/H values to int instead of .xx, no effect.

where is the DTD/Schema defined...

That is an EXTREMELY good question. I have no idea and part of this was searching for it. I don't know. :-\

Were you me I would be on the phone with USPS... or maybe on hold with USPS (sadLOL)

That's coming. I fear the hold time (I have a statue of a skeleton at a computer on my desk . . . you know the one . . . )

read this and see if you get any inspiration from it:


Yeah that's the (semi-worthless) documentation of the V4 API. The PDF version is at least a little more digestible.

Machinable is required for large packages, and it must be false, container must be rectangular . . . chokes without it. Played around with rearranging the order of the attributes too, unless you put them outside the tree it doesn't seem to have any effect.

sun818




msg:4411199
 7:00 pm on Jan 26, 2012 (gmt 0)

You can try:

1) making machinable True,

or

2) omit Machinable XML

Dijkgraaf




msg:4411245
 8:35 pm on Jan 26, 2012 (gmt 0)

What it means that it was expecting one of the listed elements of "ReturnLocations, ReturnServiceInfo, ShipDate" which means that the ReturnLocations & ReturnServiceInfo are optionally occurring ones (min occurs=0), but ShipDate is mandatory. Add Shipdate before Machinable and that error will go away.

rocknbil




msg:4411354
 1:46 am on Jan 27, 2012 (gmt 0)


<RateV4Request USERID="the-user">
<Revision>2</Revision>
<Package ID="1ST">
<Service>All</Service>
<ZipOrigination>91942</ZipOrigination>
<ZipDestination>97526</ZipDestination>
<Pounds>48</Pounds>
<Ounces>4</Ounces>
<Container>RECTANGULAR</Container>
<ShipDate>30-Jan-2012</ShipDate>
<Size>Large</Size>
<Machinable>FALSE</Machinable>
<Width>6</Width>
<Length>36</Length>
<Height>30</Height>
</Package>
</RateV4Request>

Expecting: Size. But, you're onto something, that led to the solution: -) I missed a very important part of the docs, " . . . pay specific attention to the order and case of the tags . . . " it was exactly that. When elements are output in exactly the order specified in the diagram,

<RateV4Request USERID="the-user">
<Revision>2</Revision>
<Package ID="1ST">
<Service>All</Service>
<ZipOrigination>91942</ZipOrigination>
<ZipDestination>97526</ZipDestination>
<Pounds>48</Pounds>
<Ounces>4</Ounces>
<Container>RECTANGULAR</Container>
<Size>Large</Size>
<Width>6</Width>
<Length>36</Length>
<Height>30</Height>
<Machinable>FALSE</Machinable>
</Package>
</RateV4Request>


SUCCESS, THANK YOU! And the optional elements, ship date included, remain optional.

Dijkgraaf




msg:4411368
 3:09 am on Jan 27, 2012 (gmt 0)

Yes, if the schema specifies the the elements should be in a particular sequence (some schemas don't) then they need to be in that exact sequence.

Yes, XML is case sensitive and your XML nodes/elements need to match the case exactly.

This schema expect things in sequence
<?xml version="1.0" encoding="utf-16"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="RateV4Request">
<xs:complexType>
<xs:sequence>
<xs:element name="Revision" type="xs:unsignedByte" />
<xs:element name="Package">
<xs:complexType>
<xs:sequence>
<xs:element name="Service" type="xs:string" />
<xs:element name="ZipOrigination" type="xs:unsignedInt" />
<xs:element name="ZipDestination" type="xs:unsignedInt" />
<xs:element name="Pounds" type="xs:unsignedByte" />
<xs:element name="Ounces" type="xs:unsignedByte" />
<xs:element name="Container" type="xs:string" />
<xs:element name="Size" type="xs:string" />
<xs:element name="Width" type="xs:unsignedByte" />
<xs:element name="Length" type="xs:unsignedByte" />
<xs:element name="Height" type="xs:unsignedByte" />
<xs:element name="Machinable" type="xs:string" />
</xs:sequence>
<xs:attribute name="ID" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="USERID" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:schema>

This one doesn't
<?xml version="1.0" encoding="utf-16"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="RateV4Request">
<xs:complexType>
<xs:all minOccurs="1" maxOccurs="1">
<xs:element name="Revision" type="xs:unsignedByte" />
<xs:element name="Package">
<xs:complexType>
<xs:all minOccurs="1" maxOccurs="1">
<xs:element name="Service" type="xs:string" />
<xs:element name="ZipOrigination" type="xs:unsignedInt" />
<xs:element name="ZipDestination" type="xs:unsignedInt" />
<xs:element name="Pounds" type="xs:unsignedByte" />
<xs:element name="Ounces" type="xs:unsignedByte" />
<xs:element name="Container" type="xs:string" />
<xs:element name="Size" type="xs:string" />
<xs:element name="Width" type="xs:unsignedByte" />
<xs:element name="Length" type="xs:unsignedByte" />
<xs:element name="Height" type="xs:unsignedByte" />
<xs:element name="Machinable" type="xs:string" />
</xs:all>
<xs:attribute name="ID" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:all>
<xs:attribute name="USERID" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:schema>

rocknbil




msg:4411540
 4:33 pm on Jan 27, 2012 (gmt 0)

Knew about cases sensitivity but part of the problem was I've no idea where the DTD is and USPS isn't saying. :-)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / XML Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved