Closed umnibot closed 8 months ago
Any help here?
After 3 weeks of tests, I found a solution and successfully uploaded an existing agent/backup. The thing was to set the body to binary. To set the body to binary data and upload without multipart/form-data, the key is to cheat curl, first, we tell him to PUT, then to POST:
This is the code that worked
$url = 'https://api.wit.ai/import?v=20230215&name=newapp&private=true';
$file_local_full = '/path-to-file/exported-agent.zip';
$content_type = mime_content_type($file_local_full);
$headers = array(
"Content-Type: $content_type", // or whatever you want
"Authorization: Bearer THE_TOKEN"
);
$filesize = filesize($file_local_full);
$stream = fopen($file_local_full, 'r');
$curl_opts = array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_PUT => true,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => $headers,
CURLOPT_INFILE => $stream,
CURLOPT_INFILESIZE => $filesize,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1
);
$curl = curl_init();
curl_setopt_array($curl, $curl_opts);
echo $response = curl_exec($curl);
fclose($stream);
Credits to Sergio A. Kessler https://stackoverflow.com/questions/31970541/php-curl-how-to-set-body-to-binary-data
What is the current behavior? I am trying to import an agent via the API using this cURL.
But I am getting this error:
{"error":"Something went wrong. We've been notified","code":"unknown"}
The token I am using is correct as I can create a new app with it if not importing an agent.