Cannot get a single calendar event - microsoft-graph-api

I'm having trouble reading a single calendar event, calling:
Api::get('me/calendar/'.$id);
(API:: is a wrapper for Guzzle)
returns the errors:
The specified object was not found in the store.
I know it's a valid id as I've listed my calendar events:
$records = Api::get("me/calendarview?startdatetime=$start&enddatetime=$end&\$top=1000");
foreach ($records['value'] as $row) {
$events[] = array(
'id' => $row['id'],
'title' => $row['subject'],
'start' => date("Y-m-d H:i:s", strtotime($row['start']['dateTime'])),
'end' => date("Y-m-d H:i:s", strtotime($row['end']['dateTime'])),
'allDay' => $row['isAllDay'],
);
}
return $events;
The output contains the id:
{
"id": "AAMkADdlZTBjNjQ4LWI0OGItNDFhZS05ZDNiLThiY2JkYzIzZWZkYwBGAAAAAABFX7lJCx7ZRLTJ6iI0yZK6BwC8b_tAO4nLRZCbkhud5CXFAAAAAAEOAAC8b_tAO4nLRZCbkhud5CXFAAMc9p8aAAA=",
"title": "TOP - DC/JB - FEO",
"start": "2017-11-27 15:00:00",
"end": "2017-11-27 16:30:00",
"allDay": false
}
I've then used that id and attempted to return a single entry, the same happens when I use the Graph Explorer so I'm wondering if there is a bug or the documentation is incorrect.

The endpoint for fetching a single calendar entry is /me/events/{id}, not /me/calendar/{id}:
Api::get('me/events/'.$id);
The /calendar endpoint returns a Calendar resource whereas you're looking for an Event resource (a child object of the Calendar)

Related

Microsoft Graph API and events start and end dates

I am working with the Graph API and trying to create events using the C# Microsoft.Graph API. Let's assume to have the following Microsoft.Graph.Event objects:
{
Subject = "A Title",
Body = new ItemBody(),
Start = {
DateTime = "2022-10-24T00:00:00",
TimeZone = "W. Europe Standard Time"
},
End ={
DateTime = "2022-10-25T00:00:00",
TimeZone = "W. Europe Standard Time"
},
IsAllDay = true,
},{
Subject = "B Title",
Body = new ItemBody(),
Start = new DateTimeTimeZone {
DateTime = "2022-10-28T13:30:00",
TimeZone = "W. Europe Standard Time"
},
End = new DateTimeTimeZone {
DateTime = "2022-10-28T16:45:00",
TimeZone = "W. Europe Standard Time"
},
IsAllDay = false,
}
They are successfully written into my calendar trough twice call to:
await _graphServiceClient.Users[emailAddress].Events.Request().AddAsync(graphEvent);
and I see:
and
which is the expected behaviour.
Querying the API with the filter "start/dateTime ge '2022-10-24T00:00:00'" I get just B Title, A Title is missing. Furthermore the start and end dates are wrong, I get 2022-10-28T11:30:00.0000000 and 2022-10-28T14:45:00.0000000.
If I edit the query to "start/dateTime ge '2022-10-23T00:00:00'" I get both, the dates of B title are the same (wrong), but the ones of A Title ar correct 2022-10-24T00:00:00.0000000 and 2022-10-25T00:00:00.0000000.
I expected that B Title has 2022-10-28T13:30:00.0000000 and 2022-10-28T16:45:00.0000000. What am I doing wrong?
When you call list events endpoint you can specify request header Prefer: outlook.timezone="<time-zone>". If not specified, those time values are returned in UTC.
Example:
var events = await _graphServiceClient.Users[emailAddress]
.Events
.Request()
.Header("Prefer","outlook.timezone=\"W. Europe Standard Time\"")
.GetAsync();
I guess that with the correct outlook.timezone header your query will return also A Title and correct time values.
References:
Calendar list events - request headers

Symfony form not working properly if a field is empty or not exists

To edit the entity training, I use the TrainingFormType like this:
public function editTraining(Training $training) {
$form = $this->createForm(TrainingFormType::class, $training);
$form->submit($request->request->all());
The form has a field title:
->add('title', TextType::class, [
'constraints' => [
new NotBlank(),
new Length(null, null, 50)
]])
If I pass in the request an empty value into the field title "title" : "", I get an error 500:
"Expected argument of type "string", "null" given at property path "title".". I expected here an error from the form, not the InvalidArgumentException
When using the same form for creating of a new training, everything works fine, a validation error is generated, as expected:
"title": {
"errors": [
"This value should not be blank."
]
},
It's how I use the form when creating a new training:
$training = new Training();
$form = $this->createForm(TrainingFormType::class, $training);
$form->submit($request->request->all());
How to solve this problem? I thought, I can resolve it using an so called IgnoreNonSubmittedFieldListener, but on this way it also doesn't work. I get the same error.
One possible solution is to set a sensible default in the Training entity for that field:
// in Training.php
// ORM mapping omitted:
private string _title = '';
Then when a new entity is created it will have that value.

Is there a way to filter using count of a nested array item when using OData Query?

I am using Microsoft Graph List CalendarView to get calendar events from outlook. I would like to filter out items where count of attendees is 0. (Logically meaning time blocked for self).
I understand there is a $count parameter that will return the count of items. However, in the List CalendarView response i am not after the count of calendar items, but rather the count of attendees within each calendar item. And infact to use a not equal (ne) filter based on it.
{
"value": [
{
"originalStartTimeZone": "originalStartTimeZone-value",
"originalEndTimeZone": "originalEndTimeZone-value",
"iCalUId": "iCalUId-value",
"reminderMinutesBeforeStart": 99,
"isReminderOn": true,
"attendees":[
{
"type":"required",
"status":{
"response":"none",
"time":"0001-01-01T00:00:00Z"
},
"emailAddress":{
"name":"Samantha Booth",
"address":"samanthab#a830edad905084922E17020313.onmicrosoft.com"
}
},
{
"type":"required",
"status":{
"response":"none",
"time":"0001-01-01T00:00:00Z"
},
"emailAddress":{
"name":"Dana Swope",
"address":"danas#a830edad905084922E17020313.onmicrosoft.com"
}
}
]
}
]
}
I want to specifically filter out any event items where the array size of "attendees" is 0.
Is this feasible using OData query params?
It appears filtering against attendees property is not supported, see for example, this thread for a details. But the following approach could be considered:
a) introduce an extended property for event resource which will expose summary info (flag whether event contains attendees or the count of attendees) about attendees.
Update all the existing events:
PATCH https://graph.microsoft.com/v1.0/me/events/{event-id}
Content-Type: application/json
{
"singleValueExtendedProperties": [
{
"id":"String {66f5a359-4659-4830-9070-00047ec6ac6e} Name ContainsAttendes",
"value":"1"
}
]
}
b) now events could be filtered like this:
https://graph.microsoft.com/beta/me/events?$filter=singleValueExtendedProperties/Any(ep: ep/id eq 'String {66f5a359-4659-4830-9070-00047ec6ac6e} Name ContainsAttendes' and ep/value eq '1')
where it is assumed ContainsAttendes=1 corresponds to events which have one or more attendees

Unable to set dynamic dropdown value in Zapier CLI trigger

I have my app in Zapier CLI. I have created a trigger to set dropdown values for a particular action step during zap creation.
The data comes like this :
{ "data": {
"account_status": {
"field_name": "account_status",
"field_label": "Status",
"field_type": "list",
"field_length": "50",
"field_items": "Active|Inactive|444|Closed",
"required": "0",
"related_module": "",
"related_field_name": "",
"join_table": "",
"join_lhs_field_name": "",
"join_rhs_field_name": "",
"related_data_field": ""
},
}
}
Here is my code:
Now I am trying to set the data for the dynamic dropdown using field_items value from the above result like this:
return responsePromise
.then(response => JSON.parse(response.content ) )
.then(data => {
const account_status_list = data.data.account_status.field_items;
const account_status_arr = account_status_list.split("|");
return account_status_arr.map(function(e){
e.id = e
return e
})
})
my input field for the dynamic dropdown trigger is:
{
key: 'account_status',
label:'Account Status',
required: false,
dynamic: 'account_status.account_dropdown.id'
}
On clicking the dropdown I get this error
Can anyone suggest where I am going wrong or what may I do to resolve this ?
David here, from the Zapier Platform team.
The issue is that Zapier expects an array of objects and you're returning an array of strings. It seems like you're trying to make an id field in your code snippet, but calling "Active".id = "Active" won't make an object.
Instead, you should change your map function to be something like the following:
return account_status_arr.map(function(e){
return {id: e}
})
The other thing you'll probably need to tweak is how your dynamic dropdown is set up. It's a period-separated string that follows the format trigger_key.id_key.label_key. The id and label can be the same key; it really depends on what data you need to send to the API (the label is just for show, the id is what's actually sent). In the dynamic field, you'll have a dyanmic property that'll be account_status.id.id.
There are docs here.

Adding new Mantis status but ran out of enumeration values

I was wondering if you had any thoughts about this issue: We want to add one more status at a specific 'place' between two statuses, but we ran out of enumeration for it.
The enumeration looks like this:
$s_status_enum_string = "10:new,20:feedback,40:confirmed,50:assigned,52:in progress,53:code review pending,54:merge pending, 56:merged, 58:resolved, 60:testing, 70:tested, 90:closed, 91:updating test documentation";
And I want to add a new status between 52 and 53 so that, on the pull-down menu for status, they appear in the desired order.
I tried different things - including changing the .php file definitions then updating the MySQL table's status field in mantis_bug_table, but it messes up all the views and filters.
Any ideas?
The following steps might help you:
Redefine the enumeration string as per your requirements
Prepare a traceability with your current enumeration values
Update the status field in bugs table with the new values
Add the enumeration in config.php
You may have to reset your previous filters. The filter criteria is stored as a serialized string and it's very difficult to modify.
If anyone is having issues with this you need to change the following:
In config_inc.php modify $g_status_enum_string to ennumerate the new statuses as you see fit.
In custom_constants_inc.php make sure to do the same as above.
In the database, run SQL commands such as this:
UPDATE mantisclone.mantis_bug_table SET status=100 WHERE status=10;
to change the actual records for existing status IDs to new ones.
In custom_strings_inc.php modify $s_status_enum_string and input your new statuses. For example one of mine was:
$s_sanity_test_bug_title = "Set Issue Sanity Test";
$s_sanity_test_bug_button = "Issue Sanity Test Pending";
$s_email_notification_title_for_sanity_test = "The following issue is NOW SANITY TEST PENDING";
Finally you'll need a small script to change the existing ennumerated values in mantis_filters_table. This was mine, alter it as you see fit:
<?php
$mantisDB="myMantisDatabaseName";
mysql_connect("localhost", "XXXX", "YYYY") or die("Could not connect: " . mysql_error());
mysql_select_db($mantisDB);
$result = mysql_query("SELECT id, filter_string FROM $mantisDB.mantis_filters_table");
function parseRecord($statusArray)
{
$newStatus = array( "10" => "100",
"20" => "200",
"50" => "300",
"52" => "400",
"53" => "500",
"54" => "540",
"56" => "560",
"58" => "580",
"60" => "600",
"70" => "700",
"75" => "450",
"90" => "900",
"91" => "910"
);
foreach ($statusArray as $key=>$value)
{
if(array_key_exists($value, $newStatus))
{
echo "Found value $value, replacing it with " . $newStatus[$value] . "\n";
$statusArray[$key] = (int)$newStatus[$value];
}
}
}
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$statusID = $row["id"];
$serializedString = $row["filter_string"];
$unserializedArray = unserialize(substr($serializedString,3)); // There's a prepended 'v8#' string in there, don't know why.
parseRecord(&$unserializedArray["hide_status"]);
parseRecord(&$unserializedArray["show_status"]);
$newSerialized = "v8#".serialize($unserializedArray);
// echo $newSerialized;
$changeStatus = mysql_query("UPDATE $mantisDB.mantis_filters_table SET filter_string='$newSerialized' WHERE id=$statusID");
}
mysql_free_result($result);
?>
I hope this works, let me know if you're having any issues.

Resources