Google Sheets API returns "401 - Unauthorized error"

I’m trying to append rows to a Google Sheet using the native API, I have correctly configured the OAuth 2.0, It works correctly with static input but when I try to make it dynamic It’s not working returning the error message “401 - Unauthorized error”.

  "error": {
    "code": 401,
    "details": [
        "@type": "",
        "domain": "",
        "metadata": {
          "method": "google.apps.sheets.v4.SpreadsheetsService.AppendValues",
          "service": ""
        "reason": "CREDENTIALS_MISSING"
    "message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See",
    "status": "UNAUTHENTICATED"