Failed to generate session token how to generate


  • protected function generateSessionToken()
    {
    $client = new Client();

        try 
        {           
            $response = $client->post('https://apiconnect.angelbroking.com/rest/auth/angelbroking/user/v1/loginByPassword', [
                            'json' => [
                                'clientcode' => env('ANGEL_BROKING_CLIENT_CODE'),
                                'password' => env('ANGEL_BROKING_PASSWORD'),
                                'totp' => env('BDODBV4DALNVJGAPS4R7YS3J7A'),
                            ],
                            'headers' => [
                                'X-API-Key' => $this->apiKey,
                                'Content-Type' => 'application/json',
                                'Accept' => 'application/json',
                                'X-UserType' => 'USER',
                                'X-SourceID' => 'WEB',
                                'X-ClientLocalIP' => $_SERVER['SERVER_ADDR'],
                                'X-ClientPublicIP' => file_get_contents('https://api.ipify.org'),
                                'X-MACAddress' => 'f8:32:e4:9c:27:0d',
                            ],
                        ]);
    
           
            $statusCode = $response->getStatusCode();
            $responseBody = $response->getBody()->getContents();
    
          
            $responseData = json_decode($responseBody, true);
            dd($responseData);
    
            Log::info('API Response:', ['status' => $statusCode, 'body' => $responseBody]);
    
            if ($statusCode == 200) {
                if (isset($responseData['data']['jwtToken'])) {
                    return $responseData['data']['jwtToken'];
                } elseif (isset($responseData['success']) && !$responseData['success']) {
                    $errorMessage = isset($responseData['message']) ? $responseData['message'] : 'Unknown error occurred';
                    throw new Exception('Failed to generate session token: ' . $errorMessage);
                }
                throw new Exception('Failed to generate session token: Unexpected response');
            } else {
                throw new Exception('Failed to generate session token: Status Code ' . $statusCode);
            }
        } catch (Exception $e) {
            dd($e);
            Log::error('Error generating session token: ' . $e->getMessage());
            throw $e;
        }
    }

  • @H56857442

    ANGEL_BROKING_TOTP= 6 digit code generated in authenticator app

    Regards,
    SmartAPI Team


  • @Moderator_3

    ANGEL_BROKING_CLIENT_CODE=H56857442
    ANGEL_BROKING_PASSWORD=5285
    ANGEL_BROKING_TOTP=BDODBV4DALNVJGAPS4R7YS3J7A


  • @H56857442

    Please send below values in request parameter ,
    You need to send your mpin instead of password in the "password" field.

    "clientcode": "Your_client_code",
    "password": "Your_mpin"
    "totp":"code_displayed_on_your_authenticator_app"

    Regards,
    SmartAPI Team