PDA

View Full Version : US Postal API


J-vibe
04-01-06, 06:37 AM
Hi,

I'm looking everywhere for answers or direction to solving this.
There are no examples anywhere of how to do this is Miva.

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. I've even tried safe URL encoding methods and it still fails. BUT, like I said...If I take
the so-called failed link and paste it from MVCall directly to the address bar....It Works..!?? MvCALL must adding something to the submission.

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><ZipDest**ination>20008</ZipDestination><Pounds>10</Pounds><Ounces>5</Ounces><Contai*n*er>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><Zi**pDestination>20008</ZipDestination><Pounds>10</Pounds><Ounces>5</Ounces><C*o*ntainer>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 correct reponse from the USPS server after pasting the translated cstring contents directly to the address bar, but fails with MvCall.


<?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?
I really don't want to switch to another language like PHP to do this request, but I'm starting to feel I have to.

Thanks in advance.

Bruce - PhosphorMedia
04-01-06, 06:41 AM
Try stuffing the entire output of your script into a variable and pushing through the Field parameter of MvCall. For example:

<MvCALL ACTION = "https://usps.com/etc"
METHOD = "XML"
FIELDS = "l.order_export">

(--thanks to Bill Guidon...no thanks to OrderWave's test environment.--)

J-vibe
04-01-06, 07:54 PM
I stuffed it as you suggested and got the proper response from the
server.

Thanks.

donb
05-17-06, 12:55 AM
From the text it appears that you were successfull at making the interface to usps work. I thought I had gotten it to work about a month ago but that must have just been a dream. Anyway I am trying again. What did you do to make it work? The following is code that I have been trying. Any suggestions?

Thanks

<mvassign name="URL" value="http://Production.ShippingAPIs.com/ShippingAPI.dll?API=ExpressMailLabel&XML=<ExpressMailLabelRequest USERID=\"&[uid]\" PASSWORD=\"&[pwd]\">">

<mvassign name="XMLcode" value="<Option/><EMCAAccount/><EMCAPassword/> <ImageParameters/> <FromFirstName></FromFirstName> <FromLastName></FromLastName> <FromFirm>XYZ Corporation</FromFirm> <FromAddress1></FromAddress1> <FromAddress2>1234 ETAILER DR.</FromAddress2> <FromCity>Los Angeles</FromCity> <FromState>CA</FromState> <FromZip5>90052</FromZip5> <FromZip4>1234</FromZip4> <FromPhone></FromPhone> <ToFirstName>LINDA</ToFirstName> <ToLastName>SHOPPER</ToLastName> <ToFirm/> <ToAddress1>APT. 3C</ToAddress1> <ToAddress2>100 MAIN ST.</ToAddress2> <ToCity>NEW YORK</ToCity> <ToState>NY</ToState> <ToZip5>10010</ToZip5> <ToZip4>1234</ToZip4> <ToPhone></ToPhone><WeightInOunces>37</WeightInOunces> <FlatRate></FlatRate> <StandardizeAddress>FALSE</StandardizeAddress><WaiverOfSignature>TRUE</WaiverOfSignature> <NoHoliday>TRUE</NoHoliday><NoWeekend>TRUE</NoWeekend> <SeparateReceiptPage>False</SeparateReceiptPage> <POZipCode>90210</POZipCode> <ImageType>GIF</ImageType><LabelDate></LabelDate> <CustomerRefNo></CustomerRefNo> <SenderName></SenderName> <SenderEMail></SenderEMail> <RecipientName></RecipientName> <RecipientEMail></RecipientEMail> </ExpressMailLabelRequest>">

<MvCALL ACTION="{URL}" METHOD="XML" FIELDS="XMLcode">

Vic - WolfPaw Computers
05-17-06, 01:03 AM
Do you have somewhere that you are trapping s.callvalue to process the results and returning data?

donb
05-17-06, 01:19 AM
The whole mvcall looks like this

<MvCALL ACTION="{URL}" METHOD="XML" FIELDS="XMLcode">
<MvEVAL EXPR="{callvalue}">
<MvIF EXPR="{len(callobjectelement) LT 1}">
<MvEVAL EXPR="{callobjecttye }">
</MvIF>
</MvCALL>


The results I get back are:
The parameter is incorrect.

I have tried various combinations but have been unsuccessful.

Thanks

aGorilla
05-17-06, 01:35 AM
From the text it appears that you were successfull at making the interface to usps work. I thought I had gotten it to work about a month ago but that must have just been a dream. Anyway I am trying again. What did you do to make it work? The following is code that I have been trying. Any suggestions?

It sounds like he did something like this:

<mvassign name="URL" value="http://Production.ShippingAPIs.com/ShippingAPI.dll?API=ExpressMailLabel">

<mvassign name="XMLcode" value="<ExpressMailLabelRequest USERID=\"&[uid]\" PASSWORD=\"&[pwd]\"><Option/><EMCAAccount/><EMCAPassword/> <ImageParameters/> <FromFirstName></FromFirstName> <FromLastName></FromLastName> <FromFirm>XYZ Corporation</FromFirm> <FromAddress1></FromAddress1> <FromAddress2>1234 ETAILER DR.</FromAddress2> <FromCity>Los Angeles</FromCity> <FromState>CA</FromState> <FromZip5>90052</FromZip5> <FromZip4>1234</FromZip4> <FromPhone></FromPhone> <ToFirstName>LINDA</ToFirstName> <ToLastName>SHOPPER</ToLastName> <ToFirm/> <ToAddress1>APT. 3C</ToAddress1> <ToAddress2>100 MAIN ST.</ToAddress2> <ToCity>NEW YORK</ToCity> <ToState>NY</ToState> <ToZip5>10010</ToZip5> <ToZip4>1234</ToZip4> <ToPhone></ToPhone><WeightInOunces>37</WeightInOunces> <FlatRate></FlatRate> <StandardizeAddress>FALSE</StandardizeAddress><WaiverOfSignature>TRUE</WaiverOfSignature> <NoHoliday>TRUE</NoHoliday><NoWeekend>TRUE</NoWeekend> <SeparateReceiptPage>False</SeparateReceiptPage> <POZipCode>90210</POZipCode> <ImageType>GIF</ImageType><LabelDate></LabelDate> <CustomerRefNo></CustomerRefNo> <SenderName></SenderName> <SenderEMail></SenderEMail> <RecipientName></RecipientName> <RecipientEMail></RecipientEMail> </ExpressMailLabelRequest>">

<MvCALL ACTION="{URL}" METHOD="XML" FIELDS="XMLcode">

donb
05-17-06, 02:14 AM
Actually that results in a different error "Not Implemented"

I have tried with the password as part of the url and stuffing the whole string into the url. Those all give the " The parameter is incorrect." error