Authentication overview
To interact with the ShipStation API, all requests must be authenticated. ShipStation employs Basic HTTP Authentication for securing API access. This method requires developers to provide an API key and an API secret with every API call. These credentials act as a unique identifier and a shared secret, enabling the ShipStation server to verify the identity of the client making the request and authorize access to account-specific resources. The API is designed as a RESTful service, accepting and returning data in JSON format, as detailed in the ShipStation API reference documentation.
Basic HTTP Authentication transmits credentials as a base64-encoded string in the Authorization header of an HTTP request. The format typically involves concatenating the API key and secret with a colon (:) in between, then encoding the resulting string. This approach is standard for many RESTful APIs due to its simplicity and broad client support, though it requires secure transmission, such as over HTTPS, to protect the credentials in transit, as noted in MDN Web Docs on Basic Authentication.
ShipStation's API design also includes comprehensive documentation with code examples in various programming languages, facilitating the integration process for developers using different technology stacks.
Supported authentication methods
ShipStation primarily supports one method for API authentication:
- Basic HTTP Authentication with API Key and Secret: This is the standard and only direct method for programmatic access to the ShipStation API. It involves passing an API key and an API secret with each request.
The table below summarizes the primary authentication method:
| Method | When to Use | Security Level |
|---|---|---|
| Basic HTTP Authentication (API Key & Secret) | Programmatic access to ShipStation API for integrations, custom applications, and server-side operations. | Moderate (Requires secure transport like HTTPS to protect credentials in transit. Credential management critical.) |
While Basic HTTP Authentication is straightforward, its security relies heavily on the secure handling and storage of the API key and secret. Always ensure that requests are made over HTTPS to encrypt the credentials during transmission, preventing eavesdropping and unauthorized access, consistent with RFC 7235 on HTTP Authentication recommendations.
Getting your credentials
To obtain the necessary API key and API secret for ShipStation, you must generate them within your ShipStation account. This process ensures that only authorized users can create and manage API credentials associated with their account. The steps are generally as follows:
- Log in to your ShipStation account: Access the ShipStation web application using your administrative credentials.
- Navigate to API Settings: Once logged in, go to
Settings(the gear icon) in the upper right corner. - Select
API Settings: Under theAPI Settingssection, you will find options related to API access. - Generate or view credentials: If you have not yet generated credentials, you will see an option to generate a new API key and API secret. If they already exist, you can view them. ShipStation typically allows you to view the API key directly, but the API secret might only be shown once upon generation for security reasons. It's crucial to record the API secret immediately upon generation, as it may not be retrievable later.
- Copy and store securely: Copy both the API key and API secret. Store them in a secure location, such as an environment variable, a secrets manager, or a secure configuration file, avoiding direct embedding in code.
- Regenerate (if needed): If your API key or secret is compromised, or you need to rotate credentials for security policies, ShipStation provides an option to regenerate them. Regenerating credentials will invalidate the old ones, requiring updates in all your integrated applications.
It is recommended to generate separate API keys for different integrations or applications if your workflow allows, to minimize the impact of a potential compromise and facilitate easier credential rotation and revocation.
Authenticated request example
After obtaining your API Key and API Secret, you can construct an authenticated request to the ShipStation API. The credentials must be base64-encoded and included in the Authorization header using the Basic scheme. Below is an example using curl, a common command-line tool for making HTTP requests, as demonstrated in ShipStation's developer documentation.
First, combine your API Key and API Secret with a colon:
YOUR_API_KEY:YOUR_API_SECRET
Then, base64-encode this string. For example, if YOUR_API_KEY is a1b2c3d4e5f6g7h8 and YOUR_API_SECRET is i9j0k1l2m3n4o5p6, the combined string would be a1b2c3d4e5f6g7h8:i9j0k1l2m3n4o5p6.
The base64-encoded value might look something like YTFiMmMzZDRlNWY2ZzdoODppOWowazFsMm0zbjRvNXA2 (this is an example and will vary based on your actual keys).
Now, include this encoded string in the Authorization header:
curl -X GET \
-H "Content-Type: application/json" \
-H "Authorization: Basic YTFiMmMzZDRlNWY2ZzdoODppOWowazFsMm0zbjRvNXA2" \
"https://ssapi.shipstation.com/orders"
This curl command attempts to retrieve a list of orders from the ShipStation API. Replace the placeholder base64 string with your actual encoded credentials. For programmatic implementations, most HTTP client libraries provide methods to handle Basic HTTP Authentication, simplifying the encoding process. For example, in Python with the requests library:
import requests
api_key = "YOUR_API_KEY"
api_secret = "YOUR_API_SECRET"
url = "https://ssapi.shipstation.com/orders"
response = requests.get(url, auth=(api_key, api_secret))
if response.status_code == 200:
print(response.json())
else:
print(f"Error: {response.status_code}, {response.text}")
This Python example directly uses the auth parameter, allowing the library to handle the base64 encoding and header construction automatically.
Security best practices
Securing your ShipStation API integration is critical to protect sensitive shipping and order data. Adhere to the following best practices:
- Use HTTPS for all API calls: Always ensure that all communications with the ShipStation API occur over HTTPS. This encrypts the data in transit, preventing unauthorized parties from intercepting your API key, secret, and sensitive information. ShipStation's API endpoints are designed to enforce HTTPS, but it is a fundamental security practice to verify this in your client code.
- Safeguard API Key and Secret: Treat your API key and secret as sensitive as passwords.
- Avoid hardcoding: Do not embed credentials directly in your application's source code.
- Environment variables: Store credentials in environment variables for server-side applications.
- Secrets management: Utilize dedicated secrets management services (e.g., AWS Secrets Manager, Google Secret Manager, Azure Key Vault) for robust protection and rotation capabilities. Refer to Google Cloud Secret Manager's overview for an example of such a service.
- Secure configuration files: If using configuration files, ensure they are secured with appropriate file permissions and never committed to version control systems like Git.
- Implement Least Privilege: If ShipStation offers granular permissions for API keys (check ShipStation's official documentation for specific capabilities), create keys with the minimum necessary permissions required for your application's functionality. This limits the damage if a key is compromised.
- Regular Credential Rotation: Periodically rotate your API key and secret. This reduces the window of exposure if a key is inadvertently compromised. ShipStation allows key regeneration within your account settings.
- Monitor API Usage: Regularly review API logs and usage patterns for any unusual activity that might indicate unauthorized access or misuse of your credentials. Implement alerting for suspicious spikes or failed authentication attempts.
- Error Handling and Logging: Implement robust error handling for API responses, especially for authentication failures. Log these failures securely for auditing and incident response, but avoid logging the raw API key or secret.
- Input Validation: Sanitize and validate all data sent to the ShipStation API to prevent common web vulnerabilities like injection attacks.
- Secure Development Lifecycle: Integrate security considerations throughout your development process, from design to deployment and maintenance. Regular security audits and penetration testing of your integrated applications are recommended.
Adhering to these practices will help maintain the integrity and confidentiality of your ShipStation data and API access.