FindMeetingTimes with TimeConstraint returns ErrorInternalServerError - microsoft-graph-api

Using Graph API I am positing a request similar to below.
For some reason, when I include the TimeConstraint I get a null pointer. If I don't include the TimeConstraint node, request is returned successfully.
To me, my TimeConstraint section looks OK. Is there anything wrong or that I'm missing?
Exception:
{
"error": {
"code": "ErrorInternalServerError",
"message": "Object reference not set to an instance of an object.",
"innerError": {
"request-id": "905b8b0f-5de2-4559-861d-4244aa25da7c",
"date": "2017-11-21T13:48:32"
}
}
}
Request:
{
"Attendees":[
{
"type":"required",
"emailAddress":{
"address":"user1#tenant.com"
}
},
{
"type":"required",
"emailAddress":{
"address":"user2#tenant.com"
}
},
{
"type":"required",
"emailAddress":{
"address":"user3#tenant.com"
}
}
],
"LocationConstraint":{
"locations":[
{
"resolveAvailability":true,
"locationEmailAddress":"room#tenant.com"
}
]
},
"TimeConstraint":{
"activityDomain":"work",
"timeslots":[
{
"start":{
"dateTime":"2017-11-26T09:00:00",
"timeZone":"Pacific Standard Time"
}
},
{
"end":{
"dateTime":"2017-11-26T17:00:00",
"timeZone":"Pacific Standard Time"
}
}
]
},
"MeetingDuration":"PT1H",
"MaxCandidates":99,
"IsOrganizerOptional":false,
"ReturnSuggestionReasons":true,
"MinimumAttendeePercentage":100.0
}

Your startandend` properties are scoped one level too far. These are properties of the same object:
Try this instead:
"timeslots": [{
"start": {
"dateTime": "2017-11-23T16:58:07.973Z",
"timeZone": "Eastern Standard Time"
},
"end": {
"dateTime": "2017-11-30T16:58:07.973Z",
"timeZone": "Eastern Standard Time"
}
}]
When using the Microsoft Graph .NET Client SDK:
// Create TimeConstraint
TimeConstraint timeConstraint = new TimeConstraint();
timeConstraint.ActivityDomain = ActivityDomain.Unrestricted;
// Create a TimeSlot
TimeSlot timeSlot = new TimeSlot();
timeSlot.Start.DateTime = "2017-11-23T16:58:07.973Z";
timeSlot.Start.TimeZone = "Eastern Standard Time";
timeSlot.End.DateTime = "2017-11-30T16:58:07.973Z";
timeSlot.End.TimeZone = "Eastern Standard Time";
// Create a TimeSlot collection and add the TimeSlot
List<TimeSlot> timeSlots = new List<TimeSlot>();
timeSlots.Add(timeSlot);
// Assign the TimeSlot collection to the TimeContraint
timeConstraint.Timeslots = timeSlots;

Related

Create calendar event using ruby outlook

I am trying create a event in calendar,
Iam able get all the data like calendar,contacts and emails by following below documentaion,
https://learn.microsoft.com/en-us/outlook/rest/ruby-tutorial,
But when try to create a event using ruby_outlook getting below error
{"ruby_outlook_error"=>401,
"ruby_outlook_response"=>{"error"=>{"code"=>"InvalidAudience", "message"=>"The audience claim value is invalid 'aud'.",
"innerError"=>{"requestId"=>"75984820-5241-11ea-b6fc-fc4dd44c1550", "date"=>"2020-02-18T11:26:08"}}}}
Below code is for creating event
def def index
token = get_access_token //getting access token
if token
outlook_client = RubyOutlook::Client.new
event_payload =
{
"Subject": "Discuss the Calendar REST API",
"Body": {
"ContentType": "HTML",
"Content": "I think it will meet our requirements!"
},
"Start": {
"DateTime": "2020-03-03T18:00:00",
"TimeZone": "Pacific Standard Time"
},
"End": {
"DateTime": "2020-03-03T19:00:00",
"TimeZone": "Pacific Standard Time"
},
"Attendees": [
{
"EmailAddress": {
"Address": "john#example.com",
"Name": "John Doe"
},
"Type": "Required"
}
]
}
outlook_client.create_event(token, event_payload, nil, 'user#domain.com')
end
end
Your issue is that the token that you fetched was using the Microsoft graph API but now you are trying to create an even through the Outlook API. You cannot use a token issued for Graph ("aud": "graph.microsoft.com") against the Outlook endpoint. You need a token with "aud": "outlook.office.com".Better is use the graph API itself using the graph gem to create an event since you already have the token fetched from it.
To do that first create the MicrosoftGraph object
def create_service_auth
access_token = get_access_token
callback = Proc.new do |r|
r.headers['Authorization'] = "Bearer #{access_token}"
r.headers['Content-Type'] = 'application/json'
r.headers['X-AnchorMailbox'] = "#{ email_of_calendar_for_which_to_create_the_event }"
end
#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)
end
Then create the event -
def create_event
event = {
subject: summary,
body: {
content_type: "HTML",
content: description
},
start: {
date_time: start_time,
time_zone: timezone
},
end: {
date_time: end_time,
time_zone: timezone
},
response_requested: true,
organizer: {emailAddress: { name: "#{organizer.full_name}", address: email_of_calendar_for_which_to_create_the_event }},
attendees: [
{
email_address: {
address: attendee_email,
name: "#{attendee.full_name}"
},
type: "required"
}
]
}
result = #graph.me.events.create(event)
end

CDK Stepfunction Fargate step that takes all json key

I wanted to create ECS task that takes all json as its environment input. But my cdk code won't deploy because of following error message, the error message is so vague and it is difficult for me to figure out why my code is wrong.
Failed to call Step Functions for request: 'com.amazonaws.services.stepfunctions.model.CreateStateMachineRequest'. (Service: null; Status Code: 500; Error Code: null; Request ID: null)
new StateMachine (/local/home/miae/Explanation/src/ForecastingDeepLearningExplanationInfrastructure/node_modules/#aws-cdk/aws-stepfunctions/lib/state-machine.ts:101:26)
My cdk code
...
const ecsFargateTask = new sfn.Task(this, 'myEcs', {
inputPath: "$",
resultPath: "$.ecs",
task: new class implements sfn.IStepFunctionsTask {
bind(): sfn.StepFunctionsTaskConfig {
return {
resourceArn: "arn:aws:states:::ecs:runTask.sync",
parameters: {
"LaunchType": "FARGATE",
"Cluster": props.cluster.clusterArn,
"TaskDefinition": taskDefinition.taskDefinitionArn,
"Overrides": {
"ContainerOverrides": [{
"Name": "myContainer",
"Environment.$": "$.envs"
}]
}
}
};
}
}
});
}
const chain = sfn.Chain.start(ecsFargateTask);
new sfn.StateMachine(this, `StateMachineCopy${props.stage}`, {
definition: chain,
timeout: cdk.Duration.seconds(3000)
});
This is the Step function I want, and I could manually create this without problem.
{
"StartAt": "ExplanationEcs",
"States": {
"ExplanationEcs": {
"End": true,
"InputPath": "$",
"Parameters": {
"LaunchType": "FARGATE",
"Cluster": "arn:aws:ecs:us-west-2:123456789:cluster/myCluster482E02CC-1VWQ5XRG4II88",
"TaskDefinition": "arn:aws:ecs:us-west-2:123456789:task-definition/myTaskDefinitionE3E6548C:3",
"Overrides": {
"ContainerOverrides": [
{
"Name": "myContainer",
"Environment.$": "$.envs"
}
]
}
},
"Type": "Task",
"Resource": "arn:aws:states:::ecs:runTask.sync",
"ResultPath": "$.ecs"
}
},
"TimeoutSeconds": 3000
}

'parseHasMany - Model type for relationship x not found' - How do I map nested JSON to models with Angular2-jsonapi

I am new to API's and Angular and I'm running into an issue I can't seem to resolve.
For a project I am currently working on I have set up a simple Rails API with the fast_jsonapi. This formats my JSON responses to be in line with JSON:API. I then have an Angular app which should take in that response and map it with the Angular2-jsonapi module.
For this issue imagine we have roles and accountabilities. One role can has 0 to many accountabilities. An accountability belongs to a single role.
When I sent a request to return all the roles, I get a JSON response which then gets properly mapped to models by the module. The issue arises when I try to include relationships.
According to the readme I have to define which relationship to include in the .findAll method like so:
{ include: 'accountabilities' }
The correct data is requested from the rails API, as it is the same request which I tested with Postman earlier. However the error that appears in my browser console is as follows:
{message: "parseHasMany - Model type for relationship accountability not found."}
I have tried other relationships and went through the setup proces a couple of times now, but I fail to see where things are going wrong. Searches on Google, Github and Stackoverflow haven't helped me in this case. Any help is very much appreciated.
Here is the relevant code. If any other information or code is needed, let me know and I'll happily update this post.
Example JSON response:
{
"data": [
{
"id": "1",
"type": "role",
"attributes": {
"name": "Farming Engineer",
"purpose": "Iure voluptatum rem dolores.",
"created_at": "2020-01-16T18:38:26.151Z",
"updated_at": "2020-01-16T18:38:26.151Z"
},
"relationships": {
"accountabilities": {
"data": [
{
"id": "6",
"type": "accountability"
},
{
"id": "12",
"type": "accountability"
}
]
}
}
},
{
"id": "2",
"type": "role",
"attributes": {
"name": "IT Supervisor",
"purpose": "Iusto fuga fugiat qui.",
"created_at": "2020-01-16T18:38:26.161Z",
"updated_at": "2020-01-16T18:38:26.161Z"
},
"relationships": {
"accountabilities": {
"data": []
}
}
}
],
"included": [
{
"id": "6",
"type": "accountability",
"attributes": {
"description": "penetrate the market",
"created_at": "2020-01-16T18:38:26.480Z",
"updated_at": "2020-01-16T18:38:26.480Z"
},
"relationships": {
"role": {
"data": {
"id": "1",
"type": "role"
}
}
}
},
{
"id": "12",
"type": "accountability",
"attributes": {
"description": "immersive experience",
"created_at": "2020-01-16T18:38:26.507Z",
"updated_at": "2020-01-16T18:38:26.507Z"
},
"relationships": {
"role": {
"data": {
"id": "1",
"type": "role"
}
}
}
}
]
}
role.model.ts
import {
JsonApiModelConfig,
JsonApiModel,
Attribute,
HasMany,
BelongsTo
} from 'angular2-jsonapi';
import { Accountability } from '#app/shared/models/accountability.model';
#JsonApiModelConfig({
type: 'roles'
})
export class Role extends JsonApiModel {
#Attribute()
name: string;
#Attribute()
purpose: string;
#Attribute({ serializedName: 'created_at' })
createdAt: Date;
#Attribute({ serializedName: 'updated_at' })
updatedAt: Date;
#HasMany()
accountabilities: Accountability[];
}
accountability.model.ts
import {
JsonApiModelConfig,
JsonApiModel,
Attribute,
BelongsTo
} from 'angular2-jsonapi';
import { Role } from '#app/shared/models/role.model';
#JsonApiModelConfig({
type: 'accountabilities'
})
export class Accountability extends JsonApiModel {
#Attribute()
description: string;
#Attribute({ serializedName: 'created_at' })
createdAt: Date;
#Attribute({ serializedName: 'updated_at' })
updatedAt: Date;
#BelongsTo()
role: Role;
}
datastore.ts
import { Injectable } from '#angular/core';
import { HttpClient } from '#angular/common/http';
import {
JsonApiDatastoreConfig,
JsonApiDatastore,
DatastoreConfig
} from 'angular2-jsonapi';
import { Role } from '#app/shared/models/role.model';
import { Accountability } from '#app/shared/models/accountability.model';
const config: DatastoreConfig = {
baseUrl: 'http://localhost:3000/api',
apiVersion: 'v1',
models: {
roles: Role,
accountabilities: Accountability
}
};
#Injectable()
#JsonApiDatastoreConfig(config)
export class Datastore extends JsonApiDatastore {
constructor(http: HttpClient) {
super(http);
}
}
role.component.ts
import { Component, OnInit } from '#angular/core';
import { Datastore } from '#app/datastore';
import { Role } from '#app/shared/models/role.model';
import { JsonApiQueryData } from "angular2-jsonapi";
#Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.sass']
})
export class HomeComponent implements OnInit {
roles: Role[];
constructor(private datastore: Datastore) { }
ngOnInit() {
this.datastore
.findAll(Role, { include: 'accountabilities' })
.subscribe((roles: JsonApiQueryData<Role>) => {
console.log('>>>>>>>>>>>>>', roles);
console.log('>>>>>>>>>>>>>', roles.getModels());
this.roles = roles.getModels();
});
}
}
With a lot of help over on this Github topic I finally managed to get this resolved.
What initially caused the issue is that the response that I got from my API listed the type in relationships and included in singular whereas they needed to be plural.
Adding record_type: :accountabilities to the has_many relationship in my serializer changed this and successfully mapped the response to objects.

Couchdb Reference Document

I'm new to CouchDB and struggling to implement a basic example. I have three documents Customer, Contact, Address and I want join them into a single document.
Account Document
{
"_id": "CST-1",
"_rev": "8-089da95f148b446bd3b33a3182de709f",
"name": "Customer",
"code": "CST-001",
"contact_Key": "CNT-001",
"address_Key": "ADD-001",
"type": "Customer"
}
Contact Document
{
"_id": "CNT-001",
"_rev": "8-079da95f148b446bd3b33a3182de709g",
"fullname": "Happy Swan",
"type": "Contact"
}
Address Document
{
"_id": "ADD-001",
"_rev": "8-179da95f148b446bd3b33a3182de709c",
"street1": "9 Glass View",
"street2": "Street 2",
"city": "USA",
"type": "Address"
}
Map/Query:
var map= function (doc) {
if (doc.type === 'Customer') {
emit(doc.id, { contact_Key: doc.contact_Key, address_Key: doc.address_Key })
}
};
db.query({ map: map }, { include_docs: true }, function (err, res) {
});
I want all 3 documents in a single document when I query account e.g.
Expected result
{
"_id": "CST-1",
"_rev": "8-089da95f148b446bd3b33a3182de709f",
"name": "Customer",
"code": "CST-001",
"contact_Key": "CNT-001",
"address_Key": "ADD-001",
"type": "Customer",
"Contact: {
"_id": "CNT-001",
"_rev": "8-079da95f148b446bd3b33a3182de709g",
"fullname": "Happy Swan",
"type": "Contact"
}",
"Address: {
"_id": "ADD-001",
"_rev": "8-179da95f148b446bd3b33a3182de709c",
"street1": "9 Glass View",
"street2": "Street 2",
"city": "USA",
"type": "Address"
}"
}
I don't see any better solution than querying the account document first and then querying the other two once you know their IDs. If you think about it, it makes sense because the only link between these documents is the IDs stored in the account document, so to get all three at the same time, internally the DB would have to do two queries: first the account document, then the other two. And by design CouchDB only does one query at a time.
If you had the account doc ID stored into the contact and address documents however, you could use a list function to merge them all into one.
First you would need a view:
function(doc) {
if (doc.type === 'Customer') {
emit(doc._id, doc);
}
if (doc.type === 'Contact' || doc.type === 'Address') {
emit(doc.account_id, doc);
}
}
Then a list function:
function(head, req) {
var row, account, contact, address;
while (row = getRow()) {
if (row.value.type === 'Customer') {
account = row.value;
} else if (row.value.type === 'Contact') {
contact = row.value;
} else if (row.value.type === 'Address') {
address = row.value;
}
}
account['Contact'] = contact;
account['Address'] = address;
provides("json", function() {
return { 'json': account };
});
}
And you would query it with:
GET /db/_design/foo/_list/the-list/the-view?key="CST-1"

Filter result based on a count of inner data

I am building my search query for some listing data. As part of the search people can ask for multiple rooms which sleeps a min amount of people, ie two rooms which sleep 2 and 3 people.
Im not sure how I can perform that with a filter.
Here is a shortened search query so far.
{
"query":{
"filtered":{
"query":{
"match_all":{}
}
}
},
"filter":{
"and":
[
{
"term":{
"status":"live"
}
},
{
"geo_bounding_box":{
"location":{
"top_left":"60.856553, -8.64935719999994",
"bottom_right":"49.8669688, 1.76270959999999"
}
}
}
,{
"range":{
"bedrooms":{
"gte":"2"
}
}
}
]
}
,
"size":10
}
Test Data
{
"took":1,
"timed_out":false,
"_shards":{
"total":5,
"successful":5,
"failed":0
},
"hits":{
"total":3,
"max_score":1.0,
"hits":[
{
"_index":"listings",
"_type":"listing",
"_id":"1",
"_score":1.0,
"_source":{
"name:":"Listing One",
"address1":"Some Street",
"bedrooms":2,
"city":"A City",
"id":1,
"refno":"FI451",
"user_id":1,
"rooms":[
{
"bathroom":"Shared bathroom with bath",
"double_standard":null,
"id":5,
"single":2,
"sleeps":2,
"title":"Twinny",
},
{
"bathroom":"Ensuite with bath",
"double_king_size":1,
"double_standard":1,
"id":1,
"single":null,
"sleeps":2,
"title":"Double Ensuite Room",
}
]
}
},
{
"_index":"listings",
"_type":"listing",
"_id":"2",
"_score":1.0,
"_source":{
"name":"Listing Two",
"address1":"Some Street",
"bedrooms":2,
"city":"A City",
"id":2,
"refno":"BL932",
"user_id":1,
"rooms":[
{
"bathroom":"Ensuite with bath",
"double_standard":1,
"id":4,
"single":1,
"sleeps":3,
"title":"Family Room",
},
{
"bathroom":"Ensuite with shower",
"double_standard":1,
"id":2,
"single":null,
"sleeps":2,
"title":"Single Room",
}
]
}
},
{
"_index":"listings",
"_type":"listing",
"_id":"3",
"_score":1.0,
"_source":{
"name":"Listing Three",
"address1":"Another Address",
"bedrooms":1,
"city":"Your City",
"id":3,
"refno":"TE2116",
"user_id":1,
"rooms":[
{
"bathroom":"Ensuite with shower",
"double_king_size":null,
"double_standard":1,
"id":3,
"single":1,
"sleeps":3,
"title":"Family Room",
}
]
}
}
]
}
}
If you look at my data I have 3 listings, two of them have multiple rooms (Listing One & Two) but only Listing Two would match my search, Reason it has one room with that sleeps two and the other sleeps three.
Is it possible to perform this query with elasticsearch?
If what you want is "Find all listings where a bedroom sleeps 2 AND another bedroom sleeps 3", this query will work. It makes one big assumptions: that you are using inner objects, and not the Nested data type.
This query is using the fact that inner objects are collapsed into a single field, causing "rooms.sleeps" to equal [2,3] for the desired field. Since the field is collapsed into a single array, a simple Terms query will match them. When you change the execution mode to And, it forces both 2 and 3 to be matched.
The caveat is that a room that has [2,3,4] will also be matched.
I've omitted the geo and status portion since that data wasn't provided in the source documents.
{
"query": {
"filtered": {
"query": {
"match_all": {}
}
}
},
"filter": {
"and": [
{
"range": {
"bedrooms": {
"gte": "2"
}
}
},
{
"terms": {
"rooms.sleeps": [2,3],
"execution": "and"
}
}
]
},
"size": 10
}
As far as I know the filter has to be a sibling of the query inside the filtered element. See: http://www.elasticsearch.org/guide/reference/query-dsl/filtered-query/
If you combine that with Zach's solution it should work.
{
"query":
{
"filtered":
{
"query":
{
"match_all":{}
},
"filter":
{
"put" : "your filter here"
}
}
}
}

Resources