Android / Microsoft Graph / Subscription validation
Back to Collection Items
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;
import android.app.Activity;
import com.chilkatsoft.*;
import android.widget.TextView;
import android.os.Bundle;
public class SimpleActivity extends Activity {
private static final String TAG = "Chilkat";
// Called when the activity is first created.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkHttp http = new CkHttp();
boolean success;
// Adds the "Authorization: Bearer <access_token>" header.
http.put_AuthToken("<access_token>");
CkHttpResponse resp = http.QuickRequest("POST","http://localhost:5000/api/notification?validationToken=something");
if (http.get_LastMethodSuccess() == false) {
Log.i(TAG, http.lastErrorText());
return;
}
Log.i(TAG, String.valueOf(resp.get_StatusCode()));
Log.i(TAG, resp.bodyStr());
}
static {
System.loadLibrary("chilkat");
// Note: If the incorrect library name is passed to System.loadLibrary,
// then you will see the following error message at application startup:
//"The application <your-application-name> has stopped unexpectedly. Please try again."
}
}
Curl Command
curl -X POST
-H "Authorization: Bearer <access_token>"
http://localhost:5000/api/notification?validationToken=something
Postman Collection Item JSON
{
"name": "Subscription validation",
"event": [
{
"listen": "test",
"script": {
"exec": [
"function decodeQueryParam(p) {\r",
" return decodeURIComponent(p.replace(/\\+/g, \" \"));\r",
"}\r",
"\r",
"pm.test(\"Status test\", function () {\r",
" pm.response.to.have.status(200);\r",
"});\r",
"pm.test(\"Content type test\", function () {\r",
" pm.response.to.have.header(\"Content-Type\");\r",
" pm.expect(pm.response.headers.get(\"Content-Type\")).to.include(\"text/plain\");\r",
"});\r",
"pm.test(\"Response body test\", function () {\r",
" pm.response.to.have.body(decodeQueryParam(pm.request.url.query.get(\"validationToken\")));\r",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [
],
"url": {
"raw": "http://localhost:5000/api/notification?validationToken=something",
"protocol": "http",
"host": [
"localhost"
],
"port": "5000",
"path": [
"api",
"notification"
],
"query": [
{
"key": "validationToken",
"value": "something",
"description": "random validation token passed by the Microsoft Graph when validating the notificationURL"
}
]
},
"description": "Allows you to validate whether the notification endpoint you are building properly passed Microsoft Graph Subscription creation validation.\nThe response content type should be text/plain, code 200 OK and the body the information passed by the validationToken query parameter"
},
"response": [
]
}