Difference between revisions of "API Method PingWithAuth"

From Updox API
Jump to: navigation, search
m (Adds fields)
Line 3: Line 3:
 
== Fields ==
 
== Fields ==
 
There are no input fields for this method.
 
There are no input fields for this method.
 +
 +
== Code Samples ==
 +
{| class="wikitable" style="width:900px; vertical-align:top; align:left"
 +
! Language || Source Code Examples
 +
|-
 +
| width="50px"| C# || <div class="mw-collapsible mw-collapsed" style="width:65px">
 +
<div class="mw-collapsible-content" style="width:810px">
 +
</div>
 +
|-
 +
| align="top" | Java || <div class="mw-collapsible mw-collapsed" style="width:65px">
 +
<div class="mw-collapsible-content" style="width:810px">
 +
{{Talk To Updox - Core - Java|pingWithAuth|pingWithAuth}}
 +
 
 +
{{Json API HMAC Block- Java}}
 +
 
 +
{{Base_Code_for_Consuming_API_Using_Java}}
 +
|}
 +
  
 
== Sample Request and Response ==
 
== Sample Request and Response ==

Revision as of 15:52, 27 November 2013

Ping the server for a response with full authentication. This method verifies that applicationId and applicationPassword are valid and that there is a valid userId under a valid accountId.

Contents

Fields

There are no input fields for this method.

Code Samples

Language Source Code Examples
C#
Java


   public void TalkToUpdox() throws Exception {
       String uri = "https://updoxqa.com/io/pingWithAuth";
       ObjectMapper mapper = new ObjectMapper();
       Map<String,Object> messageData = BuildMessage();
       String jsonData = mapper.writeValueAsString(messageData);
       HttpResponse httpResponse = SendReceiveJSON(jsonData, uri);
       HttpEntity responseEntity = httpResponse.getEntity();
       String response = EntityUtils.toString(responseEntity);
       JsonNode actualObj = mapper.readTree(response);
 
       System.out.println(actualObj.get("responseCode"));
       System.out.println(actualObj.get("responseMessage"));
   }
 
   
   
   public static void generateHmacHeaders(HttpURLConnection connection, String applicationId, String applicationPassword, String accountId, String userId) throws Exception{
       final SimpleDateFormat d = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss (z)");
       d.setTimeZone(TimeZone.getTimeZone("GMT"));
       final String timestampString = d.format(new Date());
       final String message = 
          (applicationId == null ? "" : applicationId) + ":" + 
          (applicationPassword == null ? "" : applicationPassword) + ":" + 
          (accountId == null ? "" : accountId) + ":" + 
          (userId == null ? "" : userId) + ":" + 
          timestampString;
       final String auth = "HMAC " + hmacSha1ToBase64(message, apiSecret); //note space after HMAC
       connection.setRequestProperty("updox-timestamp", timestampString);  
       connection.setRequestProperty("Authorization", auth);
   }
   
   public static String hmacSha1ToBase64(String value, String key) throws Exception{
       byte[] keyBytes = key.getBytes();
       SecretKeySpec signingKey = new SecretKeySpec(keyBytes, "HmacSHA1");
       Mac mac = Mac.getInstance("HmacSHA1");
       mac.init(signingKey);
       byte[] rawHmac = mac.doFinal(value.getBytes());
       byte[] base64Bytes = Base64.encodeBase64(rawHmac);
       return new String(base64Bytes, "UTF-8");
   }
 
   private HttpResponse SendReceiveJSON(String jsonData, String uri) throws Exception {
       HttpClient httpClient = new DefaultHttpClient();
       HttpResponse response = null;
       StringEntity params = new StringEntity(jsonData);
       try {
           HttpPost request = new HttpPost(uri);
           request.addHeader("content-type", "application/json");
           request.setEntity(params);
           response = httpClient.execute(request);
       } catch (Exception ex) {
           // handle exception here
       } finally {
           httpClient.getConnectionManager().shutdown();
       }
       return response;
   }


Sample Request and Response

Request

{
    "auth": {
        "applicationId": "updox",
        "applicationPassword": "1234567890",
        "accountId": "account",
        "userId": "user"
    }
}

Response

{
    "successful": true,
    "responseMessage": "OK",
    "responseCode": 2000
}

Error Codes

This API method will only return the General Error Set.