How to check an Outlook custom property is available via Microsoft Graph - microsoft-graph-api

I added a custom property to an Event using an office.js add-in.
I tried to get that custom property's value using https://graph.microsoft.com/v1.0/me/events/AQMkADU2OWFjYTF..AAAA==?singleValueExtendedProperties($filter=id eq 'String 00020329-0000-0000-C000-000000000046 myCusPropId ') but it is return an error:
{
"error": {
"code": "ErrorInvalidProperty",
"message": "PropertyId values may only be in one of the following formats: 'MapiPropertyType namespaceGuid Name propertyName', 'MapiPropertyType namespaceGuid Id propertyId' or 'MapiPropertyType propertyTag'.",
"innerError": {
"request-id": "c57cd272-2c10-4721-b48e-1c27117ea34f",
"date": "2019-09-27T10:23:03"
}
}
}
How do I retrieve myCusPropId?
here is office.js code
const item = Office.context.mailbox.item;
item.loadCustomPropertiesAsync(asyncResult => {
if (asyncResult.status == Office.AsyncResultStatus.Succeeded) {
let customProps = asyncResult.value;
customProps.set("myCusProp", "google.com");
customProps.saveAsync(asyncResult => {
if (asyncResult.status == Office.AsyncResultStatus.Succeeded) {
item.loadCustomPropertiesAsync(asyncResult => {
const customProps = asyncResult.value;
const myCusProp= customProps.get("myCusProp");
})
}});}});

You're missing the $expand query param and your id is malformed. The correct call phototype looks like this:
GET /me/events/{id}?$expand=singleValueExtendedProperties($filter=id eq '{prop_id}')
Note the ?$expand=singleValueExtendedProperties rather than ?singleValueExtendedProperties.
For the property itself, you're missing the Name segment:
String {00020329-0000-0000-C000-000000000046} Name myCusPropId
So the final URI would be:
https://graph.microsoft.com/v1.0/me/events/AQMkADU2OWFjYTF..AAAA==?$expand=singleValueExtendedProperties($filter=id eq 'String {00020329-0000-0000-C000-000000000046} Name myCusPropId')

Related

return object after null checking through if in blazor

public async Task<ServiceResponse<Product>> GetProductAsync(int productId)
{
var response = new ServiceResponse<Product>()
{
Data = await _context.Products.AsNoTracking().FirstOrDefaultAsync(p => p.Id == productId)
} ;
if ( response.Data == null )
{
response.Success = false ;
response.Message = "Sorry, but this product does not exist." ;
}
else
return response ;
return response ;
}
I am a newbie c# and blazor.
I made productservice.cs file. The above code is the part of it which will return one product class in Gerelic T.
First, I find matched productid in db.
Then, null check. if it is not null it will return response, ok.
I thought at first I will return response as one product to Task T, all code might be good.
But I faced an error in the last line. So I put again 'return response'. Then the error sign was disappeared.
But I think this might be wrong and weird, even though there is no error anymore.
I want to improve this code correctly or efficiently.
May I get your opinion?
The error you faced probably was something like not all code paths return a value. Since your method returns a typed value, and you are using if-else statement -- you have to provide returning value both in if and else clauses.
Extend your ServiceResponse<T> with a constructor that receives some arguments.
Refactor your method in order to stress your product variable for better readability.
Return ServiceResponse using newly-created constructor.
Unfortunately, I can't test it right now to be sure 100%, but you can give it a try.
class ServiceResponse<T>
{
public T Data { get; set; }
public bool IsSuccess { get; set; }
public string Message { get; set; }
public ServiceResponse( T data, string message = "success" )
{
Data = data;
IsSuccess = data != null;
Message = data == null ? "Sorry, but this product does not exist." : message;
}
}
public async Task<ServiceResponse<Product>> GetProductAsync( int productId )
{
var product = await _context.Products.Where( p => p.Id == productId).AsNoTracking().FirstOrDefault();
return new ServiceResponse<Product>( product );
}
Remarks
We don’t have to provide 2nd argument into the constructor while returning the response since it already has the default value defined for the message in the constructor. But you still can do that!
I also set default value for the message there if data == null. Actually, it can be removed if you wish!
IsSuccess is also being regulated by data in the constructor of ServiceResponse<T>
UPD: Tested
if ProductId == 1
{
"data": {
"id": 1,
"name": "Test1"
},
"isSuccess": true,
"message": "success"
}
if ProductId == 2 (which is out of list)
{
"data": null,
"isSuccess": false,
"message": "Sorry, but this product does not exist."
}

How to disable default response for springdoc openapi and swagger

I have a problem with a springdoc-openapi and swagger. In api.yml file I defined some responses for endpoint, for example:
responses:
200:
desription: example response
content:
......
404:
description: example response
And before that the behavior was expected to me. In swagger I saw an example value for 200 and I didn't see an example value for 404, only description. When I started to use springdoc-openapi, when I didn't provided content for example for 404, the content from 200 is applied to 404.
Is there a option how to hide it? For example in api.yml or any config property?
I tried to search config properties but I din't find anything. Moreover I tried with content: {} but It didn't work too.
It is be possible to handle as return an empty content as response using, one of the following syntaxes:
content = #Content
content = #Content(schema = #Schema(hidden = true))
For example:
#GetMapping
#ApiResponses(value = {
#ApiResponse(responseCode = "200", description = "example response"),
#ApiResponse(responseCode = "404", description = "example response", content = #Content)
})
public String index() {
return "Hello";
}
For RestControllerAdvice
#ResponseStatus(HttpStatus.NOT_FOUND)
#ExceptionHandler({ RuntimeException.class })
#ApiResponse(responseCode = "404", description = "example response", content = #Content)
#ResponseBody
public String handleError() {
return "NotFound";
}
Please see: https://springdoc.org/#how-can-i-return-an-empty-content-as-response

Swagger Structural error "should NOT have additional properties" $ref element in array

I am getting Structural error "should NOT have additional properties" error due to $ref element present in type: array.
In https://editor.swagger.io when replace $ref: '#/definitions/EnumExample1' with type: array. I do not see the error. But I am not sure how to fix this in swagger-gen code.
If more information is required to understand this issue, please post in comments!
Swagger snippet
parameters:
- in: query
name: parameterNameX
description: parameterNameX
type: string
- in: query
name: name
type: string
- in: query
name: include
description: Comma-separated list of properties to include in the response
type: array
items:
$ref: '#/definitions/EnumExample1'
Errors
Structural error at paths./v1/workflows.get.parameters.2.items
should NOT have additional properties
additionalProperty: $ref
Jump to line 30
Startup.cs
services
.AddMvc(options =>
{
options.EnableEndpointRouting = false;
options.Conventions.Add(new CsvQueryStringConvention());
})
.AddNewtonsoftJson(options =>
{
options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
options.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
//ensure enums passed to client are strings
options.SerializerSettings.Converters.Add(new StringEnumConverter { NamingStrategy = new CamelCaseNamingStrategy()});
})
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("",
new OpenApiInfo()
{
Title = "Service",
Version = "v1"
});
app.UseSwagger(c =>
{
c.RouteTemplate = "app/swagger/{documentName}/swagger.json";
c.PreSerializeFilters.Add((openApiDocument, httpReq) =>
{
openApiDocument.Servers = new List<OpenApiServer>
{
new OpenApiServer { Url = $"https://{httpReq.Host.Value}" }
#if DEBUG
, new OpenApiServer { Url = $"http://{httpReq.Host.Value}" }
#endif
};
});
c.SerializeAsV2 = true;
});
Model
public EnumExample1[] Example { get; set; }
From Swagger Example will be passed as comma-separated string. Since c.SerializeAsV2 = true; I am not sure why generated Swagger.json have $ref element which is OpenApi3 standard.
Adding UseInlineDefinitionsForEnums to swagger-gen removed reference to definitions and added type: string.
Found some open issues on swagger and openapi,
OpenAPI.NET : SerializeAsV2 produces invalid swagger (when SerializeAsV3 is valid) [Open]
Swashbuckle.AspNetCore : No type for enums in query parameters (using SerializeAsV2) (Closed with UseInlineDefinitionsForEnums solution)
services.AddSwaggerGen(c =>
{
c.SwaggerDoc(....);
//Generate inline schema definitions (as opposed to referencing a shared definition) for enum parameters and properties
c.UseInlineDefinitionsForEnums();

How use the API Create Event Calendar Microsoft-GraphAPI

Seem that this API
https://learn.microsoft.com/en-us/graph/api/user-post-events?view=graph-rest-1.0&tabs=http
Is possibile to use with Application Token..
But When I use this POST format :
/users/{id | userPrincipalName}/calendars/{id}/events
I imagine that the first id= is of the user 365
And the second id= id of calendar of this user
example: https://graph.microsoft.com/v1.0/users/7abea3d2-9c59-4910-90c8-24a626a2ed0f/calendar/AAMkADRiNWMwZDIwLTNkNWMtNDlhZi04ODAxLTQyZjI0NGZjZjZiYgBGAAAAAADdzAdsxNzoS5NsTnjM9VXMBwDeKuBOt9H8SaQ6MfKsS4oyAAAAAAEGAADeKuBOt9H8SaQ6MfKsS4oyAAAAADKcAAA=/events
The result is this:
{
"error": {
"code": "BadRequest",
"message": "Resource not found for the segment 'AAMkADRiNWMwZDIwLTNkNWMtNDlhZi04ODAxLTQyZjI0NGZjZjZiYgBGAAAAAADdzAdsxNzoS5NsTnjM9VXMBwDeKuBOt9H8SaQ6MfKsS4oyAAAAAAEGAADeKuBOt9H8SaQ6MfKsS4oyAAAAADKcAAA='.",
"innerError": {
"request-id": "11055856-32b4-4485-bf28-23e380d9e4ed",
"date": "2020-05-27T13:22:23"
}
}
}
Have you any suggestion?
#Thank #Homungus comment... missing a s in calendar string and now work!

Add parent site columnLink to a contentType

I have a subsite where I created a contentType. I want to a add columnLink from the parent site using:
POST https://graph.microsoft.com/v1.0/sites/{site-id}/contentTypes/{contentType-id}/columnLinks
Adding current site columns works as expected, however when adding columnLink from parent site, fails with such response:
{
"error": {
"code": "itemNotFound",
"message": "The referenced column does not exist",
"innerError": {
"request-id": "...,
"date": "2018-07-31T11:05:34"
}
}
}
The body that was sent:
{
"name": "Detail"
}
The endpoint works correctly for both id and name in request body. (For current site columnLinks)
According to your questions, I suppose you want to add a columnLink from parent site.
Based on my test, If we want to add a column to a contentType, we can get the column first by this API:
https://graph.microsoft.com/v1.0/sites/{site-id}/columns. This step is to ensure that the column exists. The part of response will be like this:
{
"name": "{column Name}",
"id": "{column Id}"
}
Then we add site columnLink to a contentType, we can use this column Name like this:
POST https://graph.microsoft.com/v1.0/sites/{site-id}/contentTypes/{contentType-id}/columnLinks
The body like this:
{
"name":"{column Name}"
}
or
{
"id": "{column Id}"
}

Resources