Code examples

Last updated last month

node.js

const formData = {
ipAddress: '219.88.232.1',
file: {
value: fs.createReadStream(dest),
options: {
filename: message.file.name,
contentType: message.file.mimetype
}
}
};
request.post({
url: 'https://api.taggun.io/api/receipt/v1/verbose/file', formData,
headers: { apikey: 'yourapikey' }
}, (err, httpResponse, body) => {
if (err) {
return console.error('upload failed:', err);
}
console.log('Upload successful! Server responded with:', body);
});

C# or .NET

See sample code for Taggun client in .NET C# here

CURL

curl -X POST --header 'Content-Type: multipart/form-data' --header 'Accept: application/json' --header 'apikey: yourapikey' 'https://api.taggun.io/api/receipt/v1/verbose/file'

PHP

<?php
print $_SERVER['SCRIPT_FILENAME'];
$filename = realpath('./download.jpg');
$cfile = new \CurlFile($filename, 'image/jpeg', 'download.jpg');
$data = array('file' => $cfile);
$taggun_endpoint = 'https://api-au.taggun.io/api/receipt/v1/verbose/file';
$ch = curl_init();
$options = array(CURLOPT_URL => $taggun_endpoint,
CURLOPT_RETURNTRANSFER => true,
CURLINFO_HEADER_OUT => true,
CURLOPT_HEADER => true,
CURLOPT_SSL_VERIFYPEER => false, // IMPORTANT!
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => array(
'apikey: yourapikey',
'Accept: application/json',
'Content-Type: multipart/form-data'
),
CURLOPT_POSTFIELDS => $data
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
$header_info = curl_getinfo($ch,CURLINFO_HEADER_OUT);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($result, 0, $header_size);
$body = substr($result, $header_size);
curl_close($ch);
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>File Upload results</title>
</head>
<body>
<p>Raw Result: <?=$result?>
<p>Header Sent: <?=$header_info?></p>
<p>Header Received: <?=$header?></p>
<p>Body: <?=$body?></p>
</body>
</html>

python

import requests
url = 'https://api.taggun.io/api/receipt/v1/simple/file'
headers = {'apikey': 'yourapikey'}
files = {
'file': (
'1_Dinner.jpg', # set a filename for the file
open('1_Dinner.jpg', 'rb'), # the actual file
'image/jpg'), # content-type for the file
# other optional parameters for Taggun API (eg: incognito, refresh, ipAddress, language)
'incognito': (
None, #set filename to none for optional parameters
'false') #value for the parameters
}
response = requests.post(url, files=files, headers=headers)
print(response.content)