Marketing
Advertisement
  • Home
  • News
  • B2B
  • B2C
  • Marketing Automation
  • Market Research
  • Contact
No Result
View All Result
  • Home
  • News
  • B2B
  • B2C
  • Marketing Automation
  • Market Research
  • Contact
No Result
View All Result
Marketing News Hubb
No Result
View All Result

UPS API Endpoints and Sample PHP Test Code

April 13, 2022
Home Marketing Automation


We’re working with a WooCommerce client right now whose UPS shipping address validation and shipping cost calculations stopped working. The first issue we identified was the UPS shipping plugin they had was outdated and the core domain for the company that developed it had malware… that’s never a good sign. So, we purchased the WooCommerce UPS plugin since it’s well-supported by the developers of Woocommerce.

With the site not validating addresses nor integrating shipping, our first step was to verify that the UPS application programming interface (API) was up and operational. UPS does have a nice site for checking the status of its API.

Since the API didn’t appear to be done, our next step was to debug the issue locally. Interestingly enough, neither plugin had any logging nor testing to see if the UPS shipping integration actually worked. Even the debug setting didn’t provide any feedback, nor did our log files. So, in order to test the API, I had to program a script to actually test the API.

I downloaded the UPS API Developer Kit… which included code samples… and was confused as ever. The documentation is limited, the endpoints for the API weren’t even listed, and the code samples aren’t well-documented.

Download The UPS API Developer Kit

As a result, I had to do some digging… the first was to identify endpoints for their API. I found documented testing endpoints, wrote my code, and tested it… with no success. A little more digging and I found out that the testing endpoints were basically useless. Ugh.

UPS API Endpoints

I was able to find a thread on a development site that listed the UPS API production endpoints:

  • https://onlinetools.ups.com/ups.app/xml/TimeInTransit
  • https://onlinetools.ups.com/ups.app/xml/License
  • https://onlinetools.ups.com/ups.app/xml/QVEvents
  • https://onlinetools.ups.com/ups.app/xml/Register
  • https://onlinetools.ups.com/ups.app/xml/AV
  • https://onlinetools.ups.com/ups.app/xml/ShipAccept
  • https://onlinetools.ups.com/ups.app/xml/Void
  • https://onlinetools.ups.com/ups.app/xml/XAV
  • https://onlinetools.ups.com/ups.app/xml/Track
  • https://onlinetools.ups.com/ups.app/xml/Rate
  • https://onlinetools.ups.com/ups.app/xml/ShipConfirm
  • https://onlinetools.ups.com/ups.app/xml/LabelRecovery

The easiest one to test is the Address Validation (bold above) endpoint so I used the code provided to write a small PHP script that passed the address and responded with whether or not it was successful or failing. Here’s the code in the event you’d like to use it:

UPS API PHP Test File for Address Validation

Here’s the updated PHP script for testing the Address Validation UPS API Endpoint:


UPS Address Validation Test
Response: " );
	$accessRequestXML->addChild ( "AccessLicenseNumber", $accessLicenseNumber );
	$accessRequestXML->addChild ( "UserId", $userId );
	$accessRequestXML->addChild ( "Password", $password );
	
	// Create AddressValidationRequest XMl
	$avRequestXML = new SimpleXMLElement ( "" );
	$request = $avRequestXML->addChild ( 'Request' );
	$request->addChild ( "RequestAction", "AV" );
	
	$address = $avRequestXML->addChild ( 'Address' );
	$address->addChild ( "City", "ALPHARETTA" );
	$address->addChild ( "PostalCode", "300053778" );
	$requestXML = $accessRequestXML->asXML () . $avRequestXML->asXML ();
	
	$form = array (
			'http' => array (
					'method' => 'POST',
					'header' => 'Content-type: application/x-www-form-urlencoded',
					'content' => "$requestXML" 
			) 
	);
	
	// get request
	$request = stream_context_create ( $form );
	$browser = fopen ( $endpointurl, 'rb', false, $request );
	if (! $browser) {
		throw new Exception ( "Connection failed." );
	}
	
	// get response
	$response = stream_get_contents ( $browser );
	fclose ( $browser );
	
	if ($response == false) {
		throw new Exception ( "Bad data." );
	} else {
		
		// get response status
		$resp = new SimpleXMLElement ( $response );
		echo $resp->Response->ResponseStatusDescription . "n";
	}
	
} catch ( Exception $ex ) {
	echo $ex;
}

?>

This script will at least show you whether or not you’re credentials are working with the UPS API Address Validation endpoint. I realize the PHP methodology (fopen) to post to their API is a bit aged in this example above… but I just wanted to get their test code working.

Disclosure: I am using my WooCommerce affiliate links in this article.



Source link

Next Post
6 Of The Best Marketing Campaigns You Need To See In 2022

6 Of The Best Marketing Campaigns You Need To See In 2022

Recommended.

Enable @ NDC London 2019

Enable @ NDC London 2019

April 21, 2022

9 Essential Social Media Manager Skills You Should Have

May 9, 2022

Trending.

What Is Lead Generation in SEO?

April 19, 2022
15 Ways to Improve Your SEO Outreach Strategy

15 Ways to Improve Your SEO Outreach Strategy

April 22, 2022
Wishpond Launches New Website Builder [FEATURE RELEASE]

Wishpond Launches New Website Builder [FEATURE RELEASE]

April 22, 2022
How to Get More Clicks on Your Pinterest Pins

How to Get More Clicks on Your Pinterest Pins

April 27, 2022
2022 B2B Marketing Trends | Launch Marketing 

2022 B2B Marketing Trends | Launch Marketing 

April 28, 2022

© 2022 Marketing News Hubb All rights reserved.

Use of these names, logos, and brands does not imply endorsement unless specified. By using this site, you agree to the Privacy Policy.

Navigate Site

  • Home
  • News
  • B2B
  • B2C
  • Marketing Automation
  • Market Research
  • Contact

Newsletter Sign Up.

No Result
View All Result
  • Home
  • News
  • B2B
  • B2C
  • Marketing Automation
  • Market Research
  • Contact

© 2022 Marketing News Hubb All rights reserved.