Jacob
Jacob

Reputation: 1490

TotalVirus API v3: Scan URL returning "HTTP 400 Bad Request"

I am currently scanning files uploaded to my file management system. To do this I'm using TotalVirus API v3. For files smaller than 32MB, everything is working well and I'm able to upload the file via cURL in a post request. For files larger than 32MB, TotalVirus requires the file to be scanned by submitting a URL to the file. When I tried to use the URL api I ran into some issues. Below is a simplified snippet of my PHP script. I've tried sending a cURL request directly from my terminal, I've tried sending requests from ReqBin, I've tried sending the request with JavaScript, and tried from one of my other servers. Every time I receive the same response: Argument \"url\" is missing.

I'm certain my API key is correct because I'm able to use it to upload files less than 32MB successfully, and I'm certain the URL I'm submitting is a valid URL and the correct file, and I'm certain TotalVirus can accept the file type at the URL because I can upload it manually directly through their site without issues.

Does anyone have any idea what could be causing this response? Am I not following the TotalVirus documentation correctly, or is my code actually incorrect syntax? I've tried using curl_errno, and implemented a few other debugging methods and haven't received any error messages except for my response from TotalVirus.

PHP

<?php
$apiKey = 'MY_API_KEY';
$urlToScan = 'https://example.com/myfile.pdf';

$headers = [
    "x-apikey: $apiKey",
    "Content-Type: application/json",
];

$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_URL, 'https://www.virustotal.com/api/v3/urls');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['url' => $urlToScan]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>

cURL

curl -X POST \
  -H "x-apikey: MY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://example.com/myfile.pdf"}' \
  "https://www.virustotal.com/api/v3/urls"

ReqBin

POST /api/v3/urls HTTP/1.1
Host: www.virustotal.com
x-apikey: MY_API_KEY
Content-Type: application/json
Content-Length: 41

{"url": "https://example.com/myfile.pdf"}

TotalVirus Response

HTTP/1.1 400 Bad Request
Content-Type: application/json

{
    "error": {
        "code": "BadRequestError",
        "message": "Argument \"url\" is missing"
    }
}

Upvotes: 0

Views: 16

Answers (0)

Related Questions