2. Authentication process is done by bearer token: username in format of EMAIL where EMAIL - an email registered by UPS service team as a customer contact. This email must be activated by a self-registration process through https://www.ship.co.il/registration wizard
Need to call to:
| Methode | Post | |
| Header | Content-Type: application/x-www-form-urlencoded | |
| Content (Body) | username: | YOUR_USER_NAME |
| password: | YOUR_PASSWORD | |
| scope: | YOUR_CUSTOMER_ID | |
| grant_type: | password | |
From response need to save the "access_token" for all future requests until expiration date ("expires_in")
3. Examples
Response : {
"access_token": "zW19Z19Lg93DkIHYbz9U7Z2zjwjTKeUaplJ1Ae1OUUM9COT2UgpHHvAA-ET_PZ8yC3U5qcG8mMtjWNjay2yEnHBvjBzPapXsyMroQLe1Er6HSe- CWgwuQik8gq04LmtgfJbrVKWApPRRsJ1GGqeyZfHIrJ8VnVqKUjITFYy93zk1Q9eCQyNx0Dpby16p1k0eDA5Zo8T169ZTxrj4zS6azrp8haSaqK0KYLXYdwET-EPNZgW4YZ677nqMHTz0u5K8ijGD3eOQZhvNjljqYpjgh86zyxd6eqCKD79r4T4rrqc",
"token_type": "bearer",
"expires_in": 1209599,
"userName": "example@ups.co.il",
"customerNumber": "0000",
".issued": "Sun, 29 Apr 2018 09:54:53 GMT",
}
HttpClientHandler handler = new HttpClientHandler()
{
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate,
};
using (HttpClient client = new HttpClient(handler))
{
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
List> keys = new List>();
keys.Add(new KeyValuePair("username", userName));
keys.Add(new KeyValuePair("password", passWord));
keys.Add(new KeyValuePair("scope", scope));
keys.Add(new KeyValuePair("grant_type", "password"));
FormUrlEncodedContent content = new FormUrlEncodedContent(keys);
String url = ConfigurationManager.AppSettings["UPSShipAPI"] + "/Token";
var response = client.PostAsync(url, content);
String tokenJSON = response.Result.Content.ReadAsStringAsync().Result;
try
{
var data = (JObject)JsonConvert.DeserializeObject(tokenJSON);
token = data["access_token"].Value();
}
catch (Exception ex)
{
var error = ex.ToString();
}
}