RootSoft / algorand-php

Unofficial community SDK to interact with the Algorand network, in PHP & Laravel

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

keep getting {"message":"Forbidden"} error upon http request making

ntswamp opened this issue · comments

made a client like:

$algodClient = new AlgodClient(PureStake::TESTNET_ALGOD_API_URL, 'my-api-key');
$indexerClient = new IndexerClient(PureStake::TESTNET_INDEXER_API_URL, ''my-api-key');
$kmdClient = new KmdClient('127.0.0.1', ''my-api-key');
$algorand = new Algorand($algodClient, $indexerClient, $kmdClient);

making http request:

$transaction = TransactionBuilder::payment()
    ->sender($account->getAddress())
    ->note('test')
    ->amount(1000000) // 1 Algo
    ->receiver(Address::fromPublicKey("some-address"))
    ->useSuggestedParams($algorand)
    ->suggestedFeePerByte(10)
    ->build();

error was occurred at line ->useSuggestedParams($algorand)

the error:

Fatal error: Uncaught Rootsoft\Algorand\Exceptions\ApiKeyException: {"message":"Forbidden"} in /Users/h1-226/code/phpz/vendor/rootsoft/algorand-php/src/Traits/MakesHttpRequests.php:125
Stack trace:
#0 /Users/h1-226/code/phpz/vendor/rootsoft/algorand-php/src/Traits/MakesHttpRequests.php(106): Rootsoft\Algorand\Algorand->handleRequestError(Object(GuzzleHttp\Psr7\Response))
#1 /Users/h1-226/code/phpz/vendor/rootsoft/algorand-php/src/Traits/MakesHttpRequests.php(27): Rootsoft\Algorand\Algorand->request(Object(Rootsoft\Algorand\Clients\AlgodClient), 'GET', 'v2/transactions...', Array) 
#2 /Users/h1-226/code/phpz/vendor/rootsoft/algorand-php/src/Services/ManagesTransactionParamsV2.php(19): Rootsoft\Algorand\Algorand->get(Object(Rootsoft\Algorand\Clients\AlgodClient), '/v2/transaction...')
#3 /Users/h1-226/code/phpz/vendor/rootsoft/algorand-php/src/Models/Transactions/Builders/RawTransactionBuilder.php(361): Rootsoft\Algorand\Algorand->getSuggestedTransactionParams()
#4 /Users/h1-226/code/phpz/index.php(61): Rootsoft\Algorand\Models\Transactions\Builders\RawTransactionBuilder->useSuggestedParams(Object(Rootsoft\Algorand\Algorand))
#5 {main} thrown in /Users/h1-226/code/phpz/vendor/rootsoft/algorand-php/src/Traits/MakesHttpRequests.php on line 125

tested out my api key in https://developer.purestake.io/apis, everything was working fine over there.

hi @ntswamp

PureStake's API requires another API Token header then the default one: x-api-key. Default one is: X-Algo-API-Token.
You can also use PureStake::API_TOKEN_HEADER
I might have to make this a bit more clear in the documentation

$algodClient = new AlgodClient(PureStake::TESTNET_ALGOD_API_URL, 'my-api-key', 'x-api-key');
$indexerClient = new IndexerClient(PureStake::TESTNET_INDEXER_API_URL, 'my-api-key', PureStake::API_TOKEN_HEADER);
$kmdClient = new KmdClient('127.0.0.1', 'my-api-key');
$algorand = new \Rootsoft\Algorand\Algorand($algodClient, $indexerClient, $kmdClient);

@RootSoft
sorry for late reply. yeah the PureStake::API_TOKEN_HEADER worked a treat. appreciate it man!