webapix / mygls-sdk

An unofficial lightweight PHP SDK for the MyGLS (GLS logistics) REST API.
MIT License
28 stars 10 forks source link

GetParcelList #15

Closed OlegBodyansky closed 2 years ago

OlegBodyansky commented 2 years ago

GLS returns an error 400 when setting dates with a timezon if change Date::toJsonDate it works normally.

zsocakave commented 2 years ago

Hey there,

Can you describe it with more details? I tested it with different dates, and it works well.

One of my example:

GetParcelList example
OlegBodyansky commented 2 years ago

There is method Date::toJsonDate I have the same) I send a request whith a data "pickUpFrom":"2022-06-08 00:00:00", "pickUpTo": "2022-06-09 23:00:00", "printFrom":"2022-06-08 00:00:00", "printTo": "2022-06-09 23:00:00"

the method Date:toJsonDate convert it to 

`array:4 [`  

"PickupDateFrom" => "/Date(1654646400000+0000)/" "PickupDateTo" => "/Date(1654815600000+0000)/" "PrintDateFrom" => "/Date(1654646400000+0000)/" "PrintDateTo" => "/Date(1654815600000+0000)/" ]` In my case changing timezone gives the same results

Screenshot 2022-06-10 at 08 39 05
zsocakave commented 2 years ago

Sorry, but I can't reproduce this error. If you can share more details, code examples, or the full original / raw request data, I'll check it again.

Are you using the test or the production API? Which country?

OlegBodyansky commented 2 years ago

Are you using the test or the production API? Which country? This is test API and Slovenia country https://api.test.mygls.si/ParcelService.svc/json/GetParcelList

request part "PickupDateFrom" => "/Date(1654646400000+0000)/" "PickupDateTo" => "/Date(1654815600000+0000)/" "PrintDateFrom" => "/Date(1654646400000+0000)/" "PrintDateTo" => "/Date(1654815600000+0000)/"

    POST https://api.test.mygls.si/ParcelService.svc/json/GetParcelList
400
195 ms
POST /ParcelService.svc/json/GetParcelList HTTP/1.1
Content-Type: application/json
User-Agent: PostmanRuntime/7.29.0
Accept: */*
Postman-Token: b6cc9807-a33f-431e-be47-c2cc94b38e3f
Host: api.test.mygls.si
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 1062
Cookie: ASP.NET_SessionId=q23yspjlzcn4xsz2u12pri5m

{
"PickupDateFrom" : "/Date(1654646400000+0000)/",
"PickupDateTo" : "/Date(1654815600000+0000)/",
"PrintDateFrom" : "/Date(1654646400000+0000)/",
"PrintDateTo" : "/Date(1654815600000+0000)/",
"Username": " --email--",
"Password": [---hashed pass---]
}

HTTP/1.1 400 Bad Request
Cache-Control: private
Content-Type: text/html
Server: Microsoft-IIS/10.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Fri, 10 Jun 2022 08:54:21 GMT
Content-Length: 2926

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Request Error</title>
<style>BODY { color: #000000; background-color: white; font-family: Verdana; margin-left: 0px; margin-top: 0px; } #content { margin-left: 30px; font-size: .70em; padding-bottom: 2em; } A:link { color: #336699; font-weight: bold; text-decoration: underline; } A:visited { color: #6699cc; font-weight: bold; text-decoration: underline; } A:active { color: #336699; font-weight: bold; text-decoration: underline; } .heading1 { background-color: #003366; border-bottom: #336699 6px solid; color: #ffffff; font-family: Tahoma; font-size: 26px; font-weight: normal;margin: 0em 0em 10px -20px; padding-bottom: 8px; padding-left: 30px;padding-top: 16px;} pre { font-size:small; background-color: #e5e5cc; padding: 5px; font-family: Courier New; margin-top: 0px; border: 1px #f0f0e0 solid; white-space: pre-wrap; white-space: -pre-wrap; word-wrap: break-word; } table { border-collapse: collapse; border-spacing: 0px; font-family: Verdana;} table th { border-right: 2px white solid; border-bottom: 2px white solid; font-weight: bold; background-color: #cecf9c;} table td { border-right: 2px white solid; border-bottom: 2px white solid; background-color: #e5e5cc;}</style>
</head>
<body>
<div id="content">
<p class="heading1">Request Error</p>
<p>The server encountered an error processing the request. The exception message is 'Error generated for warning 'Microsoft.EntityFrameworkCore.Infrastructure.DetachedLazyLoadingWarning': An attempt was made to lazy-load navigation property 'Service' on detached entity of type 'ParcelServiceProxy'. Lazy-loading is not supported for detached entities or entities that are loaded with 'AsNoTracking()'. This exception can be suppressed or logged by passing event ID 'CoreEventId.DetachedLazyLoadingWarning' to the 'ConfigureWarnings' method in 'DbContext.OnConfiguring' or 'AddDbContext'.'. See server logs for more details. The exception stack trace is: </p>
<p> at DynamicModule.ns.Wrapped_ParcelService_fc052c5eeac646c6914cd8dad81ca376.GetParcelList(GetParcelListRequest getParcelListRequest)
at SyncInvokeGetParcelList(Object , Object[] , Object[] )
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]&amp; outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp; rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp; rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc&amp; rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)</p>
</div>
</body>
</html>
zsocakave commented 2 years ago

I think this is an error in the MyGLS database, a Parcel object may have an invalid Service object and this generates the error message.

Can you check the results with different dates?

Martin-1182 commented 2 years ago
Webapix\GLS\Requests\GetParcelList^ {
  #endpoint: "GetParcelList"
  -pickupDateFrom: null
  -pickupDateTo: null
  -printDateFrom: DateTime @1655185542 {#2573
    date: 2022-06-14 07:45:42.0 Europe/Bratislava (+02:00)
  }
  -printDateTo: DateTime @1655703942 {#2571
    date: 2022-06-20 07:45:42.0 Europe/Bratislava (+02:00)
  }
  #method: "POST"
}

 $client = new Client(new GuzzleClient());

 /** @var \Webapix\GLS\Responses\GetParcelList $response */
$response = $client->on(GlsAccount::account())->request($request);

Hi I have the same problem GLS returns an error 400. Is it a GLS error?

zsocakave commented 2 years ago

Hi! I can't reproduce this error in my account. I use dates with timezone and I got HTTP 200 response. I think we use the correct payload format, we follow the documentation.

Can you contact GLS support? ( connect@gls-hungary.com ). They can look at the logs and help figure out what's going on.