REST call to Microsoft Graph with a nested object for assignment

  • 27 August 2020
  • 5 replies
  • 107 views

Badge +4

I am trying to extend my K2 implementation to assign tasks to a person when creating or updating a task in Planner using Microsoft Graph and the REST broker.

After several hours it feels like I am not getting anywhere.

It looks like K2 REST can't have a nested object in the definition.

 

I need to send a JSON payload like this for create:

{
    "planId": "xg6smYH69E-B9P5uD2weqMgACzzz",
    "bucketId": "OZQvBBqIJ0Gh8mN7FeUyHsgACzzz",
    "title": "Testing assignment",
    "startDateTime": "20*personal details removed*",
    "dueDateTime": "20*personal details removed*",
    "assignments":{
        "730ccc49-f9*personal details removed*c*personal details removed*b4a-ed708f6d9zzz":
        "{"@odata.type":"#microsoft.graph.plannerAssignment","orderHint":"N9917 U2883!"}"
    }
}
If I don't hook up assignments to the SmartObject it works fine. As soon as I try to add the assignment, it fails. I have tried serialising it as a string and passing it, but Microsoft Graph is returning this error.
{
"error": {
"code": "BadRequest",
"message": "Property assignments in payload has a value that does not match schema.",
"innerError": {
"date": "20*personal details removed*T00:21:04",
"request-id": "8b5fce3f-399a-48*personal details removed*fdd-abf0ba1d5233"
}
}
}

I am using Fiddler on the K2 server to try to get it to work, but without any success.

 

Has anyone been able to do this and would like to share how please?

 

Thanks

 

Jem


5 replies

Badge +4

It looks like if I try to pass it as a string, K2 escapes it and makes it invalid.

 

So K2 is sending this payload:

{
"planId": "xg6smYH69E-B9P5uD2weqMgACzzz",
"bucketId": "OZQvBBqIJ0Gh8mN7FeUyHsgACzzz",
"title": "Testing not serialised",
"startDateTime": "20*personal details removed*",
"dueDateTime": "20*personal details removed*",
"assignments": "{
"730ccc49-f9*personal details removed*c*personal details removed*b4a-ed708f6dzzzz": {
"@odata.type": "#microsoft.graph.plannerAssignment",
"orderHint": "N9917 U2883!"
}
}"
}

instead of

{
"planId":"nq-kM0yo4Eylw9GDuTahTMgAEzzz",
"title":"Testing not serialised",
"startDateTime":"20*personal details removed*",
"dueDateTime":"20*personal details removed*",
"assignments":{"d7cfab7f-93c3-4030-aba6-3c3a29ee1zzz": {"@odata.type": "#microsoft.graph.plannerAssignment","orderHint": "N9917 U2883!" }}}

So unless I can somehow include it as an object, I wonder how I can stop K2 escaping the string.

Badge +4

If I call the Tasks -> CreateTask method with no serialization, it still converts this:

 

{
"planId": "xg6smYH69E-B9P5uD2weqMgACzzz",
"bucketId": "OZQvBBqIJ0Gh8mN7FeUyHsgACzzz",
"title": "Testing not serialised",
"startDateTime": "20*personal details removed*",
"dueDateTime": "20*personal details removed*",
"assignments":{
"730ccc49-f9*personal details removed*c*personal details removed*b4a-ed708f6d9zzz":
{"@odata.type":"#microsoft.graph.plannerAssignment","orderHint":"N9917 U2883!"}
}
}

to

{"planId":"xg6smYH69E-B9P5uD2weqMgACzzz","bucketId":"OZQvBBqIJ0Gh8mN7FeUyHsgACzzz","title":"Testing not serialised","startDateTime":"20*personal details removed*","dueDateTime":"20*personal details removed*","assignments":"{
"730ccc49-f9*personal details removed*c*personal details removed*b4a-ed708f6d9zzz": {
"@odata.type": "#microsoft.graph.plannerAssignment",
"orderHint": "N9917 U2883!"
}
}"}
Userlevel 3
Badge +5

Can you strip out the carriage returns before you serialize?

Badge +4

Thanks for the Reply Nigel.

Yes, unfortunately if the request is escaped at all it fails. I've tested it out in Postman.

Somehow I need K2 to not try to serialize it.

 

Thanks

Badge +4

Getting rid of the CR/LF, this is effectively what is sent and returned 

 

 

{
"planId":"{{PlanId}}",
"title":"Testing not serialised",
"startDateTime":"20*personal details removed*",
"dueDateTime":"20*personal details removed*",
"assignments":"{"d7cfab7f-93c3-4030-aba6-3c3a29ee1zzz":{"@odata.type":"#microsoft.graph.plannerAssignment","orderHint":" !"}}"
}

This is what gets returned

{
"error": {
"code": "BadRequest",
"message": "Property assignments in payload has a value that does not match schema.",
"innerError": {
"date": "20*personal details removed*T01:52:22",
"request-id": "a6716bdf-05*personal details removed*ba-92ee-c922d225a09c"
}
}
}

 

 

 

 

 

 

 

Reply