PROCEDURE GetShipRate(tcState,tcZipCode,tnAmount)
lcKey = 'blablablabla' && You need your OWN API Key.
TEXT TO lcXML TEXTMERGE NOSHOW
<?xml version="2.1" encoding="utf-8" ?>
<Envelope>
<Header>
<AccountId><<lcKey>></AccountId>
</Header>
<Body>
<GetItemShipRateSS version="2.1">
<DetailLevel>1</DetailLevel>
<Currency>USD</Currency>
<DestinationAddress>
<ResidentialDelivery>true</ResidentialDelivery>
<CountryCode>US</CountryCode>
<PostalCode><<tcZipcode>></PostalCode>
<StateOrProvinceCode><<tcState>></StateOrProvinceCode >
</DestinationAddress>
<ItemList>
<Item>
<RefCode>TotalMobiel Shipping</RefCode>
<Quantity>1</Quantity>
<CalcMethod code="C">
<CarrierCalcProps>
<Weight>2</Weight>
<WeightUOM>LBS</WeightUOM>
<DeclaredValue><<TRANSFORM(tnAmount)>></DeclaredValue>
<PackMethod>T</PackMethod>
</CarrierCalcProps>
</CalcMethod>
</Item>
</ItemList>
</GetItemShipRateSS>
</Body>
</Envelope>
ENDTEXT
IF TYPE('loHTTP') <> 'O'
loHTTP = CREATEOBJECT("wwHTTP")
ENDIF
lcRateScript = "http://api.auctioninc.com/websvc/shire"
loHTTP.AddPostKey(lcXML)
lcHTML = loHTTP.HTTPGet(lcRateScript)
IF NOT EMPTY(loHttp.cErrorMsg)
oPortal.IEMessagebox('error: ' + loHttp.cerrorMsg)
RETURN ""
ENDIF
lcCursorShip = SYS(2015)
CREATE CURSOR (lcCursorShip) (ShipMethod c(6), ShipDesc C(50), ShipRate N(10,2), Active L)
FOR x = 1 TO OCCURS('<ServiceName>',lcHTML)
lcShipping = STREXTRACT(lcHTML,'<ServiceCode>','</ServiceCode>',x)
lcService = STREXTRACT(lcHTML,'<ServiceName>','</ServiceName>',x)
lcRate = STREXTRACT(lcHTML,'<Rate>','</Rate>',x)
SELECT (lcCursorShip)
APPEND BLANK
REPLACE ShipMethod WITH lcShipping,;
ShipDesc WITH lcService,;
ShipRate WITH VAL(lcRate),;
active WITH .t.
ENDFOR
RETURN (lcCursorShip)
EndProc
|