Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UPS Tracking API - JSON body format?

Tags:

ups

According to the latest release of the UPS developer kit documentation "Tracking Web Services Developers Guide - January 04, 2016" the tracking API can be accessed via REST / JSON. However, there is very little information within their PDF documentation about the JSON side of things both in the PDF and on the interwebs. I can't figure out for the life of me the correct body to pass and each time I get a "The request is not well-formed or the operation is not defined. Review for errors before re-submitting." error back. There is years worth of info on the XML / SOAP side of things, but I'd love to use JSON on this particular project. Anyone have any experience with this new feature of their API and what the JSON body should look like? The JSON validates properly, but obviously isn't what UPS is looking for.

{
	"UPSSecurity": {
		"UsernameToken": {
			"Username": " userHere",
			"Password": " passHere"
		}
	},
	"ServiceAccessToken": {
		"AccessLicenseNumber": "licNoHere"
	},
	"Request": {
		"RequestOption": "15"
	},
	"InquiryNumber": "1Z12345E0291980793",
	"TrackingOption": "02"
}
like image 274
Dan Avatar asked Feb 26 '16 21:02

Dan


Video Answer


2 Answers

Posting the answer to my own question answered by UPS support.

You'll POST the following json as the body content to the following API endpoint:

https://onlinetools.ups.com/json/Track

{
  "Security": {
    "UsernameToken": {
      "Username": "ups_username_here",
      "Password": "ups_password_here"
    },
    "UPSServiceAccessToken": {
      "AccessLicenseNumber": "ups_access_license_number_here"
    }
  },
  "TrackRequest": {
    "Request": {
      "RequestAction": "Track",
      "RequestOption": "activity"
    },
    "InquiryNumber": "1Z202Y36A898759591"
  }
}
like image 173
Dan Avatar answered Sep 21 '22 06:09

Dan


On https://www.ups.com/track/api/Track/GetStatus you can post a json like

{
  "Locale": "da_DK",
  "TrackingNumber": ["enter your number here" ]
}

and you'll get a nice json structure back showing the current and previous location of the parcel

If you post multiple trackingnumbers, you only gets the summary for each parcel.

like image 35
Leif Neland Avatar answered Sep 19 '22 06:09

Leif Neland