0

My curl php code is returning 301 and i can't print out what the curl returned. this is my code:

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://subdomain.thinkific.com/api/public/v1/users/3418346");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);

$headers = array();
$headers[] = "X-Auth-Api-Key: myapikey";
$headers[] = "X-Auth-Subdomain: subdomain";
$headers[] = "Content-Type: application/json";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);


$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close($ch);
var_dump($result);

Here is what it returned:

string(142) "301{"Location"=>"https:subdomain.thinkific.com/api/public/v1/users/3418346", "Cache-Control"=>"no-cache"}#" 

i have tried json_decode the result to print it, still the same. as well as i also tried those:

curl_setopt($ch, CURLOPT_ENCODING, "");
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_NOBODY, 1); //this one returned string(0) without 301

I need to know if the error is from my server or it has something to do with my code. ( i did not share api key and subdomain for privacy sorry).

devterm
  • 32
  • 7

1 Answers1

0

The 301 response code is the following :

The HTTP response status code 301 Moved Permanently is used for permanent URL redirection, meaning current links or records using the URL that the response is received for should be updated. The new URL should be provided in the Location field included with the response.

SO it means that you're requesting a resource that has been moved (the url changed) and you should retry the request with the newly provided URL !

Ko2r
  • 1,541
  • 1
  • 11
  • 24