I tested an API using postman. Using, postman, I managed to generate a token.
From postman, I managed to get all the data of a user using the following with the following details via a GET request:
https://example.example.co.za/api/consumers/get?id=567675675&[email protected] Under Authorization type, I selected "Bearer token" and pasted the Token in its respective field.
When I click send, I get a success response with the user data.
In PHP, how can I do the same api call (using the id,email and token) inside a php function?
I tried this:
curl_setopt_array($curl, array( CURLOPT_URL => "example.example.co.za/api/consumers/[email protected]&id=567675675", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_POSTFIELDS => "", CURLOPT_HTTPHEADER => array( "Accept: */*", "Authorization: Bearer jhgukfytjfytdytfjgjyfytfjkugfyfdhtklhkugjf", "Cache-Control: no-cache", "Connection: keep-alive", "Content-Type: application/x-www-form-urlencoded", ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); return $response; But when I view the page, instead of the user data, I see this:
How do I make the API call inside a function to get the same result that I have on postman in PHP?

https://.curlis flexible, it tries to parse the URL similarly to the way browsers do in the address bar. So it will figure out thatexample.example.co.zais the domain and the scheme defaults tohttp:. The redirect is presumably the server try to switch it tohttps: