tfsaggregator / aggregator-cli

A new version of Aggregator aiming at Azure DevOps (ex Visual Studio Team Services)
https://tfsaggregator.github.io/
Apache License 2.0
73 stars 32 forks source link

Error 500 When Call Azure Function Rest API via PowerShell #248

Closed rotda closed 2 years ago

rotda commented 2 years ago

Hello I try , to call the Azure Functions Rest API with PS. I use the attached JSON in the Body but I always get an 500 Error.

`$JSON = @{

"eventType"= "workitem.updated"
"publisherId"= "tfs"
"resource"= @{
  "url"= "https://xxx.visualstudio.com/1123456-67889/_apis/wit/workItems/$($result.workItems[$i].id)"
  "id"= $($result.workItems[$i].id)
  "workItemId"= $($result.workItems[$i].id)
  "fields"= @{
    "System.TeamProject"= "YYY"
  }
  "revision"= @{
    "fields"= @{
      "System.TeamProject"= "YYY"
    }
  }
}
"resourceContainers"= @{
  "collection"= @{
    "baseUrl"= "https://xxx.visualstudio.com/"
  }
  "project"= @{
    "id"= "1123456-67889"
  }
}

} | ConvertTo-Json -Depth 5`

giuliov commented 2 years ago

The JSON payload must convert to Microsoft.VisualStudio.Services.ServiceHooks.WebApi.WebHookEvent; if you miss some fields or the data is fake could be that you do not have a neat error. In any case, you should see more details in the logs (see https://tfsaggregator.github.io/docs/v3/setup/production/#azure-production-monitoring).

rotda commented 2 years ago

Hi , WebHookEvent in PS ?

$result = Invoke-RestMethod -Uri https://xxx.azurewebsites.net/api/xx -Method POST  -Body $JSON  -Headers @{
   'x-functions-key' = 'xxxxx/a/YprrlJlxeVW0g==' 
   'Content-Type' = 'application/json; charset=utf-8'
  } 

Error :

2021-12-17 15:19:08.383 Aggregator v1.1.0 executing rule 'test3' Information 2021-12-17 15:19:08.985 Object reference not set to an instance of an object. Error 2021-12-17 15:19:08.985 Executed 'Functions.test3' (Failed, Id=600c1ade-ed88-4194-b906-7dcbac9b9470, Duration=1165ms) Error

giuliov commented 2 years ago

You get an error very early, so I suspect that the payload isn't good for some reason. Here is an example of a valid payload for workitem.updated:

{
  "subscriptionId": "REDACTED-GUID",
  "notificationId": 1,
  "id": "REDACTED-GUID",
  "eventType": "workitem.updated",
  "publisherId": "tfs",
  "message": {
    "text": "Task #18 (tatata1) updated by Giulio Vian\r\n(https://dev.azure.com/REDACTED-ORGANIZATION/web/wi.aspx?pcguid=REDACTED-GUID&id=18)",
    "html": "<a href=\"https://dev.azure.com/REDACTED-ORGANIZATION/web/wi.aspx?pcguid=REDACTED-GUID&amp;id=18\">Task #18</a> (tatata1) updated by Giulio Vian",
    "markdown": "[Task #18](https://dev.azure.com/REDACTED-ORGANIZATION/web/wi.aspx?pcguid=REDACTED-GUID&id=18) (tatata1) updated by Giulio Vian"
  },
  "detailedMessage": {
    "text": "Task #18 (tatata1) updated by Giulio Vian\r\n(https://dev.azure.com/REDACTED-ORGANIZATION/web/wi.aspx?pcguid=REDACTED-GUID&id=18)\r\n\r\n",
    "html": "<a href=\"https://dev.azure.com/REDACTED-ORGANIZATION/web/wi.aspx?pcguid=REDACTED-GUID&amp;id=18\">Task #18</a> (tatata1) updated by Giulio Vian<ul></ul>",
    "markdown": "[Task #18](https://dev.azure.com/REDACTED-ORGANIZATION/web/wi.aspx?pcguid=REDACTED-GUID&id=18) (tatata1) updated by Giulio Vian\r\n\r\n"
  },
  "resource": {
    "id": 2,
    "workItemId": 18,
    "rev": 2,
    "revisedBy": {
      "id": "REDACTED-GUID",
      "name": "Giulio Vian <REDACTED-EMAIL>",
      "displayName": "Giulio Vian",
      "url": "https://app.vssps.visualstudio.com/AREDACTED-GUID/_apis/Identities/REDACTED-GUID",
      "_links": {
        "avatar": {
          "href": "https://dev.azure.com/REDACTED-ORGANIZATION/_apis/GraphProfile/MemberAvatars/aad.MTc3MDAzODQtZjk2ZC03YjMwLWE0YTctYWZjYTVmYTZkNWU0"
        }
      },
      "uniqueName": "REDACTED-EMAIL",
      "imageUrl": "https://dev.azure.com/REDACTED-ORGANIZATION/_api/_common/identityImage?id=REDACTED-GUID",
      "descriptor": "aad.MTc3MDAzODQtZjk2ZC03YjMwLWE0YTctYWZjYTVmYTZkNWU0"
    },
    "revisedDate": "9999-01-01T00:00:00Z",
    "fields": {
      "System.Rev": {
        "oldValue": 1,
        "newValue": 2
      },
      "System.AuthorizedDate": {
        "oldValue": "2018-10-29T18:40:18.527Z",
        "newValue": "2018-10-29T18:42:55.823Z"
      },
      "System.RevisedDate": {
        "oldValue": "2018-10-29T18:42:55.823Z",
        "newValue": "9999-01-01T00:00:00Z"
      },
      "System.ChangedDate": {
        "oldValue": "2018-10-29T18:40:18.527Z",
        "newValue": "2018-10-29T18:42:55.823Z"
      },
      "System.Watermark": {
        "oldValue": 63,
        "newValue": 64
      },
      "System.Description": {
        "oldValue": "<div>some descr<br></div>",
        "newValue": "<div>some description<br></div>"
      }
    },
    "_links": {
      "self": {
        "href": "https://dev.azure.com/REDACTED-ORGANIZATION/REDACTED-GUID/_apis/wit/workItems/18/updates/2"
      },
      "workItemUpdates": {
        "href": "https://dev.azure.com/REDACTED-ORGANIZATION/REDACTED-GUID/_apis/wit/workItems/18/updates"
      },
      "parent": {
        "href": "https://dev.azure.com/REDACTED-ORGANIZATION/REDACTED-GUID/_apis/wit/workItems/18"
      },
      "html": {
        "href": "https://dev.azure.com/REDACTED-ORGANIZATION/web/wi.aspx?pcguid=REDACTED-GUID&id=18"
      }
    },
    "url": "https://dev.azure.com/REDACTED-ORGANIZATION/REDACTED-GUID/_apis/wit/workItems/18/updates/2",
    "revision": {
      "id": 18,
      "rev": 2,
      "fields": {
        "System.AreaPath": "WorkItemTracking2",
        "System.TeamProject": "WorkItemTracking2",
        "System.IterationPath": "WorkItemTracking2",
        "System.WorkItemType": "Task",
        "System.State": "To Do",
        "System.Reason": "New task",
        "System.CreatedDate": "2018-10-29T18:40:18.527Z",
        "System.CreatedBy": "Giulio Vian <REDACTED-EMAIL>",
        "System.ChangedDate": "2018-10-29T18:42:55.823Z",
        "System.ChangedBy": "Giulio Vian <REDACTED-EMAIL>",
        "System.CommentCount": 0,
        "System.Title": "tatata1",
        "Microsoft.VSTS.Common.StateChangeDate": "2018-10-29T18:40:18.527Z",
        "Microsoft.VSTS.Common.Priority": 2,
        "System.Description": "<div>some description<br></div>"
      },
      "_links": {
        "self": {
          "href": "https://dev.azure.com/REDACTED-ORGANIZATION/REDACTED-GUID/_apis/wit/workItems/18/revisions/2"
        },
        "workItemRevisions": {
          "href": "https://dev.azure.com/REDACTED-ORGANIZATION/REDACTED-GUID/_apis/wit/workItems/18/revisions"
        },
        "parent": {
          "href": "https://dev.azure.com/REDACTED-ORGANIZATION/REDACTED-GUID/_apis/wit/workItems/18"
        }
      },
      "url": "https://dev.azure.com/REDACTED-ORGANIZATION/REDACTED-GUID/_apis/wit/workItems/18/revisions/2"
    }
  },
  "resourceVersion": "1.0",
  "resourceContainers": {
    "collection": {
      "id": "REDACTED-GUID",
      "baseUrl": "https://dev.azure.com/REDACTED-ORGANIZATION/"
    },
    "account": {
      "id": "REDACTED-GUID",
      "baseUrl": "https://dev.azure.com/REDACTED-ORGANIZATION/"
    },
    "project": {
      "id": "REDACTED-GUID",
      "baseUrl": "https://dev.azure.com/REDACTED-ORGANIZATION/"
    }
  },
  "createdDate": "2018-10-29T18:42:58.5808921Z"
}

BTW Have you tried invoke.rule ?