Creating Document Libraries through Flow with a single API call - json

My company currently have client SharePoint sites hosted on our O365 tenant, and previously whenever a new client was bought on board we'd create a SharePoint site for them using the GUI or Powershell, but in the interest of making things a little easier in the long run I'm now in the process of trying to automate site creation for any new clients that join us - Historically, all sites have been designed the same with more or less the same structure, the only difference being the files themselves. I've managed to automate the bulk of the SharePoint site creation through flow (Creating the site, Hub site linkage, ownership of site, group membership, external access, etc.) but I'm having trouble with creating the document libraries on newly created sites. There are 8 libraries overall, and whilst I have actually worked out how to create them each individually using the 'Send a HTTP request to SharePoint" action (I'm quite new to Flow and all this!), I'd like to try and use MS Graph and JSON batching instead, so I can create all 8 libraries in a single API call.
I've tested my JSON on the MS Graph Explorer, which works and and creates the libraries on a specified client site as expected, but when I try and do it through Flow, I get the below error and I'm not sure where I'm going wrong:
Error
The error message singles out the Headers, but I'm not sure what the issue is?
See below the HTTP action in the Flow:
HTTP Action
{
"inputs": {
"method": "POST",
"uri": "https://graph.microsoft.com/v1.0/$batch",
"headers": {
"content-type": "application/json;odata=verbose",
"authorization": "#{body('Parse_JSON')?['token_type']} #{body('Parse_JSON')?['access_token']}"
},
"body": {
"requests": [
{
"id": "1",
"method": "POST",
"url": "/sites/devsite.sharepoint.com:/sites/BSS:/lists",
"body": {
"displayName": "Management",
"list": {
"template": "documentLibrary"
}
},
"headers": {
"content-type": "application/json"
}
},
{
"id": "2",
"method": "POST",
"url": "/sites/devsite.sharepoint.com:/sites/BSS:/lists",
"body": {
"displayName": "Employees",
"list": {
"template": "documentLibrary"
}
},
"headers": {
"content-type": "application/json"
}
},
{
"id": "3",
"method": "POST",
"url": "/sites/devsite.sharepoint.com:/sites/BSS:/lists",
"body": {
"displayName": "Work Activities",
"list": {
"template": "documentLibrary"
}
},
"headers": {
"content-type": "application/json"
}
},
{
"id": "4",
"method": "POST",
"url": "/sites/devsite.sharepoint.com:/sites/BSS:/lists",
"body": {
"displayName": "Work Equipment",
"list": {
"template": "documentLibrary"
}
},
"headers": {
"content-type": "application/json"
}
},
{
"id": "5",
"method": "POST",
"url": "/sites/devsite.sharepoint.com:/sites/BSS:/lists",
"body": {
"displayName": "Substances",
"list": {
"template": "documentLibrary"
}
},
"headers": {
"content-type": "application/json"
}
},
{
"id": "6",
"method": "POST",
"url": "/sites/devsite.sharepoint.com:/sites/BSS:/lists",
"body": {
"displayName": "Workplaces",
"list": {
"template": "documentLibrary"
}
},
"headers": {
"content-type": "application/json"
}
},
{
"id": "7",
"method": "POST",
"url": "/sites/devsite.sharepoint.com:/sites/BSS:/lists",
"body": {
"displayName": "HR",
"list": {
"template": "documentLibrary"
}
},
"headers": {
"content-type": "application/json"
}
},
{
"id": "8",
"method": "POST",
"url": "/sites/devsite.sharepoint.com:/sites/BSS:/lists",
"body": {
"displayName": "Quality",
"list": {
"template": "documentLibrary"
}
},
"headers": {
"content-type": "application/json"
}
}
]
}
}
}
Would anyone be able to offer any insight?
Thank you!

"Weird, works for me"
Header parameters are correct (case insensitive) as well as request's body.
MS Flow sometimes behave totally unexplainably.
Please try again creating temporary flow with OAuth2 token HTTP request and Graph API HTTP request only.
For token JSON parsing purposes I used this schema:
{
"type": "object",
"properties": {
"token_type": {
"type": "string"
},
"expires_in": {
"type": "integer"
},
"ext_expires_in": {
"type": "integer"
},
"access_token": {
"type": "string"
}
}
}

Related

Use JSON schema check on POST request with WireMock

I'm using WireMock (Docker) docker.io/rodolpheche/wiremock:2.27.2-alpine. I set it up via Docker Compose and everything works flawlessly.
I'm trying to set up a stub/mapping to check the JSON input against the corresponding JSON schema. Basically, this is the stub/mapping:
{
"name": "Create Character Stub",
"request": {
"headers": {
"accept": {
"caseInsensitive": true,
"equalTo": "application/json"
},
"content-type": {
"caseInsensitive": true,
"equalTo": "application/json"
}
},
"method": "POST",
"url": "/api/characters",
"body": {
// [start] I made this up, but that's what I'm trying to achieve
"type": "JSON_SCHEMA",
"location": ""schemas/create-character.json""
// [end]
}
},
"response": {
"headers": {
"location": "{{ request.path }}/{{ randomValue type='UUID' }}"
},
"status": 201,
"transformers": ["response-template"]
}
}
...and this is (an excerpt of) the JSON schema:
{
"$schema": "http://json-schema.org/draft/2019-09/schema#",
"type": "object",
"description": "Character entity",
"properties": {
"first_name": {
"type": "string",
"description": ""
},
"last_name": {
"type": "string",
"description": ""
},
"age": {
"type": "number",
"description": ""
}
},
"additionalProperties": false,
"required": ["first_name", "last_name", "age"]
}
Is there a way to accomplish this with WireMock? I've been searching for something like that for a while. The closer I've found is to use JSON path, but that's not quite the same as checking for a proper schema — and could be tedious task with long JSON requests.
I searched through the issues in the WireMock's GitHub repository, but I can only see this one (closed by the way). Still, I don't see a way to do exactly what I'm looking for. I just have as input a JSON schema.

Request parameter RefreshType is not in correct format

I try to process my Azure Analysis Service Cube via logic APP:
In HTTP action I have the following body:
{
"inputs": {
"method": "POST",
"uri": "https://northeurope.asazure.windows.net/servers/xxx/models/xxx/refreshes",
"body": {
"refresh": {
"objects": [
{
"database": "ModelName",
"table": "TableName"
}
],
"type": "full"
}
},
"authentication": {
"type": "ActiveDirectoryOAuth",
"authority": "https://login.windows.net",
"tenant": "xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx",
"audience": "https://*.asazure.windows.net",
"clientId": "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx",
"secret": "xxxxYjxx7y5xxskHxxxxxxznxxxxxxxxODX+xxxxxxxx"
}
}
}
After runningthis logic app, I get the following error:
{
"statusCode": 400,
"headers": {
"Strict-Transport-Security": "max-age=xxxxxx00; includeSubDomains",
"x-ms-root-activity-id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx",
"x-ms-current-utc-date": "2/7/2019 9:25:05 AM",
"x-ms-xmlaerror-extended": "Request parameter RefreshType is not in correct format.",
"Date": "Thu, 07 Feb 2019 09:25:05 GMT",
"Server": "Microsoft-HTTPAPI/2.0",
"Content-Length": "294",
"Content-Type": "application/json; charset=utf-8"
},
"body": {
"code": "BadRequest",
"subCode": 2,
"message": "Request parameter RefreshType is not in correct format.",
"timeStamp": "2019-02-07T09:25:05.4650388Z",
"httpStatusCode": 400,
"details": [
{
"code": "RootActivityId",
"message": "353ab74e-2793-4ee5-954f-819c851f4cb6"
},
{
"code": "Param1",
"message": "RefreshType"
}
]
}
}
Do you have any Idea, why I get this error message? and How can I solve this problem
Refresh Type is an ENUM which only takes values from below list, Can you make the type to Full and check if works:
Hope it helps.

Azure API Management latency of over 5 seconds

We're using API Management to execute an always on function app that, in turn, is calling Azure Search. The function app responds within 100 ms (usually well under), but API Management intermittently takes 3 to 8 seconds to process. I've gone through the trace and found the delay is consistently in the backend step in which API Management is processing the results (sample trace for backend below). The returned data in this case is 664 bytes. Does anyone know what may cause this and, more importantly, how to remove this latency?
The Azure API Management instance, function app, and Azure Search are all in the same region.
"backend": [
{
"source": "forward-request",
"timestamp": "2018-10-11T13:33:54.0578250Z",
"elapsed": "00:00:00.0005890",
"data": {
"message": "Request is being forwarded to the backend service. Timeout set to 300 seconds",
"request": {
"method": "GET",
"url": "https://ommitted.azurewebsites.net/api/HollanderSearch/?hollander=125-222L&websiteId=1&retrieveAllProductNames=false&onlyRetrieveProductNames=true&numRecsToRetrieve =25&code=%2Fxu1iz0EimDFnOUvhDVaM4ZejfaW7umV3somaIDCeWJYI5RMIfNnNg%3D%3D&keyword=125-222L",
"headers": [
{
"name": "Ocp-Apim-Subscription-Key",
"value": "ommitted"
},
{
"name": "Postman-Token",
"value": "9e809f11-6e63-4422-8c3f-d61962cec6ac"
},
{
"name": "Cache-Control",
"value": "no-cache"
},
{
"name": "Accept",
"value": "*/*"
},
{
"name": "Accept-Encoding",
"value": "gzip,deflate"
},
{
"name": "User-Agent",
"value": "PostmanRuntime/7.3.0"
},
{
"name": "X-Forwarded-For",
"value": "omitted"
}
]
}
}
},
{
"source": "forward-request",
"timestamp": "2018-10-11T13:33:59.6717259Z",
"elapsed": "00:00:05.6045857",
"data": {
"response": {
"status": {
"code": 200,
"reason": "OK"
},
"headers": [
{
"name": "Pragma",
"value": "no-cache"
},
{
"name": "Transfer-Encoding",
"value": "chunked"
},
{
"name": "Content-Encoding",
"value": "gzip"
},
{
"name": "Vary",
"value": "Accept-Encoding"
},
{
"name": "Cache-Control",
"value": "no-cache"
},
{
"name": "Content-Type",
"value": "application/json; charset=utf-8"
},
{
"name": "Date",
"value": "Thu, 11 Oct 2018 13:33:59 GMT"
},
{
"name": "Expires",
"value": "-1"
},
{
"name": "Set-Cookie",
"value": "ARRAffinity=8065e5ea6c0774f598f30cd38416a122cd6afe1af34a15c7f6430e1a0fe9924c;Path=/;HttpOnly;Domain=omitted-dev.azurewebsites.net"
},
{
"name": "Server",
"value": "Microsoft-IIS/10.0"
},
{
"name": "X-Powered-By",
"value": "ASP.NET"
}
]
}
}
},
{
"source": "decompressor",
"timestamp": "2018-10-11T13:33:59.6717259Z",
"elapsed": "00:00:05.6045976",
"data": "Content-Encoding header with value `gzip` detected in message headers. Content re-compression may require to correctly apply content modification policies."
}
]

Logic Apps - Get Email Infos from http request body with json

How can you determine the email data from a request body and integrate it into the Outlook function?
You can easily send the whole Body of the response from the Http request into the Body of the Email using outlook.
See below
Select the body from the HTTP request and pass it to the email body (as a raw JSON)
The corresponding code will look like
{
"$connections": {
"value": {
"office365": {
"connectionId": "/subscriptions/....../Microsoft.Web/connections/office365",
"connectionName": "office365",
"id": "/subscriptions/......./Microsoft.Web/locations/southindia/managedApis/office365"
}
}
},
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Send_an_email": {
"inputs": {
"body": {
"Body": "#{triggerBody()}",
"Subject": "test",
"To": "abc#abc.com"
},
"host": {
"connection": {
"name": "#parameters('$connections')['office365']['connectionId']"
}
},
"method": "post",
"path": "/Mail"
},
"runAfter": {},
"type": "ApiConnection"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"manual": {
"inputs": {
"method": "POST",
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
}
}

Bluemix WorkLoad Scheduler Process creation REST API does not accept queryparameters and headers in restfulstep

I am using the Bluemix Workload Scheduler REST API to create Processes with a Scheduled Trigger having a oneTimeProperty and a startDate.
Additionally the json i am sending also has a restfulStep.
The issue i have is, that no matter how i provide the "queryParameters" and "headers" for the restfulStep, they are not accepted/configured in the process after the successful process creation.
Here is the json i am using:
{
"name": "my process name",
"processlibraryid": 1234,
"processstatus": true,
"triggers": [
{
"name": "Scheduled Trigger",
"triggerType": "OnceTrigger",
"oneTimeProperty": {
"startDate": "TIMEVALUE"
}
}
],
"steps": [
{
"restfulStep": {
"agent": "AGENTNAME}",
"action": {
"uri": "MYCUSTOMURL",
"contentType": "application/json",
"method": "POST",
"verifyHostname": true,
"queryParameters": [
["param1", "value1"],
["param2", "value2"]
],
"headers": [
["param3", "param4"]
],
"numberOfRetries": 3,
"retryIntervalSeconds": 30
},
"authdata": {
"username": "USERNAME",
"password": "PASSWORD"
},
"input": {
"input": "",
"isFile": false
}
}
}
]
}
issue has been fixed with last Workload Scheduler upgrade.
Could you try using a Json like the following?
{
"name": "myname",
"processlibraryid": <1234>,
"processstatus": false,
"triggers": [
{
"name": "Scheduled Trigger",
"triggerType": "OnceTrigger",
"oneTimeProperty": {
"startDate": "2016-12-16T10:30:43.218Z"
}
}
],
"steps": [
{
"restfulStep": {
"agent": "<MY_AGENT_NAME>",
"action": {
"uri": "<MY_URL>",
"contentType": "application/json",
"method": "GET",
"verifyHostname": true,
"queryParameters": [
["param1", "value1"],
["param2", "value2"]
],
"headers": [
["Accept", "application/json"],
["User-Agent", "Mozilla/5.0 "]
],
"numberOfRetries": 3,
"retryIntervalSeconds": 30
},
"authdata": {
"username": "USERNAME",
"password": "PASSWORD"
},
"input": {
"input": "",
"isFile": false
}
}
}
]
}
Regards
Andrea I
your json is correct but there is a little bug in Workload Scheduler service.
A fix will be released by the end of December.
As workaround, you could use Application Lab in order to create your Restful step. In addition, you could append the queryParameters to your uri address.
At the moment, there is no workarounds for headers.
If you find other issue using the service, do not hesitate to post your comments.
Thanks!
Andrea I