Issue with POST /api/v1/notification endpoint

By reading the PowerShell Universal API documentation, I saw that it is possible to create notifications using the POST /api/v1/notification endpoint.

However, when I try to create one, I receive this error message:
Object reference not set to an instance of an object.

The body that I pass in my request:

{
    "id": 15930,
    "title": "Invalid configuration: C:\\ProgramData\\UniversalAutomation\\Repository\\.universal\\roles.ps1",
    "description": "Cannot bind argument to parameter 'ClaimValue' because it is an empty string.",
    "createdTime": "2024-07-16T15:13:39.4567132Z",
    "createdBy": null,
    "job": null,
    "script": null,
    "dashboard": null,
    "license": null,
    "identity": null,
    "level": 2,
    "viewed": false
}

When I use an ID that already exists in the database, I get this error:
notification with that id: 1594 already exists, a unique id is required

{
    "id": 1594,
    "title": "Invalid configuration: C:\\ProgramData\\UniversalAutomation\\Repository\\.universal\\roles.ps1",
    "description": "Cannot bind argument to parameter 'ClaimValue' because it is an empty string.",
    "createdTime": "2024-07-16T15:13:39.4567132Z",
    "createdBy": null,
    "job": null,
    "script": null,
    "dashboard": null,
    "license": null,
    "identity": null,
    "level": 2,
    "viewed": false
}

So… can someone explain to me how to use the endpoint correctly?

I should mention that the token used by the API was created for the admin user with the Administrator role.

Thank you very much!!!

Product: PowerShell Universal
Version: 4.3.0

I’m not sure which documentation you’re referring to, but you can go to your PSU instance’s FQDN and access the Swagger page to show you the available APIs and examples to use.

For example, go to https://psuinstance.yourcompanydomain.com/swagger

Actually, I closely followed the Swagger, which has this example:

{
  "id": 0,
  "title": "string",
  "description": "string",
  "createdTime": "2024-07-17T08:07:20.704Z",
  "createdBy": "string",
  "job": {
    "id": 0,
    "createdTime": "2024-07-17T08:07:20.704Z",
    "startTime": "2024-07-17T08:07:20.704Z",
    "endTime": "2024-07-17T08:07:20.704Z",
    "status": 0,
    "output": "string",
    "script": {
      "id": 0,
      "name": "string",
      "oldName": "string",
      "description": "string",
      "createdTime": "2024-07-17T08:07:20.704Z",
      "manualTime": 0,
      "timeOut": 0,
      "commitId": "string",
      "content": "string",
      "scriptParameters": [
        {
          "id": 0,
          "name": "string",
          "displayName": "string",
          "type": "string",
          "script": "string",
          "defaultValue": "string",
          "required": true,
          "displayType": 0,
          "validValues": [
            "string"
          ],
          "helpText": "string",
          "parameterSet": "string",
          "resolvedDefaultValue": "string",
          "iValidateSetValuesGenerator": "string",
          "using": "string"
        }
      ],
      "identity": {
        "id": 0,
        "name": "string",
        "source": 0,
        "role": {
          "id": 0,
          "name": "string",
          "description": "string",
          "policy": "string",
          "claimType": "string",
          "claimValue": "string",
          "disabled": true,
          "readOnly": true,
          "defaultRoute": "string",
          "roles": [
            "string"
          ]
        },
        "roleName": "string",
        "roles": [
          "string"
        ],
        "credentialVault": "string",
        "password": "string",
        "localAccount": true,
        "oldPassword": "string",
        "settings": "string"
      },
      "status": 0,
      "tag": [
        {
          "id": 0,
          "name": "string",
          "color": "string",
          "description": "string",
          "editable": true,
          "readOnly": true
        }
      ],
      "fullPath": "string",
      "requiredPowerShellVersion": "string",
      "environment": "string",
      "errorAction": 0,
      "informationAction": 0,
      "verbose": true,
      "debug": true,
      "commitNotes": "string",
      "disableManualInvocation": true,
      "maxHistory": 0,
      "concurrentJobs": 0,
      "credential": "string",
      "accessControls": 0,
      "retryLimit": 0,
      "anonymous": true,
      "discardPipeline": true,
      "longDescription": "string",
      "links": [
        "string"
      ],
      "examples": [
        {
          "title": "string",
          "code": "string",
          "description": "string"
        }
      ],
      "defaultParameterSet": "string",
      "loadProfile": true,
      "workingDirectory": "string",
      "parameterSets": [
        "string"
      ],
      "folder": "string",
      "oldFolder": "string",
      "readOnly": true,
      "resolvedPath": "string",
      "module": "string",
      "command": "string",
      "role": [
        "string"
      ],
      "previousContent": "string"
    },
    "isScriptDeleted": true,
    "scriptFullPath": "string",
    "scriptCommitId": "string",
    "appToken": {
      "id": 0,
      "token": "string",
      "identity": {
        "id": 0,
        "name": "string",
        "source": 0,
        "role": {
          "id": 0,
          "name": "string",
          "description": "string",
          "policy": "string",
          "claimType": "string",
          "claimValue": "string",
          "disabled": true,
          "readOnly": true,
          "defaultRoute": "string",
          "roles": [
            "string"
          ]
        },
        "roleName": "string",
        "roles": [
          "string"
        ],
        "credentialVault": "string",
        "password": "string",
        "localAccount": true,
        "oldPassword": "string",
        "settings": "string"
      },
      "revoked": true,
      "role": "string",
      "created": "2024-07-17T08:07:20.705Z",
      "expiration": "2024-07-17T08:07:20.705Z",
      "revokedDate": "2024-07-17T08:07:20.705Z",
      "createdBy": {
        "id": 0,
        "name": "string",
        "source": 0,
        "role": {
          "id": 0,
          "name": "string",
          "description": "string",
          "policy": "string",
          "claimType": "string",
          "claimValue": "string",
          "disabled": true,
          "readOnly": true,
          "defaultRoute": "string",
          "roles": [
            "string"
          ]
        },
        "roleName": "string",
        "roles": [
          "string"
        ],
        "credentialVault": "string",
        "password": "string",
        "localAccount": true,
        "oldPassword": "string",
        "settings": "string"
      },
      "description": "string",
      "lastUsed": "2024-07-17T08:07:20.705Z"
    },
    "identity": {
      "id": 0,
      "name": "string",
      "source": 0,
      "role": {
        "id": 0,
        "name": "string",
        "description": "string",
        "policy": "string",
        "claimType": "string",
        "claimValue": "string",
        "disabled": true,
        "readOnly": true,
        "defaultRoute": "string",
        "roles": [
          "string"
        ]
      },
      "roleName": "string",
      "roles": [
        "string"
      ],
      "credentialVault": "string",
      "password": "string",
      "localAccount": true,
      "oldPassword": "string",
      "settings": "string"
    },
    "parentJob": "string",
    "parentLineNumber": 0,
    "debug": true,
    "computerName": "string",
    "port": 0,
    "processId": 0,
    "memoryBytes": 0,
    "runspaceId": 0,
    "activity": "string",
    "currentOperation": "string",
    "percentComplete": 0,
    "secondsRemaining": 0,
    "statusDescription": "string",
    "environment": "string",
    "agent": {
      "id": 0,
      "name": "string",
      "heartBeat": "2024-07-17T08:07:20.705Z",
      "status": 0,
      "grpcPort": 0,
      "loadingInfo": "string",
      "maintenance": true,
      "deleted": true,
      "loginErrorMessage": "string",
      "tags": [
        {
          "id": 0,
          "name": "string",
          "value": "string",
          "static": true,
          "computer": "string"
        }
      ],
      "hangfireServerId": "string",
      "hangfireWorkerCounter": 0,
      "version": "string"
    },
    "computer": {
      "id": 0,
      "name": "string",
      "heartBeat": "2024-07-17T08:07:20.705Z",
      "status": 0,
      "grpcPort": 0,
      "loadingInfo": "string",
      "maintenance": true,
      "deleted": true,
      "loginErrorMessage": "string",
      "tags": [
        {
          "id": 0,
          "name": "string",
          "value": "string",
          "static": true,
          "computer": "string"
        }
      ],
      "hangfireServerId": "string",
      "hangfireWorkerCounter": 0,
      "version": "string"
    },
    "errorAction": 0,
    "children": [
      "string"
    ],
    "jobOutput": [
      {
        "id": 0,
        "message": "string",
        "type": 0,
        "data": "string",
        "job": "string",
        "timestamp": "2024-07-17T08:07:20.705Z",
        "jobId": 0
      }
    ],
    "parameters": [
      {
        "id": 0,
        "name": "string",
        "displayName": "string",
        "type": "string",
        "job": "string",
        "value": "string",
        "variable": {
          "id": 0,
          "name": "string",
          "value": "string",
          "userName": "string",
          "password": "string",
          "secret": true,
          "vault": "string",
          "type": "string",
          "description": "string",
          "missingSecret": true,
          "disableRunAsSupport": true,
          "deleteSecret": true,
          "readOnly": true,
          "database": true,
          "role": [
            "string"
          ],
          "force": true
        },
        "isVariable": true,
        "displayType": 0,
        "jsonData": "string",
        "file": {
          "id": 0,
          "fileName": "string",
          "content": "string",
          "jobParameter": "string",
          "jobPipelineOutput": "string"
        },
        "fileId": 0,
        "formValue": "string"
      }
    ],
    "notes": "string",
    "credential": "string",
    "scheduleId": 0,
    "triggered": true,
    "trigger": "string",
    "accessToken": "string",
    "idToken": "string",
    "retryCount": 0,
    "tags": "string",
    "schedule": "string",
    "archived": true,
    "batch": true,
    "runId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
    "roles": "string",
    "refreshToken": "string",
    "jobFeedbacks": [
      {
        "id": 0,
        "data": "string",
        "message": "string",
        "complete": true,
        "identity": {
          "id": 0,
          "name": "string",
          "source": 0,
          "role": {
            "id": 0,
            "name": "string",
            "description": "string",
            "policy": "string",
            "claimType": "string",
            "claimValue": "string",
            "disabled": true,
            "readOnly": true,
            "defaultRoute": "string",
            "roles": [
              "string"
            ]
          },
          "roleName": "string",
          "roles": [
            "string"
          ],
          "credentialVault": "string",
          "password": "string",
          "localAccount": true,
          "oldPassword": "string",
          "settings": "string"
        },
        "job": "string",
        "secure": true
      }
    ],
    "notifications": [
      "string"
    ],
    "jobPipelineOutputs": [
      {
        "id": 0,
        "data": "string",
        "jsonData": "string",
        "job": "string",
        "file": {
          "id": 0,
          "fileName": "string",
          "content": "string",
          "jobParameter": "string",
          "jobPipelineOutput": "string"
        },
        "fileId": 0
      }
    ]
  },
  "script": {
    "id": 0,
    "name": "string",
    "oldName": "string",
    "description": "string",
    "createdTime": "2024-07-17T08:07:20.705Z",
    "manualTime": 0,
    "timeOut": 0,
    "commitId": "string",
    "content": "string",
    "scriptParameters": [
      {
        "id": 0,
        "name": "string",
        "displayName": "string",
        "type": "string",
        "script": "string",
        "defaultValue": "string",
        "required": true,
        "displayType": 0,
        "validValues": [
          "string"
        ],
        "helpText": "string",
        "parameterSet": "string",
        "resolvedDefaultValue": "string",
        "iValidateSetValuesGenerator": "string",
        "using": "string"
      }
    ],
    "identity": {
      "id": 0,
      "name": "string",
      "source": 0,
      "role": {
        "id": 0,
        "name": "string",
        "description": "string",
        "policy": "string",
        "claimType": "string",
        "claimValue": "string",
        "disabled": true,
        "readOnly": true,
        "defaultRoute": "string",
        "roles": [
          "string"
        ]
      },
      "roleName": "string",
      "roles": [
        "string"
      ],
      "credentialVault": "string",
      "password": "string",
      "localAccount": true,
      "oldPassword": "string",
      "settings": "string"
    },
    "status": 0,
    "tag": [
      {
        "id": 0,
        "name": "string",
        "color": "string",
        "description": "string",
        "editable": true,
        "readOnly": true
      }
    ],
    "fullPath": "string",
    "requiredPowerShellVersion": "string",
    "environment": "string",
    "errorAction": 0,
    "informationAction": 0,
    "verbose": true,
    "debug": true,
    "commitNotes": "string",
    "disableManualInvocation": true,
    "maxHistory": 0,
    "concurrentJobs": 0,
    "credential": "string",
    "accessControls": 0,
    "retryLimit": 0,
    "anonymous": true,
    "discardPipeline": true,
    "longDescription": "string",
    "links": [
      "string"
    ],
    "examples": [
      {
        "title": "string",
        "code": "string",
        "description": "string"
      }
    ],
    "defaultParameterSet": "string",
    "loadProfile": true,
    "workingDirectory": "string",
    "parameterSets": [
      "string"
    ],
    "folder": "string",
    "oldFolder": "string",
    "readOnly": true,
    "resolvedPath": "string",
    "module": "string",
    "command": "string",
    "role": [
      "string"
    ],
    "previousContent": "string"
  },
  "dashboard": {
    "id": 0,
    "name": "string",
    "filePath": "string",
    "baseUrl": "string",
    "environment": "string",
    "processId": 0,
    "processName": "string",
    "status": 0,
    "authenticated": true,
    "role": [
      "string"
    ],
    "content": "string",
    "grantAppToken": true,
    "debug": true,
    "disableAutoStart": true,
    "disableStartupLog": true,
    "sessionTimeout": 0,
    "idleTimeout": 0,
    "deployed": true,
    "autoDeploy": true,
    "description": "string",
    "credential": "string",
    "disableErrorToast": true,
    "maintenance": true,
    "tag": [
      {
        "id": 0,
        "name": "string",
        "color": "string",
        "description": "string",
        "editable": true,
        "readOnly": true
      }
    ],
    "template": "string",
    "readOnly": true,
    "verboseErrorMessages": true,
    "disableInteractiveHost": true,
    "module": "string",
    "command": "string",
    "favIcon": "string",
    "accessControls": 0,
    "hidden": true,
    "adminConsole": true,
    "onSessionTimeout": "string",
    "computerGroup": [
      "string"
    ],
    "startTime": "2024-07-17T08:07:20.705Z",
    "deployTime": "2024-07-17T08:07:20.705Z",
    "dashboardContent": {
      "id": 0,
      "title": "string",
      "theme": {},
      "content": "string"
    }
  },
  "license": {
    "id": 0,
    "licenseText": "string",
    "licensee": "string",
    "startDate": "2024-07-17T08:07:20.705Z",
    "endDate": "2024-07-17T08:07:20.705Z",
    "seats": 0,
    "product": "string",
    "status": "string",
    "developer": true,
    "readOnly": true
  },
  "identity": {
    "id": 0,
    "name": "string",
    "source": 0,
    "role": {
      "id": 0,
      "name": "string",
      "description": "string",
      "policy": "string",
      "claimType": "string",
      "claimValue": "string",
      "disabled": true,
      "readOnly": true,
      "defaultRoute": "string",
      "roles": [
        "string"
      ]
    },
    "roleName": "string",
    "roles": [
      "string"
    ],
    "credentialVault": "string",
    "password": "string",
    "localAccount": true,
    "oldPassword": "string",
    "settings": "string"
  },
  "level": 0,
  "viewed": true
}

And I really think that the error is not coming from my call because the status returned by the server is 500…

Finally, the GET method returns this kind of object:

{
"id": 1597,
"title": "Invalid configuration: C:\ProgramData\UniversalAutomation\Repository\.universal\roles.ps1",
"description": "Cannot bind argument to parameter 'ClaimValue' because it is an empty string.",
"createdTime": "2024-07-17T06:28:21.1744122Z",
"createdBy": null,
"job": null,
"script": null,
"dashboard": null,
"license": null,
"identity": null,
"level": 2,
"viewed": false
}

So I really don’t understand why it’s not working…

Have you tried setting the ID to 0 to see if the system will generate an ID itself? I haven’t tested it to see how it behaves on my setup.

Yes, I tried, and it creates exactly the same error:
Status: 500
Message: Object reference not set to an instance of an object.

:confused:

2 Likes

I just tested with both the built-in admin account as well as my personal admin account (which is an Azure AD account), and both result in the same error you see (Object reference not set to an instance of an object.).

Looks like a bug, to me. You can create an Issue on the GitHub tracker (Issues · ironmansoftware/powershell-universal · GitHub) so @adam is aware.

2 Likes

Crazy fast. Looks like Adam already fixed it for 4.3.3.

@ADFuji 4.3.3 is out now if you want to see whether or not it fixed this issue for you. I just tested myself, and was able to generate a notification without error.

1 Like

Hi, thanks for the reminder!

On my end, it works too (I’m a bit disappointed that it doesn’t update the counter directly on the admin panel x) )

@adam could this be an idea ?

1 Like

We should be able to add that. I think it just isn’t triggering the UI callback.

2 Likes