Welcome Guest, Not a member yet? Register   Sign In
[SOLVED]HTTP request API
#1

(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 ?
Reply
#2

Your url link is not working.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(This post was last modified: 01-12-2024, 06:34 AM by pippuccio76.)

(01-12-2024, 06:22 AM)InsiteFX Wrote: Your url link is not working.

Is an example the real url is  https://www.sinapsiweb.com/API/SinapsiPa...etProdotti    ( i don't know if i can insert real url)
Reply
#4

Well it still does not work, can you give us a link to this API so that we can look at it?
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

(01-13-2024, 05:37 AM)InsiteFX Wrote: Well it still does not work, can you give us a link to this API so that we can look at it?

I have only a PDF , but i want know how can i request external data by passing credential in header . Can i do only with curl or must i  do in another way?
Reply
#6

See https://codeigniter4.github.io/CodeIgnit...ml#headers
Reply
#7

(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']]);
Reply
#8

(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 ?
Reply
#9

(This post was last modified: 01-16-2024, 12:43 AM by kenjis.)

See https://codeigniter4.github.io/CodeIgnit...html#query

and auth is also documented:
https://codeigniter4.github.io/CodeIgnit....html#auth
Reply
#10

(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()
Reply




Theme © iAndrew 2016 - Forum software by © MyBB