Can't get request client error 403

i can’t fetch data from alpaca Account - Documentation | Alpaca
when I try to fetch data from alpaca GitHub - infinitered/apisauce: Axios + standardized errors + request/response transforms.
using react component https://reactjs.org/docs/react-component.html

import alpacaApi from '../services/alpaca'
    componentDidMount() {
        console.log('fetch data from alpaca')

        const api = alpacaApi()

        api.getAccount().then((response) => {
            console.log(response)
        })
    }

here is alpacaApi.js file

import apisauce from 'apisauce'

const alpacaApi = (baseURL = config.BASE_URL) => {
    
    const api = apisauce.create({
        baseURL: config.BASE_URL,
        headers: {
            'APACA-API-KEY-ID': config.ALPACA_API_KEY_ID,
            'APACA-API-SECRET-KEY': config.ALPACA_API_SECRET_KEY
        },
        timeout: 5000
    })

    const getAccount = () => api.get('v2/account')
    const getPostitions = () => api.get('v2/positions')

    return {
        getAccount,
        getPostitions
    }
}

const config = {
    ALPACA_API_KEY_ID: "apikey",
    ALPACA_API_SECRET_KEY: "secretkey",
    BASE_URL: "https://paper-api.alpaca.markets"
}

export default alpacaApi

it shows error

 LOG  fetch data from alpaca
 LOG  {"config": {"adapter": [Function xhrAdapter], "baseURL": "https://paper-api.alpaca.markets", "data": undefined, "headers": {"APACA-API-KEY-ID": "apikey", "APACA-API-SECRET-KEY": "secretkey", "Accept": "application/json"}, "maxBodyLength": -1, "maxContentLength": -1, "method": "get", "params": {}, "timeout": 5000, "transformRequest": [[Function transformRequest]], "transformResponse": [[Function transformResponse]], "transitional": {"clarifyTimeoutError": false, "forcedJSONParsing": true, "silentJSONParsing": true}, "url": "v2/account", "validateStatus": [Function validateStatus], "xsrfCookieName": "XSRF-TOKEN", "xsrfHeaderName": "X-XSRF-TOKEN"}, "data": {"message": "forbidden."}, "duration": 956, "headers": {"connection": "keep-alive", "content-length": "26", "content-type": "application/json", "date": "Wed, 07 Dec 2022 02:36:19 GMT"}, "ok": false, "originalError": [Error: Request failed with status code 403], "problem": "CLIENT_ERROR", "status": 403}

it didn’t show a properties data.
what should i do ??

Hi.

Unless I’m missing something, you haven’t actually defined your API and secret keys in config.

ALPACA_API_KEY_ID: “apikey”,
ALPACA_API_SECRET_KEY: “secretkey”,

You need to put your actual keys between those quotes.

Cheers

2 Likes

I already put the actual api key & secret key from Alpaca – Crypto, Stock Trading API but still got error
[Error: Request failed with status code 403], “problem”: “CLIENT_ERROR”, “status”: 403}

hi @chatofking
could you please to try your paper credentials here:

i created it on python, it’s just to test if your paper credentials are correct.

it will return you the account’s detail:

1 Like

I made a little typo from APACA to APCA it works now thank for the help.

1 Like