Microsoft Graph update SharePoint list item multi choice field - json

What is the proper JSON syntax to update a multi-choice list item field using the Microsoft Graph?
Multi choice fields return a json array of strings like:
GET: /v1.0/sites/{siteId}/lists/{listId}/items/{itemId}
"CAG_x0020_Process_x0020_Status": [
"Proposed Funding - Customer Billed",
"Proposed Funding - Sales Funded",
"SOW - Needed"
]
However, when using the same syntax to update the field a 400 invalid request is returned.
PATCH: /v1.0/sites/{siteId}/lists/{listId}/items/{itemId}/fields
"CAG_x0020_Process_x0020_Status": [
"Proposed Funding - Customer Billed",
"Proposed Funding - Sales Funded",
"SOW - Needed"
]
Error returned:
{
"error": {
"code": "invalidRequest",
"message": "The request is malformed or incorrect.",
"innerError": {
"request-id": "2251e25f-e4ce-491f-beb9-e463c7d8d5af",
"date": "2018-05-16T15:16:23"
}
}
}
I am able to update all other fields requested, but this last field is holding up a release of the application.

To elaborate on what #muhammad-obaidullah-ather wrote in the comments, for string multiple choices you need to define the type as Collection(Edm.String) and then his solutions works for me. Repeating what he wrote as complete answer.
This should be sent as a PATCH like this:
PATCH /v1.0/sites/{SiteId}/lists/{ListId}/items/{ItemId}/fields
{"*FieldName*#odata.type":"Collection(Edm.String)","*FieldName*":["*Value1*","*Value2*"]}

This works for me
graph.api(url)
.version('beta')
.post({
'fields': {
'AssignedToLookupId#odata.type': 'Collection(Edm.Int32)',
'AssignedToLookupId': [5,13]
}
});

Unfortunately, a number of column types, including MultiChoice, cannot be updated via Microsoft Graph today. I would recommend adding this to the Office Dev UserVoice so it remains on the radar of the SharePoint/Graph team.

Related

Accessing items in a list in AppleScript?

I'm trying to access items in a list via AppleScript. Try as I might, I can't seem to access them. I've pasted my code below
tell application "JSON Helper"
set result to fetch JSON from "https://newsapi.org/v2/top-headlines?sources=bbc-news&pageSize=1&apiKey=X"
set news to title of articles of result
end tell
set result_string to news & ""
Note, I've removed my api key. The api format is :
{"status":"ok","totalResults":10,"articles":[{"source":{"id":"bbc-news","name":"BBC News"},"author":"BBC News","title":"Trump urges Israeli 'care' on settlements","description":"The US president also casts doubt on whether the Palestinians or Israel are ready to talk peace.","url":"http://www.bbc.co.uk/news/world-middle-east-43025705","urlToImage":"https://ichef.bbci.co.uk/news/1024/branded_news/165CD/production/_99979519_044058382.jpg","publishedAt":"2018-02-11T16:47:27Z"}]}
I'm trying to access title but I keep getting "can't get title".
Any input would be much appreciated. Thanks!
Using the sample JSON data you gave, I used this command:
tell application "JSON Helper" to read JSON from ¬
"{
\"status\": \"ok\",
\"totalResults\": 10,
\"articles\": [
{
\"source\": {
\"id\": \"bbc-news\",
\"name\": \"BBC News\"
},
\"author\": \"BBC News\",
\"title\": \"Trump urges Israeli 'care' on settlements\",
\"description\": \"The US president also casts doubt on whether the Palestinians or Israel are ready to talk peace.\",
\"url\": \"http://www.bbc.co.uk/news/world-middle-east-43025705\",
\"urlToImage\": \"https://ichef.bbci.co.uk/news/1024/branded_news/165CD/production/_99979519_044058382.jpg\",
\"publishedAt\": \"2018-02-11T16:47:27Z\"
}
]
}"
to retrieve an AppleScript record. Pretty-printing it as I have above, however, you might already be able to see that articles is a list (containing one item). Therefore, whilst this:
set news to title of articles of result
produces an error, this:
set news to title of item 1 of articles of result
retrieves the correct datum.

REST POST json body to support complex query advice

I'm fairly new to REST. All of our legacy webservices were SOAP based with enterprise (ORACLE or DB2) databases. We are now moving to REST/couchbase.
Our team is looking into implementing a complex query method. We already have implemented simple query methods using GET, for example GET returns all entries and a GET/067e6162-3b6f-4ae2-a171-2470b63dff00 would return the entry for 067e6162-3b6f-4ae2-a171-2470b63dff00.
We want to support a query method that would support receiving several query parameters such a list of Ids and date ranges. The number of Ids can number into a few thousand and because of this, we realize we cannot pass these query parameters in a GET HTTP header since there is a limit on header size.
We are starting to look into passing our query parameters into the JSON body of a POST request. For example, we could have client pass in a few thousand Ids as an array and also pass in a date range, so we'd have each query param/filter be an object. The JSON body would then be an array of objects. For example:
{
"action" : "search",
"queryParameters" : {
[
{
“operation”: “in”,
"key" : "name.of.attribute.Id",
"value" : "[{ "id: "067e6162-3b6f-4ae2-a171-2470b63dff00"}, {"id": "next id"....}],
},
{
“operation”: “greater”,
"key" : "name.of.attribute “,
"value" : "8/20/2016"
},
{
“operation”: “less”,
"key" : "name.of.attribute “,
"value" : "8/31/2016"
}
]
}
The back end code would then receive POST and read the body. It would see action is a search and then look for any entries in the list that are in the list of Ids that are in the date range of > 8/20/2016 and < 8/31/2016.
I've been trying to look online for tips/best practices on how best to structure the JSON body for complex queries but have not found much. So any tips, guidance or advice would be greatly appreciated.
thanks.

Opensearchsever -Search range beteen dates- JSON Restful API

I'm trying to use OpenSearchServer in one of my applications using RestFul JSON API .Can you please provide an example for querying search between 2 dates using the restful JSON api?
Below is my code so far
{"query":"test help","rows":100,
"returnedFields":[
"fileName",
"url"
]
}
Sorry for the bandwidth wastage.
To search between two dates using JSON API, we can use the "Relative date filter " .
Here's what the documentation says :
The Relative date filter can be used for this. Let's say that documents are indexed with the current date in the field indexedDate. In our example the date is expressed using the yyyyMMddHHmmss format - for instance 20141225130512 stands for the 25th of December, 2014, at 1:05:12 PM.
eg:
"filters":[
{
"negative":false,
"type":"RelativeDateFilter",
"from":{
"unit":"days",
"interval":2
},
"to":{
"unit":"days",
"interval":0
},
"field":"indexedDate",
"dateFormat":"yyyyMMddHHmmss"
}
],
Further details can be found here :http://www.opensearchserver.com/documentation/faq/querying/how_to_use_filters_on_query.md

Accessing attributes of a json

I have this JSON output
{
"status":1,
"complete":1,
"list":{
"792489954":{
"item_id":"792489954",
"resolved_id":"792489954",
"given_url":"http:\/\/www.liveathos.com\/?gclid=Cj0KEQiAzb-kBRDe49qh9s75m-wBEiQATOxgwZcJ5_ws34o4PUSUYDGqs8HEbLF-LyjxrTPOwn6AYV8aAmMk8P8HAQ",
"given_title":"Athos - Wearable Technology for Fitness",
"favorite":"0",
"status":"0",
"time_added":"1418754744",
"time_updated":"1418754746",
"time_read":"0",
"time_favorited":"0",
"sort_id":0,
"resolved_title":"Wearable Technology for Fitness",
"resolved_url":"http:\/\/www.liveathos.com\/?gclid=Cj0KEQiAzb-kBRDe49qh9s75m-wBEiQATOxgwZcJ5_ws34o4PUSUYDGqs8HEbLF-LyjxrTPOwn6AYV8aAmMk8P8HAQ",
"excerpt":"Thank you for reserving Athos. You will receive a confirmation email with reservation details and a referral link where you get $10 off your next order.",
"is_article":"0",
"is_index":"0",
"has_video":"0",
"has_image":"0",
"word_count":"25"
},
"692647226":{
"item_id":"692647226",
"resolved_id":"692647226",
"given_url":"http:\/\/www.terrafugia.com\/news",
"given_title":"News | Terrafugia",
"favorite":"0",
"status":"0",
"time_added":"1418754204",
"time_updated":"1418754204",
"time_read":"0",
"time_favorited":"0",
"sort_id":1,
"resolved_title":"News",
"resolved_url":"http:\/\/www.terrafugia.com\/news",
"excerpt":"",
"is_article":"0",
"is_index":"1",
"has_video":"0",
"has_image":"0",
"word_count":"0"
},
`...etc` "since":1419641101
};
It's a JSON with a list that should have article items on it. I want to access the properties of these smaller items like given_url.
I'm using
for key in (BIGJSONRESPONSE).list
do etc...
When I try printing the key, I get only the id that comes before an item. Any idea how to access more?
Thanks!
You asked for the keys, you got the keys. To get the item associated with that key, use BIGJSONRESPONSE.list[key].
This should be correct:
for in returns the keys of an object. Since the key refers to a property of the object one can access the property using [key].
for (key in (BIGJSONRESPONSE).list)
{
console.log(BIGJSONRESPONSE.list[key]) // log the entry to console for debugger.
}

VersionOne: Report on Backlog Items, tasks, defects with Attachments in C# V1 API/JSON

How would you query VersionOne (V1) to build a report that contains (Backlog Items with assoicated tasks, defects and especially Attachments in C# for a given Project? Does anyone have C# V1 API/JSON example on how to do this? I need the the part that queries VersioOne and extracts the Attachment to a directory. I can do the reporting part.
Thanks,
Remy
I suggest using any C# HTTP library you like. Submit a query such as the following to ~/query.v1 . The query text may in a POST body or in a GET url parameter named query:
where:
Name: Whatever Project You Want
from: Scope
select:
- Name
- from: Workitems:PrimaryWorkitem
select:
- AssetType
- Number
- from: Attachments
select:
- Name
- Description
- ContentType
- Content
- from: Children:Task
select:
- Name
- Number
- AssetType
- from: Attachments
select:
- Name
- Description
- ContentType
- Content
Above, I select Attachment.Content which would yield a base64 blob in the output. The attachment content URLs are not present in any attribute that can be selected by query.v1, but you can create them by appending the Attachment id to ~/attachment.v1
Results will be returned in a straightforward hierarchical JSON response:
[
[
{
"_oid":"Scope:57460",
"Name":"openAgile",
"Workitems:PrimaryWorkitem": [
{
"_oid":"Story:83524",
"AssetType":"Story",
"Number":"S-08114",
"Attachments":[],
"Subs":[],
"Children:Task": [
{
"_oid":"Task:86578",
"Name":"Test Integration in Atlanta",
"Number":"TK-11051",
"AssetType":"Task"
},
{
"_oid":"Task:86581",
"Name":"Install In our Production environment",
"Number":"TK-11052",
"AssetType":"Task"
},
{
"_oid":"Task:86584",
"Name":"Document",
"Number":"TK-11053",
"AssetType":"Task"
}
]
},
]
}
]
]
You may also use the rest-1.v1 endpoint or our SDK library, but query.v1 is highly suggested for virtually any report or read-only query that it allows.