I'm creating a Power Automate flow that will update the Events Calendar when a Leave request is approved and I decided to try to using an HTTP Request (if anyone has a better idea, I'd love to hear your thoughts on it, but given what I've seen in articles and research online, this is the only approach I've come up with).
However I keep running into the issue of a "Bad Request" when the request is approved and the workflow gets to the step of updating the Calendar.
This is the raw input I am putting in my test:
{
"host": {
"connectionReferenceName": "shared_sharepointonline",
"operationId": "HttpRequest"
},
"parameters": {
"dataset": "https://MyTenant.sharepoint.com/sites/Ian_DevSandBox",
"parameters/method": "POST",
"parameters/uri": "_api/web/lists/getByTitle(‘Events’)/items",
"parameters/headers": {
"Accept": "application/json;odata=nometadata\t",
"Content-Type": "applications/json;odata=nometadata"
},
"parameters/body": "{\n '__metadata': {\n 'type': 'SP.Data.EventsListItem'\n },\n 'fAllDayEvent': 'true',\n 'EventDate': 2023-05-15'', //dateStarted(utcNow(),2)\n 'EndDate': 2023-05-16'', //dateEnded(addDays(utcNow(), 2),2)\n 'Title': 'Test Event from Flow: IR',\n 'Category': 'SICK',\n 'Description': '' //supports rich text format\n}"
}
}
and here is the error I am getting in my test:
{
"statusCode": 400,
"headers": {
"Pragma": "no-cache",
"Cache-Control": "no-store, no-cache",
"Set-Cookie": "ARRAffinity=2b32c941e87fc70dc161f1125535279f54f62986d944c59b80b03a276f731b44;Path=/;HttpOnly;Secure;Domain=sharepointonline-ncus.azconn-ncus-001.p.azurewebsites.net,ARRAffinitySameSite=2b32c941e87fc70dc161f1125535279f54f62986d944c59b80b03a276f731b44;Path=/;HttpOnly;SameSite=None;Secure;Domain=sharepointonline-ncus.azconn-ncus-001.p.azurewebsites.net",
"x-ms-request-id": "1e37b2a0-c079-3000-8b96-459e6976637e",
"Strict-Transport-Security": "max-age=31536000; includeSubDomains",
"X-Content-Type-Options": "nosniff",
"X-Frame-Options": "DENY",
"Timing-Allow-Origin": "*",
"x-ms-apihub-cached-response": "true",
"x-ms-apihub-obo": "false",
"Date": "Fri, 12 May 2023 18:41:58 GMT",
"Content-Length": "525",
"Content-Type": "application/json",
"Expires": "-1"
},
"body": {
"status": 400,
"message": "{\"odata.error\":{\"code\":\"-1, Microsoft.SharePoint.Client.InvalidClientQueryException\",\"message\":{\"lang\":\"en-US\",\"value\":\"The expression \\\"web/lists/getByTitle(\\u2018Events\\u2019)/items\\\" is not valid.\"}}}\r\nclientRequestId: d484a3bc-0f90-461f-bf24-e4c7e9957adc\r\nserviceRequestId: 1e37b2a0-c079-3000-8b96-459e6976637e",
"source": "https://MyTenant.sharepoint.com/sites/Ian_DevSandBox/_api/web/lists/getByTitle(%E2%80%98Events%E2%80%99)/items",
"errors": []
}
}
Full Flow:
Http Request Parameters:
SharePoint List Column Data:
I'm not sure if my JSON fields are not matching with my list fields or if I'm missing a step with getting the calendar data - but I have also attached the information for all components of the workflow.
Ideally the approval would lead to creating an event on the Events Calendar using the supplied fields for the SharePoint list items.
Any insight would be super helpful!
It looks like in the URI you are using an apostrophe character instead of a single quote in the getbytitle method. I also see some space characters and quotes in the wrong places in the body payload.
Try to use the below
URI
_api/web/lists/getByTitle('Events')/items
Body
{
'__metadata': {'type': 'SP.Data.EventsListItem' },
'fAllDayEvent': 'true',
'EventDate': '2023-05-15',
'EndDate': '2023-05-16',
'Title': 'Test Event from Flow: IR',
'Category': 'SICK',
'Description': ''
}