Inhalte aufrufen

Profilbild

WebApi: Adding customers result in exception

webapi customers web-api

  • Bitte melden Sie sich an, um eine Antwort zu verfassen.
6 Antworten zu diesem Thema

#1 TripleNico

TripleNico

    Advanced Member

  • Members
  • PunktPunktPunkt
  • 124 Beiträge

Geschrieben: 17 January 2020 - 13:14

When calling POST /odata/v1/Customers i get e exception with the message "message":"The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.

 

The content i'm sending:

{

    "odata.type":"SmartStore.Core.Domain.Customers.Customer",
    "Company":"SomeCompany",
    "CustomerNumber":"4705",
    "Email":"customer@company.com",
    "FirstName":"CustomerFirstName",
    "FullName":"CustomerFullName",
    "LastName":"CustomerLastName"

}

 

For the record this customer doesn't exists yet.



#2 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3799 Beiträge

Geschrieben: 17 January 2020 - 15:18

Probably due to missing field values. A POST with the following data works for me:

{
"CustomerGuid":"28130f6e-7180-4291-bc61-4fcc4c4637f2",
"Username":"user@test.com",
"Email":"user@test.com",
"AdminComment":null,
"IsTaxExempt":false,
"AffiliateId":0,
"Active":true,
"IsSystemAccount":false,
"SystemName":null,
"LastIpAddress":"106.90.107.1",
"CreatedOnUtc":"2018-02-27T17:43:15",
"LastLoginDateUtc":"2018-02-27T17:43:15.123",
"LastActivityDateUtc":"2018-02-27T17:43:15.123"
}

Marcus Gesing

Smartstore AG


#3 TripleNico

TripleNico

    Advanced Member

  • Members
  • PunktPunktPunkt
  • 124 Beiträge

Geschrieben: 17 January 2020 - 15:34

Oké, that works but the users arn't visible in the Admin--> Customer overview?



#4 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3799 Beiträge

Geschrieben: 17 January 2020 - 16:57

Have you ever removed the filter for customer roles above the list?


Marcus Gesing

Smartstore AG


#5 TripleNico

TripleNico

    Advanced Member

  • Members
  • PunktPunktPunkt
  • 124 Beiträge

Geschrieben: 21 January 2020 - 08:44

Ah, thanks that was the problem. Is there a way to always show all users? Because now when i reload the page it only show "registered" users.

 

Also what would be the correct way to assign billing and shipping adresses to a users and also user roles?

 

EDIT:

I figured out how to add the customerroles but the billing and shipping adresses i still can figure out. I can add them to the endpoint /odata/v1/Addresses However i have no EntityID which i can refer to meaning that adding a address and then assigning it to a customer is no big deal but how do i update a customer billing and shipping adress ? I have todo a reversred lookup where i find the adres that matches the customer ID. Normally it other OData parts (like the LocalizedProperty) this is easilly done with the EntityID

 

EDIT 2:

 

Don't know if it's implemented but when i added a new customer including a Address i get a exception:

 

POST /odata/v1/Customers

{
   "Email":"Email",
   "IsTaxExempt":false,
   "Active":true,
   "IsSystemAccount":false,
   "LastIpAddress":"0.0.0.0",
   "CreatedOnUtc":"2020-01-23T10:04:03.1028061Z",
   "LastLoginDateUtc":"2020-01-23T10:04:03.1028061Z",
   "LastActivityDateUtc":"2020-01-23T10:04:03.1028061Z",
   "FirstName":"Firstname",
   "LastName":"Lastname",
   "FullName":"FullName",
   "Company":"Test CompanyName",
   "CustomerNumber":"123-456",
   "BillingAddress":{
      "FirstName":"Firstname",
      "LastName":"Lastname",
      "Email":"Email",
      "Company":"Test CompanyName",
      "City":"Nice City",
      "Address1":"Street + Housenumber",
      "ZipPostalCode":"1234AB",
      "PhoneNumber":"+123456789"
   }
}

 

Respone:

{
  "odata.error":{
    "code":"","message":{
      "lang":"en-US","value":"An error has occurred."
    },"innererror":{
      "message":"An error occurred while updating the entries. See the inner exception for details.","type":"System.Data.Entity.Infrastructure.DbUpdateException","stacktrace":"   at System.Data.Entity.Internal.InternalContext.SaveChanges()\r\n   at SmartStore.Data.ObjectContextBase.SaveChangesOperation.Execute()\r\n   at SmartStore.Data.ObjectContextBase.SaveChanges()\r\n   at SmartStore.Data.EfRepository`1.Insert(T entity)\r\n   at SmartStore.Web.Framework.WebApi.WebApiEntityController`2.CreateEntity(TEntity entity)\r\n   at SmartStore.Web.Framework.WebApi.WebApiEntityController`2.Post(TEntity entity)\r\n   at lambda_method(Closure , Object , Object[] )\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass6_2.<GetExecutor>b__2(Object instance, Object[] methodParameters)\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of
stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__6.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown
---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__3.MoveNext()\r\n--- End of stack trace from
previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Filters.AuthorizationFilterAttribute.<ExecuteAuthorizationFilterAsyncCore>d__3.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__15.MoveNext()","internalexception":{
        "message":"An error occurred while updating the entries. See the inner exception for details.","type":"System.Data.Entity.Core.UpdateException","stacktrace":"   at System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()\r\n   at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)\r\n   at System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions options, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction)\r\n   at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)\r\n   at System.Data.Entity.Core.Objects.ObjectContext.SaveChangesInternal(SaveOptions options, Boolean executeInExistingTransaction)\r\n   at System.Data.Entity.Internal.InternalContext.SaveChanges()","internalexception":{
          "message":"The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.\r\nThe statement has been terminated.","type":"System.Data.SqlClient.SqlException","stacktrace":"   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)\r\n   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)\r\n   at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)\r\n   at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()\r\n   at System.Data.SqlClient.SqlDataReader.get_MetaData()\r\n   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption,
 Boolean shouldCacheForAlwaysEncrypted)\r\n   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)\r\n   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)\r\n   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)\r\n   at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)\r\n   at SmartStore.Data.Caching.CachingCommand.ExecuteDbDataReader(CommandBehavior behavior)\r\n   at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TI
nterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)\r\n   at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext)\r\n   at System.Data.Entity.Core.Mapping.Update.Internal.DynamicUpdateCommand.Execute(Dictionary`2 identifierValues, List`1 generatedValues)\r\n   at System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()"
        }
      }
    }
  }
}


Bearbeitet von TripleNico, 23 January 2020 - 11:08,


#6 TripleNico

TripleNico

    Advanced Member

  • Members
  • PunktPunktPunkt
  • 124 Beiträge

Geschrieben: 23 January 2020 - 14:08

So i now created my code to add addresses to endpoint POST /odata/v1/Addresses() and then assign these addresses to customers at POST /odata/v1/Customers(CustomerID)/Addresses(AddressID) , but how in the world can i determine if it is the BillingAddress or ShippingAddress of the customer?



#7 stefanmueller

stefanmueller

    SmartStore AG

  • Administrators
  • 452 Beiträge

Geschrieben: 15 February 2021 - 09:16

Hi TripleNico, did you solved that last problem (23.01.2020)? Greetings, Stefan


Stefan



Auch markiert mit einem oder mehrerer dieser Schlüsselwörter: webapi, customers, web-api