Unable to make two changes in OneNote page - microsoft-graph-api

I need to complete todos in user's page via MS Graph API. If todos are in a list, after replace operation for the todo the list becomes broken. Luckily, I found a hack to complete todo without breaking the list: Working with OneNote Page Content via the Graph API
Insert a completed copy of a target todo before it
Replace the target todo with empty block
If I send these 2 operations in one request - API returns 500.
Is it possible to fix it?
Details about page and requests:
Page layout (GET /me/onenote/pages/{{pageId}}/content?includeIDs=true)
<html lang="en-US">
<head>
<title>Nested list</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="created" content="2018-10-04T09:46:00.0000000" />
</head>
<body data-absolute-enabled="true" style="font-family:Calibri;font-size:11pt">
<div id="div:{b883c993-0084-480b-9f15-3b0407435f29}{144}" style="position:absolute;left:96px;top:139px;width:624px">
<p id="p:{b883c993-0084-480b-9f15-3b0407435f29}{146}" data-tag="to-do" style="margin-top:0pt;margin-bottom:0pt">Super task</p>
<p id="p:{b883c993-0084-480b-9f15-3b0407435f29}{153}" style="margin-top:0pt;margin-bottom:0pt">Point 1</p>
<p id="p:{b883c993-0084-480b-9f15-3b0407435f29}{155}" style="margin-top:0pt;margin-bottom:0pt">Point 2</p>
<p id="p:{b883c993-0084-480b-9f15-3b0407435f29}{149}" data-tag="to-do" style="margin-top:0pt;margin-bottom:0pt">Mega task</p>
<p id="p:{b883c993-0084-480b-9f15-3b0407435f29}{151}" data-tag="to-do" style="margin-top:0pt;margin-bottom:0pt">Mega subtask</p>
</div>
</body>
</html>
Update request (PATCH /me/onenote/pages/{{pageId}}/content):
[
{
"action": "insert",
"position": "before",
"target": "p:{b883c993-0084-480b-9f15-3b0407435f29}{146}",
"content": "<p data-tag=\"to-do:completed\" style=\"margin-top:0pt;margin-bottom:0pt\">Super task</p>"
}, {
"action": "replace",
"target": "p:{b883c993-0084-480b-9f15-3b0407435f29}{146}",
"content": "<span></span>"
}
]
API response:
{
"error": {
"code": "19999",
"message": "Something failed, the API cannot share any more information at the time of the request.",
"innerError": {
"request-id": "d352cd80-b40d-4d55-b984-2bb5cae07f2b",
"date": "2018-10-04T04:24:25"
}
}
}

Is it possible to fix it?
Yes. By using the batch request.
A workaround for you, I still working on format the body data:
{
"requests": [
{
"id": "1",
"url": "/me/onenote/pages/{page-id}/content",
"method": "PATCH",
"body": {
"value": [
{
"action": "insert",
"position": "before",
"target": "p:{04b55584-a5f7-4ac2-b34d-474ebe346ce8}{69}",
"content": "<p data-tag=\"to-do:completed\" style=\"margin-top:0pt;margin-bottom:0pt\">Super task</p>"
}
]
},
"headers": {
"Content-Type": "application/json"
}
},
{
"id": "2",
"url": "/me/onenote/pages/{page-id}/content",
"method": "PATCH",
"body": {
"value": [
{
"action": "replace",
"target": "p:{04b55584-a5f7-4ac2-b34d-474ebe346ce8}{69}",
"content": "<span></span>"
}
]
},
"headers": {
"Content-Type": "application/json"
}
}
]
}

Related

Create a ‘Post Install Page’ Module for Confluence Cloud connect app

I am trying to create a postInstallPage module for my Confluence Cloud connect app. This is how my descriptor looks like;
{
"modules": {
"webhooks": [
{
"event": "page_updated",
"url": "/page_update"
}
],
"postInstallPage": {
"url": "/install",
"name": {
"value": "My Post-Install Page"
},
"key": "my-post-install-page"
}
},
"key": "<%= ENV['APP_KEY'] %>",
"name": "<%= ENV['APP_NAME'] %>",
"description": "<%= ENV['APP_DESCRIPTION'] %>",
"vendor": {
"name": "<%= ENV['APP_VENDOR_NAME'] %>",
"url": "<%= ENV['SITE_URL'] %>"
},
"links": {
"self": "<%= ENV['SITE_URL'] %>/confluence.json"
},
"lifecycle": {
"installed": "/callback"
},
"baseUrl": "<%= ENV['SITE_URL'] %>",
"authentication": {
"type": "jwt"
},
"enableLicensing": <%= ENV['ENABLE_LICENSING'] %>,
"scopes": [
"read"
]
}
In the install.html , I have this
<html>
<p>Let's get started</p>
</html>
<script src="https://connect-cdn.atl-paas.net/all.js"></script>
The problem is, when I install the app and click on “Get Started”, I get this error “App is not responding. Wait or Cancel” I have no idea what I am doing wrong. The app connects well with Atlassian on other modules like webhooks.

Graph JSON response seldom contains raw HTML

When I send batch request made of calendar appointment request to Graph API, I seldom encounter a improper response from the API: some XML are injected as is in the JSON response.
This is impossible to unserialize, so I cannot know which appointment had issues, and it leaves no choice but to reiterate the same calendar appointments batch, which poses performance issue.
The request to batch API looks as follow (I intentionally hide information with *** in the post data below and did not show with ... the 3 others requests to calendar Graph API)
POST https://graph.microsoft.com/v1.0/$batch
Accept: application/json
Content-Type: application/json
{
"requests": [
{
"id": "33",
"method": "PATCH",
"url": "/me/calendars/***/events/***",
"body": {
"subject": "***",
"location": {
"displayname": "***"
},
"body": {
"content": "***"
},
"categories": ["***"],
"start": {
"dateTime": "2021-05-12 06:00:00",
"timeZone": "UTC"
},
"end": {
"dateTime": "2021-05-12 07:00:00",
"timeZone": "UTC"
},
"showAs": "free",
"isReminderOn": false,
"reminderMinutesBeforeStart": 0,
"singleValueExtendedProperties": [{
"id": "String {***} Name ***",
"value": "***"
}
]
},
"headers": {
"Content-Type": "application/json"
}
}, {
"id": "34",
...
}
]
}
This is what I seldom get (before and later on, the same id worked just fine)
{
"responses": [
{
"id": "33",
"status": 503,
"headers": {
"Content-Type": "text/html; charset=us-ascii"
},
"body":<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Service Unavailable</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Service Unavailable</h2>
<hr><p>HTTP Error 503. The service is unavailable.</p>
</BODY></HTML>
}, {
"id": "34",
"status": 200
...
}
]
}
Could you please investigate this issue and render a proper JSON response in any case, even if it fails with a 503 response?
Note: I reported this bug at https://github.com/microsoftgraph/microsoft-graph-docs/issues/12951 but none of the solution provided by the automated closing message was relevant.
I rather reported the bug to the right github repo https://github.com/microsoftgraph/msgraph-sdk-serviceissues/issues/93

Microsoft graph batch inserting new task and updating details

Current steps for creating task are
POST /planner/tasks
GET /planner/tasks/{id from post call}/details
PATCH /planner/tasks/{id from post call}/details
If-Match: {etag from get call}
but I want to batch three steps in single call using https://developer.microsoft.com/en-us/graph/docs/concepts/json_batching
And according to odata v4 references http://docs.oasis-open.org/odata/odata-json-format/v4.01/csprd02/odata-json-format-v4.01-csprd02.html#sec_ReferencingNewEntities we can refer entities in same batch call using ${id of other request}
{
"requests": [
{
"id": "task",
"url": "/planner/tasks",
"body": {
"title": "asff",
"appliedCategories": {
"category5": true
},
"planId": "mSV7ODf3g0iTJrUtsNcvHZYAB-ZW",
"bucketId": "WFN6kxMykE-4xxqLUh1uS5YALCWq",
"assignments": {
"4393baf8-8a52-4164-bf93-b1cba5130329": {
"#odata.type": "#microsoft.graph.plannerAssignment",
"orderHint": " !"
}
},
"dueDateTime": "2018-04-23T18:30:00.000Z"
},
"method": "POST",
"headers": {
"Content-Type": "application/json"
}
},
{
"id": "getDetail",
"method": "GET",
"dependsOn": [
"task"
],
"url": "/planner/tasks/$task/details"
},
{
"id": "patchDetail",
"dependsOn": [
"getDetail"
],
"url": "/planner/tasks/$task/details",
"method": "PATCH",
"headers": {
"Content-Type": "application/json",
"if-match": "$getDetail"
},
"body": {
"description": "gwrthbetrhnety"
}
}
}
]
}
but Get details call is failing with error
{
"id": "getDetail",
"status": 400,
"body": {
"error": {
"code": "BadRequest",
"message": "The request URI is not valid. Since the segment 'tasks' refers to a collection, this must be the last segment in the request URI or it must be followed by an function or action that can be bound to it otherwise all intermediate segments must refer to a single resource.",
"innerError": {
"request-id": "a46ce528-993f-4cff-865e-98b2b98d5f23",
"date": "2018-04-17T10:38:29"
}
}
}
}
What I'm doing wrong here
I believe what is missing is the URI (should be POST https://graph.microsoft.com/v1.0/$batch instead of POST /planner/tasks) and "id" field has to be numeric. Check out MS documentation:
https://learn.microsoft.com/en-us/graph/json-batching?context=graph%2Fapi%2F1.0&view=graph-rest-1.0
Here is an example of combining POST and GET in a batch call

Tranformer Rule for Slideshow in Facebook Instant Article not working?

I am using Justified Gallery and I want to publish my page as an Instant Article on Facebook. As I go through the documentations here, I found out that I can transform the images into Slideshow by Transformer Rules. Here is my gallery code:
<div class="myExMul">
<a href="link_to_img" class="swipeboxImg">
<img src="link_to_img" alt="example_text" class="myExMulImg">
</a>
<a href="link_to_img2" class="swipeboxImg">
<img src="link_to_img2" alt="example_text2" class="myExMulImg">
</a>
<a href="link_to_img3" class="swipeboxImg">
<img src="link_to_img3" alt="example_text3" class="myExMulImg">
</a>
</div>
And here is my Transformer Rules:
{
"class": "SlideshowRule",
"selector": "div.myExMul",
},
{
"class": "SlideshowImageRule",
"selector": "img.myExMulImg",
"properties": {
"image.url": {
"type": "string",
"selector": "img.myExMulImg",
"attribute": "src"
},
"caption.title": {
"type": "string",
"selector": "img.myExMulImg",
"attribute": "alt"
}
}
}
When I imported the rules, it seems that my rules broke everything and I can no longer publish my articles, what am I doing wrong here?
So after some hours of research, I found the right rule for my code. The problem is you have to use the outer tag as the selector (in my case it's the a tag) instead of the inner tag (img).
{
"class": "SlideshowRule",
"selector": "div.myExMul"
},
{
"class": "SlideshowImageRule",
"selector": "a.swipeboxImg",
"properties": {
"image.url": {
"type": "string",
"selector": "img",
"attribute": "src"
},
"caption.title": {
"type": "string",
"selector": "img",
"attribute": "alt"
}
}
}

How to load a GeoJSON layer on a MapBox GL JS map?

I need to load a GeoJson Feature Collection layer (points) in a MapBox GL JS Map.
I've tried to use this HTML / Javascript code
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title></title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.39.1/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.39.1/mapbox-gl.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<div id='map'></div>
<script>
mapboxgl.accessToken = '<PUT YOUR MAPBOX KEY HERE>';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/light-v9',
center: [7.828,44.836],
zoom: 9
});
map.addControl(new mapboxgl.NavigationControl());
theCoords = {
"type": "FeatureCollection",
"features": [
{ "type": "Feature", "properties": { "NAME": "<b>Entrata Castello del Valentino<\/b>", "INFO": "Torino", "IMG_SRC": "<img src=\"http:\/\/ftp.webgisprova.altervista.org\/Database\/1T.JPG\">", "IMAGE,C": "<a href=\"http:\/\/ftp.webgisprova.altervista.org\/Database\/1.Entrata_Castello_del_Valentino.JPG\" target=\"_blank\">Immagine 360 ø<\/a>", "Longitudine": 7.6855111, "Latitudine": 45.0546417, "Altitudine": 288.39, "Direzione": 202.5, "Data": "2017:06:06", "Ora": "17:57" }, "geometry": { "type": "Point", "coordinates": [ 7.6855111, 45.0546417 ] } },
{ "type": "Feature", "properties": { "NAME": "<b>Via Frazione di Buriasco<\/b>", "INFO": "Buriasco (TO)", "IMG_SRC": "<img src=\"http:\/\/ftp.webgisprova.altervista.org\/Database\/1B.JPG\">", "IMAGE,C": "<a href=\"http:\/\/ftp.webgisprova.altervista.org\/Database\/1.Via_Frazione_di_Buriasco.JPG\" target=\"_blank\">Immagine 360›<\/a>", "Longitudine": 7.4303883, "Latitudine": 44.8816653, "Altitudine": 0.0, "Direzione": 292.5, "Data": "2017:06:16", "Ora": "19:27" }, "geometry": { "type": "Point", "coordinates": [ 7.4303883, 44.8816653 ] } },
{ "type": "Feature", "properties": { "NAME": "<b>Via Regione Maineri<\/b>", "INFO": "Buriasco (TO)", "IMG_SRC": "<img src=\"http:\/\/ftp.webgisprova.altervista.org\/Database\/1A.JPG\">", "IMAGE,C": "<a href=\"http:\/\/ftp.webgisprova.altervista.org\/Database\/1.Via_Regione_Maineri.JPG\" target=\"_blank\">Immagine 360›<\/a>", "Longitudine": 7.4328394, "Latitudine": 44.8790463, "Altitudine": 336.29, "Direzione": 180.0, "Data": "2017:06:16", "Ora": "20:23" }, "geometry": { "type": "Point", "coordinates": [ 7.4328394, 44.8790463 ] } },
{ "type": "Feature", "properties": { "NAME": "<b>Via Frazione di Buriasco<\/b>", "INFO": "Buriasco (TO)", "IMG_SRC": "<img src=\"http:\/\/ftp.webgisprova.altervista.org\/Database\/10B.JPG\">", "IMAGE,C": "<a href=\"http:\/\/ftp.webgisprova.altervista.org\/Database\/10.Via_Frazione_di_Buriasco.JPG\" target=\"_blank\">Immagine 360›<\/a>", "Longitudine": 7.4236184, "Latitudine": 44.8790577, "Altitudine": 0.0, "Direzione": 270.0, "Data": "2017:06:16", "Ora": "19:30" }, "geometry": { "type": "Point", "coordinates": [ 7.4236184, 44.8790577 ] } },
{ "type": "Feature", "properties": { "NAME": "<b>Via Rivasecca<\/b>", "INFO": "Buriasco (TO)", "IMG_SRC": "<img src=\"http:\/\/ftp.webgisprova.altervista.org\/Database\/10C.JPG\">", "IMAGE,C": "<a href=\"http:\/\/ftp.webgisprova.altervista.org\/Database\/10.Via_Rivasecca.JPG\" target=\"_blank\">Immagine 360›<\/a>", "Longitudine": 7.4266083, "Latitudine": 44.88725, "Altitudine": 348.79, "Direzione": 0.0, "Data": "2017:06:16", "Ora": "20:16" }, "geometry": { "type": "Point", "coordinates": [ 7.4266083, 44.88725 ] } },
{ "type": "Feature", "properties": { "NAME": "<b>Viale Mattioli<\/b>", "INFO": "Torino", "IMG_SRC": "<img src=\"http:\/\/ftp.webgisprova.altervista.org\/Database\/10T.JPG\">", "IMAGE,C": "<a href=\"http:\/\/ftp.webgisprova.altervista.org\/Database\/10.Viale_Mattioli.JPG\" target=\"_blank\">Immagine 360›<\/a>", "Longitudine": 7.687725, "Latitudine": 45.0566306, "Altitudine": 282.6, "Direzione": 292.5, "Data": "2017:06:06", "Ora": "17:44" }, "geometry": { "type": "Point", "coordinates": [ 7.687725, 45.0566306 ] } }
]
};
map.on('load', function () {
map.addSource("route", {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"properties": {},
"geometry": theCoords
}
});
map.addLayer({
"id": "route",
"type": "symbol",
"source": "route",
"paint": {
"circle-radius": 10,
"circle-color": "#ff0000"
}
});
});
</script>
</body>
</html>
No errors come out in my browser console but I can't see my layer on the map.
I've checked my GeoJSON using http://geojsonlint.com/ and all seems right (and using this tool my GeoJson is drawn on the tool map ....).
I think that could be something about the GeoJSON structure but I don't know hao to resolve
I've solved!
Here you're the right code ...
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title></title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.39.1/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.39.1/mapbox-gl.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<div id='map'></div>
<script>
mapboxgl.accessToken = '<PUT YOUR MAPBOX KEY HERE>';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/light-v9',
center: [7.828,44.836],
zoom: 9
});
map.addControl(new mapboxgl.NavigationControl());
map.on('load', function () {
map.addSource("route", {
"type": "geojson",
"data": "./data/test.geoJSON"
});
map.addLayer({
"id": "route",
"type": "circle",
"source": "route",
"paint": {
"circle-radius": 5,
"circle-color": "#ff0000"
}
});
});
</script>
</body>
</html>
I've put my geoJSON in a file and then I used "data": "./data/test.geoJSON" to upload it .....

Resources