cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
murrah
Level: Powered On

Custom Planner Connector to update the bucketId on a task: how to set the If-Match request parameter?

Hi.

In my PowerApp using the standard connector I can update the Task Title of the current record in the Gallery eg

 

onChange = Planner.UpdateTaskV2(id,{title:TaskTitle.Text})

 

 ie in the onChange event handler of the Text component called "TaskTitle", call the Planner connector method UpdateTaskV2(id,{title:TaskTitle.Text}) and yes, the Task Title updates in Planner. Same for updating the dueDateTime:

 

Planner.UpdateTaskV2(id,{dueDateTime:dueDate})

 

So far so good. Now, what I also want to do is update the bucketId to move a Task record from one bucket in the plan to another which the standard connector does not allow. So, I need to make a Custom Connector (CC).

I made a CC called PlannerCustomConnector (imaginative, I know!) with a bunch of GETs and all works well. eg for a Gallery Items collection:

 

PlannerCustomConnector.ListBucketTasks("myBucketIdGoesHere").value

 

To change the bucketId on a Task I need to use PATCH with an If-Match of the most recent etag from the Task. Testing that in MSGraph works to shift the Task record from one bucket to another eg:

 

PATCH https://graph.microsoft.com/v1.0/planner/tasks/myTaskIdHere
Request header If-Match : W/"JzEtVGFzayAgQEBAQEBAQEBAQEBAQEBESCc="   
Request body: { "bucketId":"theTargetBucketIdInThisPlanGoesHere" }

 

where that If-Match was copied from the etag of the most recent GET of that same task. So, that much works.

 

Now, what I cannot work out is how to define the PATCH request in the PowerApps Custom Connector builder so I can set the If-Match request header property. I can get the etag data from ThisItem in the app, of course, but how to define the request in the Connector so I can set the request header property with that value? Or so it will do it for me even?

I used the Postman => Export => import to PowerApps Connector method for all my other requests and have a definition item for my UpdateTask request in the PowerApps Connector builder but what value do I put in the Request Header CC definition for the If-Match key??

 

This is the last hurdle preventing me from finishing my custom Planner app. Well, I hope it is the last hurdle anyway - I have said that about 10 times so far in this project! So many Gotchas!

Thanks,

Murray

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
murrah
Level: Powered On

Re: Custom Planner Connector to update the bucketId on a task: how to set the If-Match request parameter?

Sorry for the delay getting back. I now have this working.

So, in addition to the helpful info above there was another request header that was required to make this useful in an app and which is not mentioned in the docs. 😞

Here are the steps to define an action called UpdateTask:

1. This blog post outlines setting up the Azure App permissions etc so your custom connector can authenticate on behalf of the user who is using it (ie you, for now).

https://toddbaginski.com/blog/how-to-make-a-custom-connector-for-powerapps-and-flow-that-calls-the-m... 

Follow that pattern to delegate permissions, generate the secret key, etc. That blog post example requires Directory and Group permissions. For Planner you will also need to delegate permissions for Tasks eg Tasks.ReadWrite (and possibly others depending on what you want your custom connector to be able to do). 

2. In the Generate Swagger file section, when using Postman, add API calls for the various Planner calls you want to include in your connector. In terms of this example, we will want one for at least GetTask and UpdateTask

 

 

 

 

GET https://graph.microsoft.com/v1.0/planner/tasks/:taskid
PATCH https://graph.microsoft.com/v1.0/planner/tasks/:taskid

 

 

 

 

Note that with some extra work you can use Postman to test your calls, that is not necessary here. All we are doing is defining the API calls we want to build into our custom connector so Postman will build the JSON definition file for us. So, add your calls and continue down to Export your collection of API calls.

3. Follow the instructions in the Create your custom connector section of the blog post.

Build the action for GetTask() first. It is simple and you can use it to make sure all is working before going on to define the UpdateTask() action. Note that in the blog post Todd is using the connector Test tab to get the template JSON to continue with the definition (step 20 or so). In practice, I found it easier to have the Graph Explorer open in another browser window and use it to run the calls in order to get the template / sample response JSON we need for the connector definition. 

Once you have built and saved the GetTask() action you can test it to make sure you are on track so far. If you wanted you could go ahead and test it in your Power App as per the blog post.

NB: whenever you change your custom connector definition, you will need to remove it from your Power App connectors section and add it back again so the Power App uses the latest version of your connector.

 

Now the UpdateTask() action:

Caveat: This example shows you how to update the simple types (title, bucketId, dueDateTime, etc). I have not tested using it for the objects like assignments{} or createdBy{}

 

Click the Definition tab:

Greenshot 2019-12-17 08.54.19.png

 

Click the UpdateTask action from your Postman import (as above). Fill in the dialog:

Greenshot 2019-12-18 21.15.12.png

 

Scroll down to Import from sample and click it then add the following (text samples are below the image), then click Import:

Greenshot 2019-12-17 09.46.17.png

 

 

https://graph.microsoft.com/v1.0/planner/tasks/{taskid}

If-Match XXXX
Prefer return=representation
{
    "bucketId": "",
    "orderHint": "",
    "assigneePriority": "",
    "title": "",
    "percentComplete": 0,
    "startDateTime": null,
    "dueDateTime": "",
    "conversationThreadId": null,
    "appliedCategories": {},
    "assignments": {}
}

 

 

Notes on the above:

1. Only the header property names are used. Their values don't matter here.

2. Same for the Body definition / template (hence empty property values). This fragment contains the full list of possible properties one can change according to the Graph docs at the time of writing (December 2019). At some stage the priority property will come out of Beta. When it does we will need to update this connector by adding that to the JSON (or start using the Beta url now, not recommended). If your connector only needs a subset of properties that you wish to make updateable, only specify the ones you need in the JSON.

Scroll down to the Headers section and Edit the If-Match:

Greenshot 2019-12-17 09.49.13.png

set its values like so, then click the Back button to save your changes:

Greenshot 2019-12-17 09.52.23.png

Same for Prefer.

Greenshot 2019-12-17 09.53.31.png

NOTE: the Default value is set because we want to use that on all calls. It is not dynamic and we do not want to have to pass it on every UpdateTask() action (unlike the If-Match header value) so we set the default and set visibility to "Internal". Don't quote me on that explanation but these settings work.

The purpose of the Prefer header with this value is to tell Graph to return the updated Task record. This is not mentioned in the docs but is vital so we get back an updated odata.etag value so we can do subsequent updates on the same record.

See: https://docs.microsoft.com/en-us/graph/api/resources/planner-overview?view=graph-rest-1.0#planner-re... 

 

Now define the Response Body, then click Import.

Greenshot 2019-12-17 10.12.11.png

Again, the JSON values do not matter, just the property names. To get the JSON, use Graph Explorer to run a Get Task query and copy the response JSON

 

 

https://graph.microsoft.com/v1.0/planner/tasks/{task-id}

 

 

Finally, update your connector.

Greenshot 2019-12-17 10.13.13.png

Now you can use your custom connector in your Power App. eg in a Gallery template definition for a Task. I have a dropdown control (called "bucket") on each Task record the gallery collection that lists the the buckets on that Plan so the user can use the dropdown to move a task from one bucket to another within that Plan. 

This is a simplified version. There is a bit more to this in practical application - the subject of another post.

 

 

Items = PlannerCustomConnector.ListPlanBuckets("my plan id here").value
onChange = PlannerCustomConnector.UpdateTask(id,'@odata.etag',{bucketId: bucket.Selected.id})

 

 

The take-away here is that the parameter list to UpdateTask() is the taskId AND the If-Match header value (the current etag of ThisItem's Task record) AND the object containing the data to change (the bucketId of the selected item in the bucket dropdown).

Similarly, to update the Task Title:

 

 

onChange = PlannerCustomConnector.UpdateTask(id,'@odata.etag',{title: TaskTitle.Text})

 

 

where TaskTitle is the control property name of the title field on the gallery item template.

IMPORTANT: at this point the connector should successfully update the server ONCE, but subsequent updates might fail, depending on how you set up your gallery collection. This relates to keeping track of the updated etag that is sent back after each call to UpdateTask(). I do have a work around and lots of questions about that which I will point to once I fully understand the best way forward.

Cheers,

Murray

 

 

View solution in original post

5 REPLIES 5
Community Support Team
Community Support Team

Re: Custom Planner Connector to update the bucketId on a task: how to set the If-Match request parameter?

Hi @murrah ,

Could you please share a bit more about your scenario?

Do you want to set a "If-Match" HTTP Request header property within your app when you executing the PlannerCustomConnector.UpdateTask() action?

 

If you want to set a "If-Match" HTTP Request header property within your app when you executing the PlannerCustomConnector.UpdateTask() action, I have made a test on my side, please consider take a try with the following workaround:

1. Define your "UpdateTask" action within your custom connector as below:

1.JPG

Note: The action patch (/v1.0/planner/tasks/{taskId}) is based on the Base URL you specified in your custom connector. If you specified /v1.0 as your Base URL, the above action path should be changed into /planner/tasks/{taskId}.

2. Edit the "If-Match" header within your operation as below:

2.JPG

3. Edit the If-Match Header as below:

3.JPG

4. Then click "Back" button, and specify proper Body Response Payload for this operation.

5. Save your custom connector.

 

Then when you executing the PlannerCustomConnector.UpdateTask() action within your app, the "If-Match" header property would be marked as Required property, there you could provide a proper value for it using ThisItem.ETag formula.

4.JPG

 

Please take a try with above solution, check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
murrah
Level: Powered On

Re: Custom Planner Connector to update the bucketId on a task: how to set the If-Match request parameter?

Thank you! I will work on this later today and report back.

Much appreciated.

Murray

Community Support Team
Community Support Team

Re: Custom Planner Connector to update the bucketId on a task: how to set the If-Match request parameter?

Hi @murrah ,

Have you taken a try with the solution I provided above? Have you solved your problem?

 

If you have solved your problem, please consider go ahead to click "Accept as Solution" to identify this thread has been solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
murrah
Level: Powered On

Re: Custom Planner Connector to update the bucketId on a task: how to set the If-Match request parameter?

Yes I will set as accepted once I have fully tested. Your post was a great start but there was more to it which I am still working through. One thing is that you MUST also send the following request header item (in addition to the If-Match) otherwise you do not get data back and usually get an error instead. This is not in the docs.

Prefer: return=representation

Once I have a complete working replacement for the UpdateTask() method in my custom connector I will update this post with full instructions. That will be in a few days.

Thanks,

Murray

murrah
Level: Powered On

Re: Custom Planner Connector to update the bucketId on a task: how to set the If-Match request parameter?

Sorry for the delay getting back. I now have this working.

So, in addition to the helpful info above there was another request header that was required to make this useful in an app and which is not mentioned in the docs. 😞

Here are the steps to define an action called UpdateTask:

1. This blog post outlines setting up the Azure App permissions etc so your custom connector can authenticate on behalf of the user who is using it (ie you, for now).

https://toddbaginski.com/blog/how-to-make-a-custom-connector-for-powerapps-and-flow-that-calls-the-m... 

Follow that pattern to delegate permissions, generate the secret key, etc. That blog post example requires Directory and Group permissions. For Planner you will also need to delegate permissions for Tasks eg Tasks.ReadWrite (and possibly others depending on what you want your custom connector to be able to do). 

2. In the Generate Swagger file section, when using Postman, add API calls for the various Planner calls you want to include in your connector. In terms of this example, we will want one for at least GetTask and UpdateTask

 

 

 

 

GET https://graph.microsoft.com/v1.0/planner/tasks/:taskid
PATCH https://graph.microsoft.com/v1.0/planner/tasks/:taskid

 

 

 

 

Note that with some extra work you can use Postman to test your calls, that is not necessary here. All we are doing is defining the API calls we want to build into our custom connector so Postman will build the JSON definition file for us. So, add your calls and continue down to Export your collection of API calls.

3. Follow the instructions in the Create your custom connector section of the blog post.

Build the action for GetTask() first. It is simple and you can use it to make sure all is working before going on to define the UpdateTask() action. Note that in the blog post Todd is using the connector Test tab to get the template JSON to continue with the definition (step 20 or so). In practice, I found it easier to have the Graph Explorer open in another browser window and use it to run the calls in order to get the template / sample response JSON we need for the connector definition. 

Once you have built and saved the GetTask() action you can test it to make sure you are on track so far. If you wanted you could go ahead and test it in your Power App as per the blog post.

NB: whenever you change your custom connector definition, you will need to remove it from your Power App connectors section and add it back again so the Power App uses the latest version of your connector.

 

Now the UpdateTask() action:

Caveat: This example shows you how to update the simple types (title, bucketId, dueDateTime, etc). I have not tested using it for the objects like assignments{} or createdBy{}

 

Click the Definition tab:

Greenshot 2019-12-17 08.54.19.png

 

Click the UpdateTask action from your Postman import (as above). Fill in the dialog:

Greenshot 2019-12-18 21.15.12.png

 

Scroll down to Import from sample and click it then add the following (text samples are below the image), then click Import:

Greenshot 2019-12-17 09.46.17.png

 

 

https://graph.microsoft.com/v1.0/planner/tasks/{taskid}

If-Match XXXX
Prefer return=representation
{
    "bucketId": "",
    "orderHint": "",
    "assigneePriority": "",
    "title": "",
    "percentComplete": 0,
    "startDateTime": null,
    "dueDateTime": "",
    "conversationThreadId": null,
    "appliedCategories": {},
    "assignments": {}
}

 

 

Notes on the above:

1. Only the header property names are used. Their values don't matter here.

2. Same for the Body definition / template (hence empty property values). This fragment contains the full list of possible properties one can change according to the Graph docs at the time of writing (December 2019). At some stage the priority property will come out of Beta. When it does we will need to update this connector by adding that to the JSON (or start using the Beta url now, not recommended). If your connector only needs a subset of properties that you wish to make updateable, only specify the ones you need in the JSON.

Scroll down to the Headers section and Edit the If-Match:

Greenshot 2019-12-17 09.49.13.png

set its values like so, then click the Back button to save your changes:

Greenshot 2019-12-17 09.52.23.png

Same for Prefer.

Greenshot 2019-12-17 09.53.31.png

NOTE: the Default value is set because we want to use that on all calls. It is not dynamic and we do not want to have to pass it on every UpdateTask() action (unlike the If-Match header value) so we set the default and set visibility to "Internal". Don't quote me on that explanation but these settings work.

The purpose of the Prefer header with this value is to tell Graph to return the updated Task record. This is not mentioned in the docs but is vital so we get back an updated odata.etag value so we can do subsequent updates on the same record.

See: https://docs.microsoft.com/en-us/graph/api/resources/planner-overview?view=graph-rest-1.0#planner-re... 

 

Now define the Response Body, then click Import.

Greenshot 2019-12-17 10.12.11.png

Again, the JSON values do not matter, just the property names. To get the JSON, use Graph Explorer to run a Get Task query and copy the response JSON

 

 

https://graph.microsoft.com/v1.0/planner/tasks/{task-id}

 

 

Finally, update your connector.

Greenshot 2019-12-17 10.13.13.png

Now you can use your custom connector in your Power App. eg in a Gallery template definition for a Task. I have a dropdown control (called "bucket") on each Task record the gallery collection that lists the the buckets on that Plan so the user can use the dropdown to move a task from one bucket to another within that Plan. 

This is a simplified version. There is a bit more to this in practical application - the subject of another post.

 

 

Items = PlannerCustomConnector.ListPlanBuckets("my plan id here").value
onChange = PlannerCustomConnector.UpdateTask(id,'@odata.etag',{bucketId: bucket.Selected.id})

 

 

The take-away here is that the parameter list to UpdateTask() is the taskId AND the If-Match header value (the current etag of ThisItem's Task record) AND the object containing the data to change (the bucketId of the selected item in the bucket dropdown).

Similarly, to update the Task Title:

 

 

onChange = PlannerCustomConnector.UpdateTask(id,'@odata.etag',{title: TaskTitle.Text})

 

 

where TaskTitle is the control property name of the title field on the gallery item template.

IMPORTANT: at this point the connector should successfully update the server ONCE, but subsequent updates might fail, depending on how you set up your gallery collection. This relates to keeping track of the updated etag that is sent back after each call to UpdateTask(). I do have a work around and lots of questions about that which I will point to once I fully understand the best way forward.

Cheers,

Murray

 

 

View solution in original post

Helpful resources

Announcements
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

New Badges

Check it out!

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors
Users online (5,097)