Getting "errorCode":"AG8001 while getting historical data


  • Error code- {"success":false,"message":"Invalid Token","errorCode":"AG8001","data":""}'

    Getting this error while fetching historical data, I have reset my password and pin also but still getting the same error.

    Although I am able to generate refresh token successfully.


  • Instead doing it literally strings as provided in documentation

    OkHttpClient client = new OkHttpClient().newBuilder()
      .build();
    MediaType mediaType = MediaType.parse("application/json");
    RequestBody body = RequestBody.create(mediaType,
         "{\n
            \"clientcode\":\"CLIENT_ID\",\n
            \"password\":\"CLIENT_PIN\"\n
    		\"totp\":\"TOTP_CODE\"\n
        }"
         );
    

    put it in map to reduce chances of error in json format

       // Create a Map to represent the JSON structure
            Map<String, String> requestBodyMap = new HashMap<>();
            requestBodyMap.put("clientcode", "CLIENT_ID");
            requestBodyMap.put("password", "CLIENT_PIN");
            requestBodyMap.put("totp", "TOTP_CODE");
    
            // Convert the Map to JSON
            ObjectMapper objectMapper = new ObjectMapper();
            byte[] requestBodyBytes = objectMapper.writeValueAsBytes(requestBodyMap);
    
            // Create the request body
            RequestBody body = RequestBody.create(mediaType, requestBodyBytes);
    
    

  • Hi @daalchawal,

    Apologies for delayed response.
    Kindly write to us with the client details on smartapi@angelbroking.com if the "Invalid Token" still being faced on login API.

    Thanks & Regards,
    SmartAPI team


  • @Moderator_2
    url <- "https://apiconnect.angelbroking.com/rest/auth/angelbroking/user/v1/loginByPassword"

    json_body<-toJSON(list(
    'clientcode'="xxxx",
    'password'='xxxx',
    'totp'='372426'
    ))

    response<-POST(url ="https://apiconnect.angelbroking.com/rest/auth/angelbroking/user/v1/loginByPassword",
    config=list(
    add_headers(
    'Content-Type'= 'application/json',
    'Accept'= 'application/json',
    'X-UserType'= 'USER',
    'X-SourceID'= 'WEB',
    'X-ClientLocalIP'= 'xxxxx',
    'X-ClientPublicIP'= 'xxxx',
    'X-MACAddress'= 'xxxx',
    'X-PrivateKey'= 'xxxx'
    )
    ),body = json_body,
    encode = 'raw')


  • Hi @ackshay

    Apologies for delayed response.
    "Invalid Token" represents the expired authorization. Kindly reverify by passing the fresh token after login. If the issue has not resolved, please share us the API request, header passed and response to analyze further.

    Thanks & Regards,
    SmartAPI team