Erro na Logistics API ao tentar atualizar valores de frete

Quando tento utilizar o endpoint Create/update freight values ele me retorna o seguinte erro:

object(stdClass)#4 (1) {
  ["error"]=>
  object(stdClass)#1 (3) {
    ["code"]=>
    string(14) "internal_error"
    ["message"]=>
    string(53) "Object reference not set to an instance of an object."
    ["exception"]=>
    object(stdClass)#2 (12) {
      ["ClassName"]=>
      string(48) "Vtex.Practices.Net.Http.VtexHttpRequestException"
      ["Message"]=>
      string(53) "Object reference not set to an instance of an object."
      ["Data"]=>
      NULL
      ["InnerException"]=>
      object(stdClass)#3 (12) {
        ["ClassName"]=>
        string(29) "System.NullReferenceException"
        ["Message"]=>
        string(53) "Object reference not set to an instance of an object."
        ["Data"]=>
        NULL
        ["InnerException"]=>
        NULL
        ["HelpURL"]=>
        NULL
        ["StackTraceString"]=>
        string(2902) "   at Vtex.Commerce.Logistics.Service.FreightServices.d__4.MoveNext() in D:\pachamama\BuildAgent\work\3d353e624ca31c80\src\Vtex.Commerce.Logistics.Service\Configuration\FreightServices.cs:line 81
--- 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 Vtex.Commerce.Logistics.WebApi.FreightValueController.d__7.MoveNext() in D:\pachamama\BuildAgent\work\3d353e624ca31c80\src\Vtex.Commerce.Logistics.WebApi\Controllers\Configuration\FreightValueController.cs:line 303
--- 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.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.ApiControllerActionInvoker.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.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 Vtex.Commerce.Logistics.WebApi.AccessControlFilter.d__7.MoveNext() in D:\pachamama\BuildAgent\work\3d353e624ca31c80\src\Vtex.Commerce.Logistics.WebApi\AccessControlFilter.cs:line 140
--- 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.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.Controllers.ExceptionFilterResult.d__0.MoveNext()"
        ["RemoteStackTraceString"]=>
        NULL
        ["RemoteStackIndex"]=>
        int(0)
        ["ExceptionMethod"]=>
        string(196) "8
MoveNext
Vtex.Commerce.Logistics.Service, Version=6.10.0.3659, Culture=neutral, PublicKeyToken=null
Vtex.Commerce.Logistics.Service.FreightServices+d__4
Void MoveNext()"
        ["HResult"]=>
        int(-2147467261)
        ["Source"]=>
        string(31) "Vtex.Commerce.Logistics.Service"
        ["WatsonBuckets"]=>
        NULL
      }
      ["HelpURL"]=>
      NULL
      ["StackTraceString"]=>
      NULL
      ["RemoteStackTraceString"]=>
      NULL
      ["RemoteStackIndex"]=>
      int(0)
      ["ExceptionMethod"]=>
      NULL
      ["HResult"]=>
      int(-2146233088)
      ["Source"]=>
      NULL
      ["WatsonBuckets"]=>
      NULL
    }
  }
}

O que pode estar causando isto?

Olá @leandro.gabrielcunha, seja bem-vindo à VTEX Community!

Você pode copiar pra gente o cURL do request que você está fazendo, anonimizando seu app key e app token, para tentarmos replicar o problema?

De cara, parece que você está mandando um request com algum parâmetro faltando. No mínimo o carrierId precisaria indicar uma política de envio válida e o request precisaria ter todos campos obrigatórios, como indicado no exemplo de request body.

1 Like

Obrigado @georgebrindeiro pelo retorno, segue os dados!

    $data = [

        "absoluteMoneyCost" => "1,00",

        "country" => "BRA",

        "maxVolume" => 1000000000,

        "operationType" => 1,

        "pricePercent" => 0,

        "pricePercentByWeight" => 0,

        "timeCost" => "2.00:00:00",

        "weightEnd" =>  500,

        "weightStart" => 0,

        "zipCodeEnd" => "11999999",

        "zipCodeStart" => "1000000",

        "polygon"=> ""

    ];

    $payload = json_encode($data);

    $url_api = 'https://tecidoskite.myvtex.com/api/logistics/pvt/configuration/freights/1401/values/update';

    $headers = [

        'Content-Type: application/json; charset=utf-8',

        'Accept: application/json',

        'X-VTEX-API-AppKey: ',

        'X-VTEX-API-AppToken: '

    ];

    $ch = curl_init();

    curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);

    curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload );

    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );

    curl_setopt( $ch, CURLOPT_ENCODING, "");

    curl_setopt( $ch, CURLOPT_MAXREDIRS, 10);

    curl_setopt( $ch, CURLOPT_TIMEOUT , 30);

    curl_setopt( $ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);

    curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "POST");

    curl_setopt( $ch, CURLOPT_URL, $url_api);

    $result = curl_exec($ch);

    curl_close($ch);

Você notou que em absoluteMoneyCost você mandou 1,00 ao invés de 1.00?

Obrigado @georgebrindeiro pelo retorno, notei sim até refiz o teste por garantia e tive o mesmo erro. Me tira uma outra duvida por gentileza, somos um marketplace de cotação de fretes temos varias transportadoras cadastradas em nosso sistema. O EndPoint para integração seria este mesmo? Nosso sistema já traz a cotação pronta com base na (quantidade de produtos, peso, origem, destino e dimenções)

O seu carrierID (id da transportadora) realmente é 1401 na vtex? Não que não possa ser, mas geralmente o código é diferente.
Ao invés de utilizar myvtex.com, use vtexcommercestable.com.br
Vai ficar assim:
https://tecidoskite.vtexcommercestable.com.br/api/logistics/pvt/configuration/freights/1401/values/update

1 Like

Sim. É esse mesmo o endpoint para alimentar a tabela de frete com peso, origem, destino e dimensões.
Mas, precisa estar alimentando a transportadora (Carrier) correta e não qualquer uma.

1 Like