Skip to main content

Examples

This bash script demonstrates a complete FTP account CRUD workflow using HTTPie and jq.

The example performs the following operations:

  1. Authenticate against the Management API
  2. Create a new FTP account
  3. Retrieve the account
  4. Update the account
  5. Retrieve the updated account
  6. Delete the account

Requirements

Install:

Full Example

#!/bin/bash

#
# Authenticate and retrieve Bearer token
#

TOKEN=$(http --body POST https://api.ftpgrid.com/apiaccess/auth \
AssociationKey="YOUR_ASSOCIATION_KEY" \
AccessKey="YOUR_ACCESS_KEY" \
SecretKey="YOUR_SECRET_KEY" | jq -r '.token')

echo "Access token: $TOKEN"

#
# Create FTP account
#

ID=$(http POST https://api.ftpgrid.com/ftpaccounts/auto \
Authorization:"Bearer $TOKEN" | jq -r '.ID')

echo "FTP Account ID: $ID"

#
# Retrieve FTP account
#

http GET https://api.ftpgrid.com/ftpaccounts/id/$ID \
Authorization:"Bearer $TOKEN"

#
# Update FTP account
#

http PATCH https://api.ftpgrid.com/ftpaccounts \
Authorization:"Bearer $TOKEN" \
Id:=$ID \
Description="Updated using CLI"

#
# Retrieve updated FTP account
#

http GET https://api.ftpgrid.com/ftpaccounts/id/$ID \
Authorization:"Bearer $TOKEN"

#
# Delete FTP account
#

http DELETE https://api.ftpgrid.com/ftpaccounts/id/$ID \
Authorization:"Bearer $TOKEN"

echo "FTP account deleted"

Notes

  • The /ftpaccounts/auto endpoint automatically generates a secure username and password
  • The generated FTP account can immediately be used with FTP, FTPS, SFTP, and SCP
  • The Authorization header must contain a valid Bearer token
  • Passwords are never returned by the API after creation