403 Error - GraphQL Query

Hey Devs!

I have a GraphQL query that simply stopped working and started throwing a 403 error.

In the Client header used by the query we have the VtexIdclientAutCookie with ctx.authToken, but I also tried with ctx.adminUserAuthToken and ctx.storeUserAuthToken.

(...)

export class GiftCard extends ExternalClient {
constructor(ctx: IOContext, options?: InstanceOptions) {
  super(`https://${ctx.account}.vtexcommercestable.com.br/api`, ctx, {
    ...options,
headers: {
      ...options?.headers,
      ...{ Accept: 'application/vnd.vtex.ds.v10+json' },
      ...{ VtexIdclientAutCookie: ctx.authToken },
},
  })
}

(...)

However, when I access the page that loads the application using this query, I get the error below:

{
  "errors": [
    {
      "message": "Request failed with status code 403",
      "path": [
        "giftcard"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "message": "Request failed with status code 403",
          "name": "ForbiddenError",
          "status": 403,
          "code": "FORBIDDEN",
          "level": "warn",
          "response": {
            "data": "",
            "headers": {
              "date": "Thu, 08 Aug 2024 13:34:10 GMT",
              "set-cookie": [
                "janus_sid=984114e8-c4ed-470c-8849-6d571bc999b9; expires=Sun, 11 Aug 2024 13:33:42 GMT; domain=xpto.vtexcommercestable.com.br; path=/; samesite=lax"
              ],
              "x-powered-by": "ASP.NET",
              "x-vtex-janus-router-backend-app": "gcsapi-v1.20.1+442",
              "x-vtex-operation-id": "dd809273-ecaa-4400-b3be-b3319cbcc98f",
              "content-length": "0",
              "connection": "Close"
            },
            "status": 403
          },
          "isAxiosError": true,
          "sensitive": {
            "config": {
              "baseURL": "https://xpto.vtexcommercestable.com.br/api",
              "data": "{\"client\":{\"id\":\"4d51ee02-7820-4267-ae6f-48f279235ec6\"}}",
              "headers": {
                "Accept": "application/vnd.vtex.ds.v10+json",
                "Content-Type": "application/json;charset=utf-8",
                "accept-encoding": "gzip",
                "user-agent": "xpto.giftcard-points@0.3.8",
                "x-forwarded-host": "temp--xpto.myvtex.com",
                "x-vtex-tenant": "pt-BR",
                "x-vtex-binding": "eyJpZCI6ImQyNWEzODkyLTQxNjUtNGNiNS05ODNiLTFiM2JiOWJkYWY3MSIsImxvY2FsZSI6InB0LUJSIn0=",
                "x-vtex-locale": "pt-BR",
                "x-vtex-operation-id": "dd809273-ecaa-4400-b3be-b3319cbcc98f",
                "x-vtex-product": "store",
                "x-vtex-segment": "eyJjYW1wYWlnbnMiOm51bGwsImNoYW5uZWwiOiIxIiwicHJpY2VUYWJsZXMiOm51bGwsInJlZ2lvbklkIjpudWxsLCJ1dG1fY2FtcGFpZ24iOm51bGwsInV0bV9zb3VyY2UiOm51bGwsInV0bWlfY2FtcGFpZ24iOm51bGwsImN1cnJlbmN5Q29kZSI6IkJSTCIsImN1cnJlbmN5U..",
                "x-vtex-session": "eyJhbGciOiJFUzI1NiIsImtpZCI6IkVFQzY3MENNQUQ4Mjc4QzJGNUIxQUJERDNDREMxMDEyM0Y5RjkyM0YiLCJ0eXAiOiJqd3QifQ.eyJhY2NvdW50LmlkIjoiNTI0NDY0MzAtNzJiZS00MGZkLWE1MjEtZmRmMTE1YTA4NDAzIiwiaWQiOiIwODZmNGYzNC0zZTYzLTQ0YzEtYTBlMy05YWEzY2NlNGU2MDEiLCJ2ZXJzaW9uIjoxOCwic3ViIjoic2Vzc2lvbiIsImFjY291bnQiOiJzZXNzaW9uIiwiZXhwIjoxNzIzNzU4NjkyLCJpYXQiOjE3MjMwNjc0OTIsIm...",
                "Content-Length": 56
              },
              "method": "post",
              "timeout": 6000,
              "url": "/giftcards/_search",
              "params": {}
            },
            "request": {
              "finished": true,
              "method": "POST",
              "path": "/api/giftcards/_search"
            },
            "stack": "Error: Request failed with status code 403\n    at createError (/usr/local/app/node_modules/axios/lib/core/createError.js:16:15)\n    at settle (/usr/local/app/node_modules/axios/lib/core/settle.js:17:12)\n    at IncomingMessage.handleStreamEnd (/usr/local/app/node_modules/axios/lib/adapters/http.js:260:11)\n    at IncomingMessage.emit (node:events:525:35)\n    at endReadableNT (node:internal/streams/readable:1358:12)\n    at processTicksAndRejections (node:internal/process/task_queues:83:21)"
          }
        }
      },
      "name": "GraphQLError",
      "forwardedHost": "temp--xpto.myvtex.com",
      "forwardedProto": "https",
      "operationId": "dd809273-ecaa-4400-b3be-b3319cbcc98f",
      "query": {
        "query": "query getGiftcard {\n  giftcard {\n    code\n    balance\n    points {\n      balance\n      expiringDate\n      __typename\n    }\n    vtexBalance\n    __typename\n  }\n}\n",
        "operationName": "getGiftcard",
        "variables": ""

          ```
{
  "errors": [
    {
      "message": "Request failed with status code 403",
      "path": [
        "giftcard"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "message": "Request failed with status code 403",
          "name": "ForbiddenError",
          "status": 403,
          "code": "FORBIDDEN",
          "level": "warn",
          "response": {
            "data": "",
            "headers": {
              "date": "Thu, 08 Aug 2024 13:34:10 GMT",
              "set-cookie": [
                "janus_sid=984114e8-c4ed-470c-8849-6d571bc999b9; expires=Sun, 11 Aug 2024 13:33:42 GMT; domain=xpto.vtexcommercestable.com.br; path=/; samesite=lax"
              ],
              "x-powered-by": "ASP.NET",
              "x-vtex-janus-router-backend-app": "gcsapi-v1.20.1+442",
              "x-vtex-operation-id": "dd809273-ecaa-4400-b3be-b3319cbcc98f",
              "content-length": "0",
              "connection": "Close"
            },
            "status": 403
          },
          "isAxiosError": true,
          "sensitive": {
            "config": {
              "baseURL": "https://xpto.vtexcommercestable.com.br/api",
              "data": "{\"client\":{\"id\":\"4d51ee02-7820-4267-ae6f-48f279235ec6\"}}",
              "headers": {
                "Accept": "application/vnd.vtex.ds.v10+json",
                "Content-Type": "application/json;charset=utf-8",
                "accept-encoding": "gzip",
                "user-agent": "xpto.giftcard-points@0.3.8",
                "x-forwarded-host": "temp--xpto.myvtex.com",
                "x-vtex-tenant": "pt-BR",
                "x-vtex-binding": "eyJpZCI6ImQyNWEzODkyLTQxNjUtNGNiNS05ODNiLTFiM2JiOWJkYWY3MSIsImxvY2FsZSI6InB0LUJSIn0=",
                "x-vtex-locale": "pt-BR",
                "x-vtex-operation-id": "dd809273-ecaa-4400-b3be-b3319cbcc98f",
                "x-vtex-product": "store",
                "x-vtex-segment": "eyJjYW1wYWlnbnMiOm51bGwsImNoYW5uZWwiOiIxIiwicHJpY2VUYWJsZXMiOm51bGwsInJlZ2lvbklkIjpudWxsLCJ1dG1fY2FtcGFZ24iOm51bGwsInV0bV9zb3VyY2UiOm51bGwsInV0bWlfY2FtcGFpZ24iOm51bGwsImN1cnJlbmN5Q29kZSI6IkJSTCIsImN1cnJlbmN5U3ltYm9sIjoiUiQiLCJjb3VudHJ5Q29kZSI6IkJSQSIsImN1bHR1cmVJbmZvIjoicHQtQlIiLCJhZG1pbl9jdWx0dXJlSW5mbyI6InB0LUJSIiwiY2hhbm5lFByaXZhY3kiOiJwdWJsaWMifQ",
                "x-vtex-session": "eyJhbGciOiJFUzI1NiIsImtpZCI6IkVFQzY3MENDQUQ4Mjc4QzJGNUIxQUJERDNDREMxMDEyM0Y5RjkyM0YiLCJeXAiOiJqd3QifQ.eyJhY2NvdW50LmlkIjoiNTI0NDY0MzAtNzJiZS00MGZkLWE1MjEtZmRmMTE1YTA4NDAzIiwiaWQiOiIwODZmNGYzNC0zZTYzLTQ0YzEtYTBlMy05YWEzY2NlNGU2MDEiLCJ2ZXJzaW9IjoxOCwic3ViIjoic2Vzc2lvbiIsImFjY291bnQiOiJzZXNzaW9uIiwiZXhwIjoxNzIzNzU4NjkyLCJpYXQiOjE3MjMwNjc0OTIsImlzcyI6InRva2VuLWVtaXR0ZXIiLCJqdGkiOiIwOGI2Y2FmYi00NDhmLTRlOTYtYjQxYy03ODdkMTRlMjhlOGYifQ.OPyK_eZuEI0gL6C5vDe1ViWUXdn8Xfv9KGuLSLRLICnkRVw-dBOmazR3rBMPawA3Gk3t8IdoTg-FMFKu96_NKg",
                "Content-Length": 56
              },
              "method": "post",
              "timeout": 6000,
              "url": "/giftcards/_search",
              "params": {}
            },
            "request": {
              "finished": true,
              "method": "POST",
              "path": "/api/giftcards/_search"
            },
            "stack": "Error: Request failed with status code 403\n    at createError (/usr/local/app/node_modules/axios/lib/core/createError.js:16:15)\n    at settle (/usr/local/app/node_modules/axios/lib/core/settle.js:17:12)\n    at IncomingMessage.handleStreamEnd (/usr/local/app/node_modules/axios/lib/adapters/http.js:260:11)\n    at IncomingMessage.emit (node:events:525:35)\n    at endReadableNT (node:internal/streams/readable:1358:12)\n    at processTicksAndRejections (node:internal/process/task_queues:83:21)"
          }
        }
      },
      "name": "GraphQLError",
      "forwardedHost": "temp--xpto.myvtex.com",
      "forwardedProto": "https",
      "operationId": "dd809273-ecaa-4400-b3be-b3319cbcc98f",
      "query": {
        "query": "query getGiftcard {\n  giftcard {\n    code\n    balance\n    points {\n      balance\n      expiringDate\n      __typename\n    }\n    vtexBalance\n    __typename\n  }\n}\n",
        "operationName": "getGiftcard",
        "variables": ""
      },
      "requestId": "0253b8cd2f0c4043a5411dec3cd5754d",
      "pathName": "giftcard"
    }
  ],
  "data": {
    "giftcard": null
  }
}

Anyone have a clue what’s going on here?

Why did this error suddenly start showing up?

Any suggestions?

This might be related to the following:

Even though it doesn’t directly affect GraphQL, I’d assume the client is calling some Gift Card Hub REST API. I’d investigate which calls are being made and where they’re going, and also review the account’s gift card provider settings.

Hey @georgebrindeiro, how’s it going?

Thanks for the help, but we’re not using an external provider.

This would be creating a gift card within VTEX itself.

In fact, if I query the registered providers, it only returns one:

[
    {
        "id": "VtexGiftCard",
        "serviceUrl": "http://api.vtex.com/xpto",
        "oauthProvider": "vtex",
        "preAuthEnabled": true,
        "cancelEnabled": true,
        "_self": {
            "href": "xpto/giftcardproviders/VtexGiftCard"
        }
    }
]

Did you introduce that xpto in the URL? Or is it in the configuration?

Hey @georgebrindeiro, I was the one who changed the account name to avoid giving visibility to the partner’s account.

But I tested adjusting the Client to use the AppKey and AppToken in the header pulling from an env, but with the other header using ctx.authToken it keeps throwing this 403 error.

In that case, I suggest opening a support ticket for a more detailed investigation.