1

To authenticate API calls, you must first generate a session to get a token. Then you must send the session token as the value of the X-Auth-Token header to authenticate API calls.

To create a session you first need to manually generate an API Key. This is a key/value pair that can be generated in the API Access page. When you click Generate New API Key, a popup will be displayed with the API Key Value and in the table of Active Keys you can find the API Key ID. This is then sent via Basic Authentication in a POST call to the sessions route.

I followed this Api Documentation of deepcrawl already but what am I doing wrong?

I have X-Auth-Token and API KEY ID where should I put this?

$deephead = "X-Auth-Token: asdjasiojqoieuqiouwqpofoqwojeq"; 

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.deepcrawl.com/sessions");
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, $deephead);

// Get the response
$response = curl_exec($ch);

// Close cURL connection
curl_close($ch);

// Decode the response (Transform it to an Array)
$result = json_decode($response);

//debug the response
dd($result); 

The I can't even get to CURLOPT_GET cause at my post I only get null value. Any idea/thoughts how can I fix this. Thank you in advance.

Christian Gallarmin
  • 660
  • 4
  • 15
  • 34

1 Answers1

1

DeepCrawl API

It looks like you are trying to generate a token, which it looks like you already have.

To authenticate API calls, you must first generate a session to get a token. Then you must send the session token as the value of the X-Auth-Token header to authenticate API calls.

To create a session you first need to manually generate an API Key. This is a key/value pair that can be generated in the API Access page. When you click Generate New API Key, a popup will be displayed with the API Key Value and in the table of Active Keys you can find the API Key ID. This is then sent via Basic Authentication in a POST call to the sessions route.

curl -X POST -u '123:abcdef' https://api.deepcrawl.com/sessions { "token":"abcdef123", "_user_href":"/users/example-user", ... }

Not the clearest, but it's right there.

$headers = [
    'Content-Type: application/x-www-form-urlencoded',
    'accept: text/html'
];
$username='yourusername';
$password='supersecret';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.deepcrawl.com/sessions");
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, "root=1");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

// Get the response
$response = curl_exec($ch);

// Close cURL connection
curl_close($ch);

// Decode the response (Transform it to an Array)
return json_decode($response);

That will return something like

{
  "token":"abcdef123",
  "_user_href":"/users/example-user",
  ...
}

Since you already have the token, you don't need ot hit session. you can just make your calls.

$headers = [
    'X-AUTH-TOKEN: your-api-key',
    'accept: text/html'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.deepcrawl.com/system_statuses");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

// Get the response
$response = curl_exec($ch);

// Close cURL connection
curl_close($ch);

// Decode the response (Transform it to an Array)
return json_decode($response);
whoacowboy
  • 6,982
  • 6
  • 44
  • 78