Upload customer data files to VAT Compliance
The VAT Compliance File Upload API provides a more secure, API-driven method for uploading customer data files to VAT Compliance.
This article describes the process of uploading customer data files:
- Authenticate for VAT Compliance to generate an access token.
- Generate the SHA-256 hash to verify the file upload.
- Request a pre-signed URL by using the API.
- Upload the file directly to VAT Compliance by using the pre-signed URL.
- Notify VAT Compliance that the file upload is complete.
Prerequisites
Before continuing, make sure that you have created a reusable import profile as described in Creating an import profile.
To complete the file upload process, you need:
- An access token for use in API request headers.
- An SHA-256 hash generator tool. You need to calculate the hash of the file before uploading.
- Access to the API operation Upload customer data files into VAT Compliance.
- The ability to perform a PUT request to upload the file to the pre-signed URL by using cURL, Postman, or your own integrated program.
Authenticate for VAT Compliance
Follow the steps in Authenticate for VAT Compliance to receive your client ID and client secret and then generate the required access token for making API requests.
Generate the SHA-256 hash
Calculate the hash of the file before uploading. Use an SHA-256 hash generator tool.
For MacOS and Linux
-
Open a terminal window.
-
Run the following command:
shasum -a 256 your_file.txtwhere
your_file.txtis the path and file name of the customer data file you need to upload. The file can be.txtor.csv.Your import files must be comma-separated, pipe-separated, or tab-separated text or non-paginated CSV files. If your data includes special characters, your data file must be in UTF-8 format. If your data file is not in the correct format and the import data includes special characters, the import will fail.
-
Copy the hash and include it in the next step.
For Windows
-
Open a terminal window.
-
Run the following command:
Get-FileHash your_file.txt -Algorithm SHA256Where
your_file.txtis the path and file name of the customer data file you need to upload. The file can be.txtor.csv.Your import files must be comma-separated, pipe-separated, or tab-separated text or non-paginated CSV files. If your data includes special characters, your data file must be in UTF-8 format. If your data file is not in the correct format and the import data includes special characters, the import will fail.
-
Copy the hash and include it in the next step.
Sample code to generate SHA-256 hash
If you decide to develop a programmatic solution, here is the Java, C# (.NET), Python, and Go source code needed to generate the SHA-256 hash.
Java code
import java.io.FileInputStream;
import java.security.MessageDigest;
public class HashUtil {
public static String getSHA256(String filePath) throws Exception {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
FileInputStream fis = new FileInputStream(filePath);
byte[] byteArray = new byte[1024];
int bytesCount;
while ((bytesCount = fis.read(byteArray)) != -1) {
digest.update(byteArray, 0, bytesCount);
}
fis.close();
StringBuilder sb = new StringBuilder();
for (byte b : digest.digest()) {
sb.append(String.format("%02x", b));
}
return sb.toString();
}
}
C# (.NET) code
using System.IO;
using System.Security.Cryptography;
public static class HashHelper {
public static string GetSHA256(string filePath) {
using (FileStream stream = File.OpenRead(filePath))
using (SHA256 sha = SHA256.Create()) {
byte[] hashBytes = sha.ComputeHash(stream);
return BitConverter.ToString(hashBytes).Replace("-", "").ToLowerInvariant();
}
}
}
Python code
import hashlib
def get_sha256(file_path):
sha256_hash = hashlib.sha256()
with open(file_path, "rb") as f:
for byte_block in iter(lambda: f.read(4096), b""):
sha256_hash.update(byte_block)
return sha256_hash.hexdigest()
# Example usage:
hash_value = get_sha256("your_file.txt")
print("SHA-256:", hash_value)
Go code
package main
import (
"crypto/sha256"
"fmt"
"io"
"os"
)
func main() {
file, _ := os.Open("your_file.ext")
defer file.Close()
hash := sha256.New()
io.Copy(hash, file)
fmt.Printf("%x\n", hash.Sum(nil))
}
Upload data files to generate the pre-signed URL
Use the VAT Compliance API to upload your data files, which generates the pre-signed URL.
The required parameters are import profile name, mime type, file name, and hash.
For step-by-step instructions, refer to Upload your data files to generate the upload URL.
Upload the customer data file by using the pre-signed URL
Perform a PUT request to upload the file to the pre-signed URL by using cURL, Postman, or your own integrated program.
To use cURL from a command prompt, refer to Upload the file to the pre-signed URL.
To use Postman, attach the file by using Body > Binary > Select File.
Notify VAT Compliance that the file upload is complete
Use the VAT Compliance API to complete the upload.
The required parameter is the virtual reference number (VRN) that the Upload your data files to generate the upload URL operation generates.
For step-by-step instructions, refer to Complete customer data file Upload.
Updated 1 day ago
