Create SharePoint list item with lookup field with Microsoft Graph - microsoft-graph-api

I am trying to create list items with Microsoft Graph's new SharePoint endpoint. My URL is as follows:
https://graph.microsoft.com/beta/sites/{site-id}/lists/{list-id}/items
Calling this URL with POST, and a body like this:
{
"fields": {
"Title": "test",
}
}
.. works! But if I include a lookup field, the lookup field is always empty. I have tried with
"{columnName}": "id",
"{columnName}": "id;#value",
"{columnName}": {
"#odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference", //and others like this
"Id": "id",
"Value": "value",
}
"{columnName}": "value",
"{columnName}Id": "id",
None of these seems to work. Some give an error like "The request is malformed or incorrect.", others go through, but doesn't include the lookup field.
The documentation for this is scarce (if any), and I have found very little information on google (apart from someone asking the same question with no answers). Anyone that got this to work yet? Is it even possible?

I have got this to work with people fields where the multiple selection option was DISABLED. So if you have a person field which allows one person only, the following works.
"{columnName}LookupId": id
Additionally, the id still needs to be the SP ID and not the graph user GUID. This ID changes from site to site.

You need to add a lookup column in the following format
"Office": "London",
"OfficeLookupId", "16"
Where Office is the name of the column

Related

Sorting by controller names (Swagger) .NET Core

I am trying to figure out how and if its possible to display the api groups (controllers) sorted by controller name in .net core swagger.
There are plenty of info on how to sort the actions but i am struggling to figure out how to sort by Groups (Controller name)
Any one has any idea on this ?
Yes it is possible, look here:
http://swagger-net-test.azurewebsites.net/swagger/docs/V1
towards the end you should see:
"tags": [
{
"name": "ActionFilter"
},
{
"name": "ApiExplorer"
},
that is what controls the final order on the UI.
Hopefully, you have the latest of the swagger-ui on the version of swashbuckle you have...
But the order should not really matter, the latest has a very handy filter that makes searching for something lighting fast:
http://swagger-net-test.azurewebsites.net/swagger/ui/index?filter=Image
Try with this:
services.AddSwaggerGen(c =>
{
c.OrderActionsBy((apiDesc) => $"{apiDesc.ActionDescriptor.RouteValues["controller"]}_{apiDesc.HttpMethod}");
....
}

How to use backend permissions in frontend

I have a web application using Rails as backend and AngularJS as frontend and it has a rather complicated permission system that must hide/show buttons in the frontend accordingly.
For example, imagine something like ebay, if I created a product, I can edit, delete, etc.. but somebody can share a product with me and I can also edit, but not delete. So the permission is calculated by resource, and not using roles.
I thought adding a "permissions" attribute to each json object, something like:
[{
id: 1,
name: "product 1",
permissions: {
canEdit: true,
canDelete: false
}
},
{
id: 2,
name: "product 2",
permissions: {
canEdit: true,
canDelete: true
}
}]
Is there any best practice to send each resource permissions to the frontend?
Just to be clear, this permissions are only used to show/hide buttons, the backend still blocks this resources even if the person changes the values in the frontend
As the logic to figure out what a user can do with each item is determined on the server side, I reckon it's redundant to pass on the permissions associated with these items to client-side, unless additional processing is done on client-side based on user's interaction.
In your case, maybe you can just return different collections of objects, say an editable list and a read-only list to the client-side, based on permissions associated and then render actions based on which collection the item belongs to?

OData PUT to replace collection property

Using the OData standard is it possible to replace collection by sending a new collection?
Scenario:
The person object contains a list Address object. I would want to replace the Address collection with a new collection.
PUT Persons(1)/Addresses
[{"city": "X", "country": "US"}, {"city": "Y", "country": "US"}]
This is not possible out of the box (at least for ODATAv3), as the default routing template does not expect segments after the key portion.
But you should be able to add an ODATA Action that would do what you want to achieve. Your action definition could then look similar to this:
var action = builder.Entity<Person>()
.Action("Addresses")
.Returns<bool>();
action.Parameter<Collection<CityCountryPair>>("data");
The type CityCountryPair would be a regular DTO containing your properties you want to change. Make sure this type is also registered as an EntitySet in Odata or use a plain map/dictionary with only primitive types.
The actual call to the ODATA action would then look similar to this:
POST http://www.example.com/api/YourEndpoint/Persons(42)/Addresses
Content-Type: application/json
{
"data" :
[
{ "city" : "Berne" , "country": "CH" },
{ "city" : "Y" , "country": "CH" }
]
}
If you want to send more complex data types you can still resort to a customer JSON Deserialiser and override the default one or use a custom model binder after all.

Assign value from api response to specific model object in RAILS

I have a Contact model that has three attributes:
name, email, id
name and email are both present, but id is null.
I am using name and email to pass in through an API Post call, and this is the response I get back:
{"count": 1, "next": null, "previous": null, "results": [
{"id": 8067950, "name": "Bill","email": "test#test.com"}]}
My loop looks like this:
contacts_array.each do |contact|
api_call(contact.name, contact.email)
end
contacts_array is an array of ruby objects, namely Contact models. How can I, within that loop, assign the response id I get back to the contact used in the api_call?
I didn't really understand the difference between your Person and Contact model, but I'll assume they're the same model.
Generally you should know that it's a bad idea to handle the field called id on your own in rails. If you insist on storing the id which is returned from the call, then you should store it in another field, like api_id for example.
Below is a code that should work fine if api_call returns a Ruby Hash like the one in your question.
contacts_array.each do |contact|
contact.api_id = api_call(contact.name, contact.email)['results'].first['id']
end

joining in couchdb documents

I have posts documents and user documents how are authors of this posts. I need to get all posts which are at a given venue and for those posts the corresponding user/author documents as well.
Post:
{
"_id": "53551d9e92436f69ae04a104c2000b82",
"content": "heythere!",
"author": "a4df7fe1226fedb80f6c2dc13e000af5",
"venue": "51434246e4b0601fde0cf2eb",
"type": "post"
}
User:
{
"_id": "a4df7fe1226fedb80f6c2dc13e000af5",
"username": "sep o sep",
"type" : "user"
}
Is it possible to emit keys in the way that i will get posts to a given location along with the user documents to that posts in one couchdb query?
Check out the wiki, there's a feature called "linked documents" that allow you to retrieve related documents in a single view query.
The wiki will give a full explanation, but the gist is that you emit an object with an _id property in your view function for each related document. (since you have the id contained in your parent document) When include_docs=true is used in your view query, CouchDB knows to retrieve the documents you emitted rather than the source.

Resources