martinagrom / Office365Scripts

Some helpful PowerShell scripts for Microsoft Office 365
27 stars 18 forks source link

No parameter defined in the script or function for the input binding 'Request'. #2

Open dhx10000 opened 5 years ago

dhx10000 commented 5 years ago

Hi I was trying to follow the series:https://blog.atwork.at/post/2017/10/01/Provisioning-an-Office-365-group-with-an-approval-flow-and-Azure-functions-part-2. I copied the provisioning code from GitHub to my Azure function, copied the GroupName and UPN values in the Request Body, ran the script and received the following error:

Exception: No parameter defined in the script or function for the input binding 'Request'.

Stack: at Microsoft.Azure.Functions.PowerShellWorker.AzFunctionInfo..ctor(RpcFunctionMetadata metadata) in C:\projects\azure-functions-powershell-worker\src\FunctionInfo.cs:line 121 at Microsoft.Azure.Functions.PowerShellWorker.FunctionLoader.LoadFunction(FunctionLoadRequest request) in C:\projects\azure-functions-powershell-worker\src\FunctionLoader.cs:line 45 at Microsoft.Azure.Functions.PowerShellWorker.RequestProcessor.ProcessFunctionLoadRequest(StreamingMessage request) in C:\projects\azure-functions-powershell-worker\src\RequestProcessor.cs:line 186

chwilfing commented 5 years ago

Hi,

the error says your function.json file is not containing the request parameter. two reason from the top of my head.

=> the function.json was not copied and is missing the required binding

=> the function app you provisioned is of type V2 (which is the default currently) but the code presented in this sample does not support V2, it's a V1 Code and therefore you need to change the version back to V1.

chwilfing commented 5 years ago

PLZ - DO NOT PASTE Client Secrets in Error Messages.

the error message in your message above contains tenant id + app id + secret .. PLZ DELETE THIS APP ID.. immediatly as everybody is currently able to delete your groups in your tenant.. if this is your production tenant... your really F*** up..

will look at the error messag in a minute..

dhx10000 commented 5 years ago

thanks, its a test tenant, but I will repost

chwilfing commented 5 years ago

and to answer your question. the $req parameter is empty - so your functions.json is not correct or seems to be wrong, can you post the function.json your testing with?

dhx10000 commented 5 years ago

ok, I guess that's where my issue is. Maybe I missed those instructions but I did not add any json file so its using the default:

{ "bindings": [ { "authLevel": "function", "type": "httpTrigger", "direction": "in", "name": "Request", "methods": [ "get", "post" ] }, { "type": "http", "direction": "out", "name": "Response" } ] }

chwilfing commented 5 years ago

Yes - the name of the http trigger binding (which defines the name of the variable for the input) is 'request' .. so the line to read the data needs to reference this as a variable name like: (line 4)

$requestBody = Get-Content $Request -Raw | ConvertFrom-Json

admintgal commented 5 years ago

Hi there chwilfing,

I'm having the same issue. I've renamed my variable as stated in your post but I still get the same errors. Also it appears there is no longer a way to deploy a specific v1 application in Azure as they seemed to have merged them. Just curious what I can do to get past this error.

Thank you!

chwilfing commented 5 years ago

Hi admintgal,

the problem with V1 functions - there is no way to directly create a V1 functions since version V2 with Powershell support is in public preview. you need to create an empty V2 function and 'downgrade' it through the portal to V1 (as shown in the screenshot below)

image

After downgrading you can create the powershell function with http trigger. this will create the correct function.json and allow you to use

$requestBody` = Get-Content $Req -Raw | ConvertFrom-Json

where

$req

is the name of the http trigger in the function.json (sample:)

{
  "bindings": [
    {
      "name": "req",
      "type": "httpTrigger",
      "direction": "in",
      "authLevel": "function"
    },
    {
      "name": "res",
      "type": "http",
      "direction": "out"
    }
  ],
  "disabled": false
}
dhx10000 commented 5 years ago

The instructions for downgrading your Azure function is as follows:

chwilfing commented 5 years ago

Does this solve your issue?

admintgal commented 5 years ago

chwilfing & dhx10000

Thank you both! This worked like a charm for me!!!

dhx10000 commented 5 years ago

Without sharing confidential detail, can you share a sample functions.json file? I;m still having some problems but I think it has to do with that file not being properly configured.

chwilfing commented 5 years ago

The Function.json under: https://github.com/martinagrom/Office365Scripts/issues/2#issuecomment-492774499 is a working sample. Are you anything missing?

dhx10000 commented 5 years ago

HI,

this is my exact JSON: { "bindings": [ { "name": "Request", "type": "httpTrigger", "direction": "in", "authLevel": "function", "methods": [ "get", "post" ] }, { "name": "res", "type": "http", "direction": "out" } ], "disabled": false }

Line 4 from your code reads like this: $requestBody = Get-Content $Request -Raw | ConvertFrom-Json

The test JSON is exactly as you have it except of course with my own tenant image

When I run the script these are the errors I receive:

Cannot process command because of one or more missing mandatory parameters: Uri. at Initialize-Authorization, : line 81 at run.ps1: line 101

admintgal commented 5 years ago

So I actually ran through both scenarios, 1) creating a new empty function and 2) modifying the parameter mentioned by dhx10000

from there i did not change any of the code except for the following 1) commented out lines 11 and 12 for confidentiality 2) Changed line 51 as the variable was incorrect with what was defined in the app settings. I changed this from appsecret to clientkey 3)Changed line 4 $req variable to match the json file $request 4) Changed line 153 $res variable to match the json file $response

Now runs error free.

The errors I got were referencing empty values where yours is referencing incorrect syntax is appears. Perhaps try recopying the code and making the modifications mentioned above.

FurtureNinjaCoder commented 5 years ago

I am also facing same issues and have made changes as suggested above and get a Status: 500 Internal Server Error. Please help.

FurtureNinjaCoder commented 5 years ago

when changing to runtime version 1 I get "Status: 404 Not Found"

FurtureNinjaCoder commented 5 years ago

I have got a little further now with downgrading Azure Function to 1 and creating new but now get an error about Uri missing: Run Logs Errors and warnings Console Reconnect Copy logs Start Clear Expand 2019-11-14T16:48:44 Welcome, you are now connected to log-streaming service. The default timeout is 2 hours. Change the timeout with the App Setting SCM_LOGSTREAM_TIMEOUT (in seconds).

2019-11-14T16:48:58.081 [Info] Function started (Id=dbd06b2*) 2019-11-14T16:48:58.280 [Info] TenantID: ** AppID: * AppSecret: * 2019-11-14T16:48:58.280 [Info] GroupName: DeathStar EMail: DeathStar UPN: ***** 2019-11-14T16:48:58.452 [Error] : Cannot process command because of one or more missing mandatory parameters: Uri.

at Initialize-Authorization, : line 81

at run.ps1: line 101

at Initialize-Authorization, : line 83

at run.ps1: line 101

at Initialize-Authorization, : line 85

at run.ps1: line 101

at Initialize-Authorization, : line 87

at run.ps1: line 101

at run.ps1: line 305