aws-api-gateway-client icon indicating copy to clipboard operation
aws-api-gateway-client copied to clipboard

Request failed Error: Request failed with status code 403 in React native application.

Open SanjanaTailor opened this issue 2 years ago • 0 comments

Hello, we have used this library in react native application like below, we tried this library to hit the AWS endpoint gateway.

import { default as apigClientFactory, ApiGatewayClient } from "aws-api-gateway-client";

Header : const { accessKeyId, secretAccessKey, sessionToken } = authReducerData.currentUserCredentials; const ApiGatewayConfig = { invokeUrl: 'https://XXXXXXXXXX.execute-api.ap-south-1.amazonaws.com/beta', accessKey: accessKeyId, secretKey: secretAccessKey, sessionToken: sessionToken, region: 'ap-south-1', };

const additionalParams = { 'X-App-Auth-Token' : authToken } await apigClientFactory.newClient(ApiGatewayConfig) .invokeApi({}, "/v1/app/list?languageCode=hi", "GET", additionalParams, {}) .then((response : any) => { console.log('response from server ',response) }) .catch((error :any) => { console.log('response from server error',JSON.stringify(error)) });

Response : { "message": "Request failed with status code 403", "name": "Error", "stack": "Error: Request failed with status code 403\n at createError (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.upajkisanapp&modulesOnly=false&runModule=true:615477:17)\n at settle (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.upajkisanapp&modulesOnly=false&runModule=true:615467:14)\n at XMLHttpRequest.onloadend (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.upajkisanapp&modulesOnly=false&runModule=true:615357:9)\n at XMLHttpRequest.dispatchEvent (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.upajkisanapp&modulesOnly=false&runModule=true:30380:27)\n at XMLHttpRequest.setReadyState (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.upajkisanapp&modulesOnly=false&runModule=true:29487:16)\n at XMLHttpRequest.__didCompleteResponse (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.upajkisanapp&modulesOnly=false&runModule=true:29285:16)\n at http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.upajkisanapp&modulesOnly=false&runModule=true:29401:47\n at EventEmitter.emit (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.upajkisanapp&modulesOnly=false&runModule=true:2145:37)\n at MessageQueue.__callFunction (http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.upajkisanapp&modulesOnly=false&runModule=true:21533:31)\n at http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.upajkisanapp&modulesOnly=false&runModule=true:21261:17", "config": { "url": "https://mg8l0rqg38.execute-api.ap-south-1.amazonaws.com/beta/v1/kisan/crops?languageCode=hi", "method": "get", "headers": { "Accept": "application/json", "x-amz-date": "20221017T131804Z", "Authorization": "AWS4-HMAC-SHA256 Credential=ASIA2MXBOZTZP3EA3KF4/20221017/ap-south-1/execute-api/aws4_request, SignedHeaders=accept;host;x-amz-date, Signature=2e20e8db0baea2865e385ef5a207b8a6fda8e6fca7ab98eef094148e7bfb5bba", "x-amz-security-token": "IQoJb3JpZ2luX2VjEDwaCmFwLXNvdXRoLTEiRjBEAiA+I1U8JunLZFfprHLxL5KU03qhDoOPGdurExRcI5rIUAIgbQ4ZVyrgVveEJYby5RB0NXxGp/LvoWc9lsMRHXNUtcYqygQIFRAAGgw3MTQ1MTExNDIxMzAiDP+NVO/y+o0WHswMmyqnBEKVCTi1iEacZx0q101W9cFuIuvwPYwnuhVnNgIwXCAq7a8xLxNVNbt8QMWQOCj9x9bZ8aGRsLdhAr10+8ZgXlz2cjChMfmxyMvG6/RxfMlxxu39M/85QR8r994F47fKGujA+NZ5+Xz3bCJksg56jz+AdYGOxWYIOpStHM29DPIwEtF5fFcojJmlmxHzXyeRQZh6Ga6OJ8dPwl/EV5rD9NGfwLs8UcFMW8+nw9a/i3y2TCYo6XGDBoD0iD0v+SNyuT2bp9GeuBQmUAu8kfH3+IQYiliXUV2SMA84t+CO668iEq5pYeVWdoE1hQ44wRlGvqAYQa76oMP+zYEErqBmEUj/HBAPb0N2lbRvPTy1ubsmh8mFoDod483slnCvaXDQFMYf8A4ATk72enr4yie12t+AjK2fJ9wPb7Q2sqa5AVVkE/ZcIm3ecKnJ0k+NEN6nrQeiOeQsCoab21iDODQmDe7F/I4wm7ZVGY5KT0odYyYEkKU5mPtH4AaPm1JABMuJ5g7WN202rncbPIEGK+hqBgAX9v3ZdlwB/uz3xA09ioUoooxAdRutUPAnWbm8YPOg65J6/qzhkOZylhoa0Zfi0iEL59+LivTwh5aQUUQMq9rnRAuENBpY1eI7zms8yS5Jz15i4D9/+Ufk40TuAgMbHz2wtDh2tQ19gpAv//53uFAGW9F0qPtCCtC9K6fhun91YC0R5BW9jxBS6r5eXPj8GjWRN//tb/6dMMyKtZoGOoYCSC4gAyuwu3Eb+IWg/LbV93wA+slp/lbfYmAzUjsnfeCD2TKh2dQrW57uTQZlvmqKtOrIUcELjPD7sL4RASb0pO7ky8ZiPYx/MsTOUK48eWhDyA8JMZYGHuWQm7jRZYVYEtSCVqVMZq5VIor0WtWAP+aIpYr+7DB3pZv032sAlffzDOVly0nQRNUT8k/AUVsFFrGV2W/Px83dP9h/tgg51lWqwWyRpkAlqw/CYix1vhXvJC+WkyyNTnNiPOPd3OmRVd09jXzNvGxuvPOoOmZxtI9hKo4P9hKbQ+9ocU3nyp8dS3zgV+NyCnNprKcEFBiaGvjfI8+O0Z8k2npagr475ovkmrgohA==" }, "transformRequest": [null], "transformResponse": [null], "timeout": 0, "xsrfCookieName": "XSRF-TOKEN", "xsrfHeaderName": "X-XSRF-TOKEN", "maxContentLength": -1, "maxBodyLength": -1, "transitional": { "silentJSONParsing": true, "forcedJSONParsing": true, "clarifyTimeoutError": false } }

please suggest where is the issue ? we are hitting the API from Android device and implementation is in reactnative as mentioned above. Thank you in advanced.

SanjanaTailor avatar Oct 17 '22 13:10 SanjanaTailor