Anyways, I am trying to use the rate calculator API for a non-merchant
app. The USPS API wants XML scipt to be sent to it. I've basically
generated the script they want using Miva. When I MvCall it, I get a
"Parameter is incorrect" message. If I paste the "action" link to the
IE address bar, it works ! ?. Makes no difference with get/post. It
seems to me that MvCall is adding or changing something. Has anyone
successfully interacted with this or any of the APIs of the USPS? I
removed my ID code in this sample.
Here is the most basic call made from my server:
<MvAssign name="cstring"
value="{'http://testing.shippingapis.com/ShippingAPITest.dll?API=RateV2&XML=<RateV2Request
USERID=' $ asciichar(34) $ 'xxxx' $ asciichar(34) $ '><Package ID=' $
asciichar(34) $ '0' $ asciichar(34) $
'><Service>PRIORITY</Service><ZipOrigination>10022</ZipOrigination><ZipDestination>20008</ZipDestination><Pounds>10</Pounds><Ounces>5</Ounces><Container>Flat
Rate Box</Container><Size>REGULAR</Size></Package></RateV2Request>'}">
<MvCall
action="&[cstring];"
method="post">
<MvEVAL EXPR="{callvalue}">
</MvCall>
The response from the the USPS server is the following html page source
that states there is a parameter error. But, If I paste the http link
below in the address bar, it works just fine and the USPS returns the
correct response.
<html>
http://testing.shippingapis.com/ShippingAPITest.dll?API=RateV2&XML=<RateV2Request
USERID="xxxx"><Package
ID="0"><Service>PRIORITY</Service><ZipOrigination>10022</ZipOrigination><ZipDestination>20008</ZipDestination><Pounds>10</Pounds><Ounces>5</Ounces><Container>Flat
Rate
Box</Container><Size>REGULAR</Size></Package></RateV2Request><br><br>
<html>
<head>
<title>
Error
</title>
</head>
<body>
The parameter is incorrect.
</body>
</html>
</html>
Here is the the reponse from the USPS server after pasting it directly
to the address bar:
<?xml version="1.0" ?>
- <RateV2Response>
- <Package ID="0">
<ZipOrigination>10022</ZipOrigination>
<ZipDestination>20008</ZipDestination>
<Pounds>10</Pounds>
<Ounces>5</Ounces>
<Container>Flat Rate Box</Container>
<Size>REGULAR</Size>
<Zone>3</Zone>
- <Postage>
<MailService>Priority Mail Flat Rate Box (11.25" x 8.75" x
6")</MailService>
<Rate>7.70</Rate>
</Postage>
- <Postage>
<MailService>Priority Mail Flat Rate Box (14" x 12" x
3.5")</MailService>
<Rate>7.70</Rate>
</Postage>
</Package>
</RateV2Response>
Am I overlooking something in the way I'm calling it from Miva?
Thanks
Can't tell how much of that is just a wrapping thing, or cut and
paste, but here's a couple quick thoughts:
You should encodeattribute() whatever you assign to XML. I also see
some '?' marks in the variable name, but I'll assume those aren't in
the actual code. Might pay to build XML up slowly, instead of one big
assign statement, easier to work with.
> <MvCall
> action="&[cstring];"
> method="post">
> <MvEVAL EXPR="{callvalue}">
> </MvCall>
Wow, a macro! Does this mean that Mr. Moon is coming back? ;)
You should upgrade that empressa, if nothing else, you should do
encodeentities() on cstring.
--
Bill Guindon (aka aGorilla)
The best answer to most questions is "it depends".
Odd. Well, you do have spaces in there, and you're not replacing them
with %20, maybe that's the problem?
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
The most important consideration I came across was with the quote marks
in the xml string. Here's a portion from a shipping module that gets
the rates from USPS:
<MvASSIGN NAME = "XML" VALUE = "{'<IntlRateRequest
USERID=\"111VIKIN222\" PASSWORD=\"123456789\"><Package ID="0">...
Note that the quote marks for userid and password have been escaped but
other values aren't. You might want to try that.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=
On 4/13/06, J-vibe <housemu...@yahoo.com> wrote:
>
> Thanks to all, I was able to solve this issue.
>
>
> >
>
<MvAssign name="l.order_export" value="{'API=RateV2&XML=<RateV2Request
USERID=' $ asciichar(34) $ 'XXXXXXXXXXXX' $ asciichar(34) $ '><Package
ID=' $ asciichar(34) $ '0' $ asciichar(34) $
'><Service>PRIORITY</Service><ZipOrigination>10022</ZipOrigination><ZipDestination>20008</ZipDestination><Pounds>10</Pounds><Ounces>5</Ounces><Container>Flat
Rate Box</Container><Size>REGULAR</Size></Package></RateV2Request>'}">
<MvAssign name="ncount" value="1">
<MvCALL ACTION = "http://testing.shippingapis.com/ShippingAPITest.dll"
METHOD = "XML"
FIELDS = "l.order_export">
<MvAssign name="l.tokens" index="{ncount}" value="{callvalue}">
<MvAssign name="ncount" value="{ncount + 1}">
<MvEval expr="{callvalue}">
</MvCall>
The array holds the following information which is sent back by the
USPS server, so using a simple loop,
you could find and assign the value to a variable.
<?xml version="1.0" ?>
<RateV2Response>
<Package ID="0">
<ZipOrigination>
10022
</ZipOrigination>
<ZipDestination>
20008
</ZipDestination>
<Pounds>
10
</Pounds>
<Ounces>
5
</Ounces>
<Container>
Flat Rate Box
</Container>
<Size>
REGULAR
</Size>
<Zone>
3
</Zone>
<Postage>
<MailService>
Priority Mail Flat Rate Box (11.25" x 8.75" x 6")
</MailService>
<Rate>
7.70
</Rate>
</Postage>
</Package>
</RateV2Response>