BookmarkSubscribeRSS Feed
Jim_Cooper_hmsa
Obsidian | Level 7

I am trying to write a PROC HTTP program to validate Zip+4 for mailing addresses using PROC HTTP and the USPS API webtools.  I have a successful HTTP URL that I need to replicate with PROC HTTP.  The program creates an XML library to format the addresses for validation but I am getting an XML syntax error when run the PROC HTTP.  The URL I am trying to reproduce returns an XML response record without error.

 

http://production.shippingapis.com/ShippingAPI.dll?API=Verify

&XML=<AddressValidateRequest USERID="165THEQU4205"><Address ID="0"><Address1></Address1>

<Address2>6406 Ivy Lane</Address2><City>Greenbelt</City><State>MD</State>

<Zip5></Zip5><Zip4></Zip4></Address></AddressValidateRequest>

 

test program that returns an XML Error Response Message:

<?xml version="1.0" encoding="UTF-8"?>
<Error><Number>80040B19</Number><Description>XML Syntax Error: Please check the XML request to see if it can be parsed.</Description><Source>USPSCOM::DoAuth</Source></Error>

 

SAS code:

libname test xml "/sasuser.v94/AddressValidateRequest.xml";
filename in "/sasuser.v94/AddressValidateRequest.xml";
filename out "/sasuser.v94/AddressValidateResponse.xml";

data test.Address;
Revision=1; ID=1; Address1=''; Address2='6406 Ivy Lane'; City='Greenbelt';
State='MD';
run;

* Pass information to USPS API webtool for processing;
proc http
url="https://stg-secure.shippingapis.com/ShippingAPI.dll?API=AddressValidateRequest"
webusername="165THEQU4205"
webpassword="120RW00US168"
method="POST"
in=in
out=out;
run;

6 REPLIES 6
ChrisNZ
Tourmaline | Level 20
ChrisNZ
Tourmaline | Level 20

Oh sorry. You formatted your question badly.

 

The link is

http://production.shippingapis.com/ShippingAPI.dll?API=Verify&XML=<AddressValidateRequest USERID="165THEQU4205"><Address ID="0"><Address1></Address1><Address2>6406 Ivy Lane</Address2><City>Greenbelt</City><State>MD</State><Zip5></Zip5><Zip4></Zip4></Address></AddressValidateRequest>

 

There is no macro variable.

 

 

 

Jim_Cooper_hmsa
Obsidian | Level 7
Chris, Yes the question was formatted badly. Let me restate:

I am trying to create a process where I can send one or more addresses to the USPS API for validating addresses and correct the ZIP+4 codes using PROC HTTP. The purpose of this test is to take this HTTP request:


http://production.shippingapis.com/ShippingAPI.dll?API=Verify
&XML=

6406 Ivy LaneGreenbeltMD



and pass it from a PROC HTTP statement.
ChrisNZ
Tourmaline | Level 20

What happens if you use http instead of https?

What happens if you use method GET?

What happens if you use 

proc http url='http://production.shippingapis.com/ShippingAPI.dll?API=Verify&XML=<AddressValidateRequest USERID="165THEQU4205"><Address ID="0"><Address1></Address1><Address2>6406 Ivy Lane</Address2><City>Greenbelt</City><State>MD</State><Zip5></Zip5><Zip4></Zip4></Address></AddressValidateRequest>'  ?

 

 

Jim_Cooper_hmsa
Obsidian | Level 7

The site only accepts https: queries.

The API User manual recommends using POST as the request method

specifying the full URL in the PROC HTTP statement causes a SAS syntax error.  Also, this will not solve root problem since I would like to make the requests dynamic and, if possible, automated from a database query by using the in= clause.

ChrisNZ
Tourmaline | Level 20

> The site only accepts https: queries. The API User manual recommends using POST as the request method

Pasting

http://production.shippingapis.com/ShippingAPI.dll?API=Verify&XML=<AddressValidateRequest USERID="165THEQU4205"><Address ID="0"><Address1></Address1><Address2>6406 Ivy Lane</Address2><City>Greenbelt</City><State>MD</State><Zip5></Zip5><Zip4></Zip4></Address></AddressValidateRequest>

in a browser works, so maybe the constraints are not as hard as they seem.

 

> Also, this will not solve root problem since I would like to make the requests dynamic

You can still make the query dynamic, for example with a call execute.

 

I can't run proc http, so these were just ideas for you to test. Feel free to ignore 🙂

 

 

 

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 1586 views
  • 0 likes
  • 2 in conversation