Logistic client authorization error

I’m using the logistic client to get inventory of a SKU, but I getting an authorization error.

Client:

import { IOClients } from '@vtex/api'
import { Logistics } from '@vtex/clients'

export class Clients extends IOClients {
  //...
  public get logistics() {
    return this.getOrSet('logistics', Logistics)
  }
}

Usage:

export async function getSKUInventoryMiddleware(
  request: MiddlewareRequest,
  context: Context
): Promise<MiddlewareResponse> {
  const { clients } = context

  try {
    const response = await clients.logistics.listInventoryBySku(
      request.params.skuId
    )

    return { statusCode: HttpStatusCodes.Ok, body: response }
  } catch (error) {
    return makeErrorResponse(error)
  }
}

Response Error:

{
    "error": {
        "code": "1",
        "message": "Access denied! The request has not been applied because it lacks valid authentication credentials for the target resource!",
        "exception": {
            "ClassName": "Vtex.Practices.ServiceModel.Client.Exceptions.ForbiddenException",
            "Message": "Access denied! The request has not been applied because it lacks valid authentication credentials for the target resource!",
            "Data": null,
            "InnerException": null,
            "HelpURL": null,
            "StackTraceString": "   at Vtex.Commerce.Logistics.WebApi.AccessControlFilter.<ExecuteAuthorizationFilterAsync>d__7.MoveNext() in F:\\pachamama\\BuildAgent\\work\\3d353e624ca31c80\\src\\Vtex.Commerce.Logistics.WebApi\\AccessControlFilter.cs:line 147\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__2.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.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext()",
            "RemoteStackTraceString": null,
            "RemoteStackIndex": 0,
            "ExceptionMethod": "8\nMoveNext\nVtex.Commerce.Logistics.WebApi, Version=6.22.1.4011, Culture=neutral, PublicKeyToken=null\nVtex.Commerce.Logistics.WebApi.AccessControlFilter+<ExecuteAuthorizationFilterAsync>d__7\nVoid MoveNext()",
            "HResult": -2146233088,
            "Source": "Vtex.Commerce.Logistics.WebApi",
            "WatsonBuckets": null
        }
    }
}

Someone knows what I’m doing wrong?

Hello Jeferson,

From that error, I believe the issue might be related to the outbound access settings in the manifest of the app.

I’d recommend checking the example we provide below, and validating that the settings match what is needed for the logistics module: