-
pippuccio76 Senior Member
   
-
Posts: 546
Threads: 231
Joined: Jun 2017
Reputation:
2
01-12-2024, 06:18 AM
(This post was last modified: 01-15-2024, 04:01 AM by pippuccio76.)
HI , im newbe for API , i want to send a request to a dispenser to know the product inside im .
In the explanation of the dispenser API every request must be with the autentication credential , send in the header of request .
To see list of product must call :
https://www.dispenserweb.com/API/Dispens...etProdotti
How can i implement a controller to do this request ?
-
pippuccio76 Senior Member
   
-
Posts: 546
Threads: 231
Joined: Jun 2017
Reputation:
2
-
kenjis Administrator
      
-
Posts: 3,671
Threads: 96
Joined: Oct 2014
Reputation:
230
-
pippuccio76 Senior Member
   
-
Posts: 546
Threads: 231
Joined: Jun 2017
Reputation:
2
01-15-2024, 03:53 AM
(This post was last modified: 01-15-2024, 04:00 AM by pippuccio76.)
(01-13-2024, 05:40 PM)kenjis Wrote: See https://codeigniter4.github.io/CodeIgnit...ml#headers
hi , this is my code :
Code: public function getDPIdispenser()
{
$uri = 'https://www.sinapsiweb.com/API/SinapsiParsedAPI/GetProdotti';
$client = \Config\Services::curlrequest();
$response = $client->request('GET', $uri, [
'headers' => [
'Autorization' => 'Autorization:Basic Base64encoded(xxxxx:xxxxx)',
],
]);
$body = $response->getBody();
dd($body);
}
I have this error : 22 : The requested URL returned error: 401
In postman work only if i work as this screenshot https://ibb.co/KFDGDn6
How can i do this with code ?
edit:
Solved by this code :
$response = $client->request('GET', $uri , ['auth' => ['xxxxx', 'xxxxxx', 'basic']]);
-
pippuccio76 Senior Member
   
-
Posts: 546
Threads: 231
Joined: Jun 2017
Reputation:
2
01-16-2024, 12:38 AM
(This post was last modified: 01-16-2024, 12:42 AM by pippuccio76.)
Another problem with request :
TRY this:
Code: public function getTransazionidispenser()
{
$uri = 'https://www.sinapsiweb.com/API/SinapsiParsedAPI/GetTransazioni?dataDa=10/01/2024 00:00:00&dataA=15/01/2024 00:00:00';
$client = \Config\Services::curlrequest();
$response = $client->request('GET', $uri ,
[
'auth' => ['xxx', 'xxx', 'basic']
],
);
$body = $response->getBody();
$res = json_decode($body);
foreach($res as $v){
echo '<pre>';
print_r($v);
}
}
[/code]
with tis error :
CodeIgniter\HTTP\Exceptions\HTTPException
3 :
and this :
Code: public function getTransazionidispenser()
{
$uri = 'https://www.sinapsiweb.com/API/SinapsiParsedAPI/GetTransazioni';
$client = \Config\Services::curlrequest();
$response = $client->request('GET', $uri ,
[
'auth' => ['xxx', 'xxx', 'basic']
],
[
'query' => [
'dataDa' => '10/01/2024 00:00:00',
'dataA' => '15/01/2024 00:00:00',
]
]
);
$body = $response->getBody();
$res = json_decode($body);
foreach($res as $v){
echo '<pre>';
print_r($v);
}
}
with this error :
CodeIgniter\HTTP\Exceptions\HTTPException
22 : The requested URL returned error: 500
in postman work fine : https://ibb.co/GVvKPph
what can i do to pass parameter to query ?
-
kenjis Administrator
      
-
Posts: 3,671
Threads: 96
Joined: Oct 2014
Reputation:
230
01-16-2024, 12:42 AM
(This post was last modified: 01-16-2024, 12:43 AM by kenjis.)
-
pippuccio76 Senior Member
   
-
Posts: 546
Threads: 231
Joined: Jun 2017
Reputation:
2
01-16-2024, 12:49 AM
(This post was last modified: 01-16-2024, 12:55 AM by pippuccio76.)
(01-16-2024, 12:42 AM)kenjis Wrote: See https://codeigniter4.github.io/CodeIgnit...html#query
and auth is also documented:
https://codeigniter4.github.io/CodeIgnit....html#auth
is exactely the second code i have posted , but doesn't work , codeigniter return an incomprehensible error what mean :
CodeIgniter\HTTP\Exceptions\HTTPException
3 :
sorry with second code return 500...
this is the log :
Code: CRITICAL - 2024-01-16 08:51:59 --> CodeIgniter\HTTP\Exceptions\HTTPException: 22 : The requested URL returned error: 500
in SYSTEMPATH\HTTP\CURLRequest.php on line 695.
1 SYSTEMPATH\HTTP\CURLRequest.php(695): CodeIgniter\HTTP\Exceptions\HTTPException::forCurlError('22', 'The requested URL returned error: 500')
2 SYSTEMPATH\HTTP\CURLRequest.php(387): CodeIgniter\HTTP\CURLRequest->sendRequest([...])
3 SYSTEMPATH\HTTP\CURLRequest.php(145): CodeIgniter\HTTP\CURLRequest->send('GET', 'https://www.sinapsiweb.com/API/SinapsiParsedAPI/GetTransazioni')
4 APPPATH\Controllers\AdminDPIRest.php(91): CodeIgniter\HTTP\CURLRequest->request('GET', 'https://www.sinapsiweb.com/API/SinapsiParsedAPI/GetTransazioni', [...], [...])
5 SYSTEMPATH\CodeIgniter.php(941): App\Controllers\AdminDPIRest->getTransazionidispenser()
6 SYSTEMPATH\CodeIgniter.php(502): CodeIgniter\CodeIgniter->runController(Object(App\Controllers\AdminDPIRest))
7 SYSTEMPATH\CodeIgniter.php(361): CodeIgniter\CodeIgniter->handleRequest(null, Object(Config\Cache), false)
8 FCPATH\index.php(79): CodeIgniter\CodeIgniter->run()
|