Library
FD1 Client Protocol Examples
Curl uses HTTP mode requests, so each individual request is silently converted to a websocket type request on the server and then closed. This means
- You must send authorization details on every request. The examples below typically omit this header.
curl -H "x-apikey: your-secret" ...
- The endpoints fd1.firehose... are unavailable. These allow the server to stream data to your client, and require a persistant connection
- FD1 protocol uses [ and ] as part of the protocol. These are also used for url globbing by curl. You need to add the switch -g to disable curl globbing, or if you wish to use globbing, setup the requests per curl requirements.
Simple Fetching Examples
curl -g "http://127.0.0.1:3490/fd1/data?_v.table=physical.products[plucode=8145]&_qo=pid,description"
» {"data":{"rows":[{"pid":6325,"description":"FRAGADOR TABLETS"}]}}
curl "http://127.0.0.1:3490/fd1/data?_v.table=physical.products&plucode=8145&_qo=pid,description"
» {"data":{"rows":[{"pid":6325,"description":"FRAGADOR TABLETS"}]}}
Updating Records
Setting the description on a product
This general pattern can be used for other endpoints too, such as customer, account, locations.
curl -H "content-type: application/json"
-H "x-apikey: your-secret-key"
-d '{"a":"fd1.products.edit_products", "k": 6011, "v": { "description", "My New Description"}}'
"http://your-server.example.com/fd1/products/edit_products"
Encrypting Payload before transmission
Sending a customer edit, encrypting the json before transmission. ie An encrypted payload sent over an HTTPS channel.
# 1. The string to encrypt
$plainText = '{"a":"fd1.customers.edit_customers", "k": 1234, "v": { "email", "faraaz@example.com"}}'
# 2. Convert to Secure String and then to Encrypted String
$secureString = $plainText | ConvertTo-SecureString -AsPlainText -Force
$encryptedString = [System.Runtime.InteropServices.Marshal::PtrToStringAuto](
[System.Runtime.InteropServices.Marshal::SecureStringToBSTR](
(ConvertTo-SecureString -String ($secureString | ConvertFrom-SecureString) -Key (1..32))
)
)
# Use a key for portability, or omit -Key for machine-specific DPAPI
# Note: For portability to other machines, use -Key with a 32-byte key instead of default DPAPI [10].
# 3. Define the URL ~e means encrypted, the "1" means registerd key #1
$url = "https://debug.ingest....com/upload/~e1"
# 4. Prepare data for POST (JSON format is common)
$body = @{
data = $encryptedString
} | ConvertTo-Json
# 5. Post to URL
Invoke-RestMethod -Uri $url -Method Post -Body $body -ContentType "application/json"