GQL addUser Internal Server Error

addUser works find in the GraphQL console:

mutation addUser{addUser(userName:"username",pinCode:"1234",roleName:"Admin"){name}}

However, in Postan and C# the response is 500 Internal Server Error.

Query in Posman:
{"query":"mutation addUser{addUser(userName:"username",pinCode:"1234",roleName:"Admin"){name}}"}

Query in C#:
"{\"query\":\"mutation addUser{addUser(userName:\"username\",pinCode:\"1234\",roleName:\"Admin\"){name}}\"}"

Response:

{
  "message": "An error has occurred.",
  "exceptionMessage": "Object reference not set to an instance of an object.",
  "exceptionType": "System.NullReferenceException",
  "stackTrace": "   at Samba.Services.Implementations.LogService.LogError(Exception e, String userMessage) in C:\\Users\\Vehbi\\Documents\\Source\\Repos\\sambapos-v5-pro\\Samba.Services\\Implementations\\LogService.cs:line 24
     at Samba.MessagingServer.WindowsService.Controllers.GraphqlController.<Post>d__6.MoveNext()
     --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Threading.Tasks.TaskHelpersExtensions.<CastToObject>d__3`1.MoveNext()
     --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()
     --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()
     --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__2.MoveNext()
     --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"
}

What am I doing wrong?

Are you logging in and authenticating the app correctly? I can’t see the code for authenticating your app .

Yes. When swapped with another query I receive the expected response.

If it were an authentication issue, I would expect to see the following:

{
  "message": "Authorization has been denied for this request."
}

Try populating the Password field? Maybe its no parsing it correctly and something needs escaped?

I don’t see any password field for the addUser mutation.

Never mind, it was, indeed, an escape issue with quotes. I’ve been staring at too much text today.

Thanks for being a sounding board again.

1 Like