Code examples


import io, requests, csv
# Define your upload key and your data dictionary
upload_key = '<<your upload key>>'
data = [{'barcode': '000001', 'price': '1.00', 'quantity': 1}]
# Turn data dictionary into a CSV string
fh = io.StringIO('')
writer = csv.DictWriter(fh, fieldnames=list(data[0].keys()))
for row in data:
# Request upload URL
url = requests.get(f"{upload_key}?type=stock").text
# PUT request to upload CSV string
requests.put(url,, headers={'content-type': 'text/csv'}).text

JavaScript (ES6, fetch)

This example expects a File object to be set as variable file, and a string named uploadKeyto contain the shop's upload key.
// Get upload URL for our shop
const res = await fetch(`${uploadKey}`)
const url = await res.text();
console.log(`Upload URL: ${url}`);
// Do a PUT request with our File object
await fetch(url, { method: "PUT", body: file });
console.log('Uploaded file successfully');

PHP (curl)

This code snippet expects a stock.csv file to be saved to disk. If you need an example on how to create this file from an array of data, have a look at our FTP PHP example.
// Define upload key and file path
$upload_key = '<<your upload key>>';
$csv_path = 'stock.csv';
// Get upload URL
$url = file_get_contents('' . $upload_key);
// Upload file to URL using CURL and PUT request
$fh_res = fopen($csv_path, 'r');
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_INFILE => $fh_res,
CURLOPT_INFILESIZE => filesize($csv_path),
'Content-Type: text/csv'
// Output status code (should be 200)
echo curl_getinfo($ch, CURLINFO_HTTP_CODE);

C# (Unirest)

This example uses the library Unirest to do the HTTP calls, but something similar should work with any other HTTP library.
// Define upload URL and CSV data
string uploadKey = "<<your upload key>>";
string data = "barcode,...";
// Get upload URL
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
var url = Unirest.get($"{uploadKey}")
// Upload CSV data
var response = Unirest.put(url)
.header("Accept", "application/json")
.header("Content-Type", "text/csv")
// Check result (response.Code should be 200)
Console.WriteLine($"Response code: {response.Code} {response.Body}");


A great low-tech way to get file uploads working in a PowerShell script that you execute on a timer.
# Update these variables
$csvPath = "C:\local\path\stock.csv" # Point this to your CSV file
$uploadKey = "xxxxxxxxx" # Set your Upload key / FTP password here
# Everything below here can stay the same
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# Get upload URL
$uploadUri = (Invoke-WebRequest -Uri "${uploadKey}?type=stock").Content
# Perform PUT
$wc = New-Object System.Net.WebClient
$wc.UploadFile($uploadUri, "PUT", $csvPath)
Write-Output "File uploaded to NearSt!"