I am having some trouble working with the MicrosoftGraph Webhook. I think that I am not properly returning HTTP response, because when I put a binding.pry into my controller, after making the request it hits the controller.
However, the request seems to timeout before hitting my controller (see stack trace below). Here is my controller code and subscription request code, and stack trace. I really appreciate the help.
def self.create_subscription(user)
callback = Proc.new do |r|
r.headers['Authorization'] = "Bearer #{user.outlook_token.access_token}"
r.headers['Content-Type'] = 'application/json'
r.headers['X-AnchorMailbox'] = user.email
end
path = 'subscriptions'
data = {
changeType: "created, updated",
notificationUrl: "https://my_url/api/watch/outlookNotification",
resource: "me/mailFolders('Inbox')/messages",
expirationDateTime:"2017-08-19T06:23:45.9356913Z",
clientState: "subscription-identifier"
}
graph = MicrosoftGraph.new(base_url: 'https://graph.microsoft.com/v1.0',
cached_metadata_file: File.join(MicrosoftGraph::CACHED_METADATA_DIRECTORY, 'metadata_v1.0.xml'),
&callback)
response = graph.service.post(path, data.to_json)
end
def outlook_webhook
@token = params[:validationToken]
head 200, content_type: "text/plain", content_length: 7
response.body = @token
end
Completed 500 Internal Server Error in 14613ms (ActiveRecord: 478.4ms)
OData::ClientError (400 InvalidRequest: "Subscription validation request timed out." from "https://graph.microsoft.com/v1.0/subscriptions"):
app/models/outlook_wrapper.rb:44:increate_subscription'index'
app/controllers/business/messages_controller.rb:18:inRendered /Users/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/actionpack-4.2.4/lib/action_dispatch/middleware/templates/rescues/_source.erb (7.9ms) Rendered /Users/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/actionpack-4.2.4/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb (1.9ms) Rendered /Users/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/actionpack-4.2.4/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb (3.8ms) Rendered /Users/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/actionpack-4.2.4/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb (176.2ms)
Started POST "/api/watch/outlookNotification?validationToken=YTJhMTk5MDQtYjdmOC00ZjYxLWIzOGEtMDczM2FjMTAxZTBj" for 52.161.110.176 at 2017-08-23 12:29:05 -0400 Processing by InboundEmailsController#outlook_webhook as HTML Parameters: {"validationToken"=>"YTJhMTk5MDQtYjdmOC00ZjYxLWIzOGEtMDczM2FjMTAxZTBj"} Completed 200 OK in 35ms (ActiveRecord: 0.0ms)