Getting started overview
Integrating with Cloudmersive APIs requires a developer account and an API key for authentication. Cloudmersive provides a suite of APIs for tasks such as virus scanning, document conversion, image recognition, and data validation. The initial setup process focuses on quickly obtaining credentials and making a test call to confirm connectivity and authentication.
The Cloudmersive developer portal offers comprehensive documentation and client SDKs for various programming languages to streamline the integration process. These SDKs abstract the underlying HTTP requests, allowing developers to interact with the API using native language constructs. For instance, the Cloudmersive developer overview details the range of available services and tools.
Here's a quick reference guide to the initial steps:
| Step | What to Do | Where |
|---|---|---|
| 1. Account Creation | Register for a free Cloudmersive developer account. | Cloudmersive homepage |
| 2. API Key Retrieval | Locate your unique API key in the developer dashboard. | Cloudmersive developer dashboard |
| 3. Choose SDK/Method | Select a preferred SDK (e.g., Python, Node.js) or use raw HTTP. | Cloudmersive SDKs section |
| 4. Install SDK | Add the Cloudmersive client library to your project. | Project dependency manager (e.g., npm, pip) |
| 5. Make First Request | Execute a simple API call, such as a virus scan or text validation. | Your code editor/IDE |
| 6. Verify Response | Confirm the API call returns a successful and expected result. | Application console or debugger |
Create an account and get keys
To begin using Cloudmersive APIs, you first need to create a developer account. This process typically involves providing an email address and setting a password. Upon successful registration, you will gain access to the Cloudmersive developer dashboard.
Your API key is a unique alphanumeric string that authenticates your requests to Cloudmersive services. It acts as a credential to verify your identity and authorize access to the APIs you are permitted to use. Cloudmersive issues one primary API key per account, which can be found in your dashboard immediately after signup. It's crucial to keep this key confidential and avoid embedding it directly into client-side code that could be publicly exposed, as recommended for any API key usage by security best practices like those outlined by Google Cloud API key best practices.
To locate your API key:
- Navigate to the Cloudmersive homepage and select the 'Sign Up' or 'Get Started' option.
- Complete the registration form.
- Once logged in, look for a section labeled 'API Key' or 'My Keys' within your developer dashboard.
- Copy the displayed API key. This key will be used in the header or as a query parameter for all your API requests.
Cloudmersive offers a free API key that includes 800 API calls per month, which is sufficient for initial development and testing purposes. For higher usage or specific features, various paid plans are available.
Your first request
Making your first API request with Cloudmersive involves selecting an API, choosing a programming language, and using your API key for authentication. For this example, we'll demonstrate a simple virus scan using the Virus Scan API, which is a common starting point for content processing and security. Cloudmersive provides SDKs for languages such as C#, Java, Node.js, Python, PHP, Go, Ruby, and Objective-C.
Example: Python SDK - Virus Scan
This example demonstrates how to perform a basic virus scan on a file using the Python SDK. Ensure you have Python installed and then install the Cloudmersive Virus Scan client library:
pip install cloudmersive-virus-api-client
Next, use the following Python code snippet:
from __future__ import print_function
import time
import cloudmersive_virus_api_client
from cloudmersive_virus_api_client.rest import ApiException
from pprint import pprint
# Configure API key authorization: Apikey
configuration = cloudmersive_virus_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'
# Uncomment the following line to set a prefix for the API key, e.g. 'Token'
# configuration.api_key_prefix['Apikey'] = 'Token'
# create an instance of the API class
api_instance = cloudmersive_virus_api_client.ScanApi(cloudmersive_virus_api_client.ApiClient(configuration))
input_file = '/path/to/your/file.txt' # file | Input file to perform the operation on.
try:
# Scan a file for viruses
api_response = api_instance.scan_file(input_file)
pprint(api_response)
except ApiException as e:
print("Exception when calling ScanApi->scan_file: %s\n" % e)
Replace 'YOUR_API_KEY' with your actual Cloudmersive API key and '/path/to/your/file.txt' with the path to a test file on your system. This code initializes the API client with your key and then calls the scan_file method to upload and scan the specified file. The response will indicate whether viruses or other threats were detected.
Example: Node.js SDK - Document Conversion
For Node.js developers, you can convert a document, for instance, a DOCX file to PDF. First, install the necessary SDK:
npm install cloudmersive-convert-api-client --save
Then, use this JavaScript code:
var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');
var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;
// Configure API key authorization: Apikey
var Apikey = defaultClient.authentications['Apikey'];
Apikey.apiKey = 'YOUR_API_KEY';
var apiInstance = new CloudmersiveConvertApiClient.ConvertDocumentApi();
var inputFile = Buffer.from(require('fs').readFileSync('/path/to/your/document.docx').buffer);
var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
// Save the PDF locally
require('fs').writeFileSync('output.pdf', data);
}
};
apiInstance.convertDocumentDocxToPdf(inputFile, callback);
Remember to replace 'YOUR_API_KEY' and '/path/to/your/document.docx' with your specific details. This example reads a DOCX file, sends it for conversion, and saves the resulting PDF locally.
Common next steps
After successfully making your first API call, consider these next steps to further integrate Cloudmersive into your application:
- Explore other APIs: Cloudmersive offers a wide range of APIs beyond virus scanning and document conversion. Explore the Cloudmersive API reference for services like email and phone validation, image recognition, and natural language processing.
- Integrate with production code: Move your API calls from test scripts into your application's codebase, ensuring proper error handling and logging.
- Implement asynchronous processing: For large files or operations that might take longer, consider using asynchronous patterns to avoid blocking your application's main thread.
- Monitor usage: Keep track of your API call usage through the Cloudmersive developer dashboard to stay within your plan limits or anticipate upgrades.
- Secure your API key: Ensure your API key is stored securely, using environment variables or a secrets management service, especially in production environments. Avoid hardcoding it directly into your application. Best practices for API key security are detailed by resources such as the Twilio API key guide.
- Upgrade your plan: If your application requires more than 800 calls per month, review the Cloudmersive pricing plans to select a tier that matches your expected usage.
Troubleshooting the first call
Encountering issues during your first API call is common. Here are some troubleshooting tips:
- Invalid API Key: Double-check that you have copied your API key correctly from your Cloudmersive dashboard. An incorrect key will typically result in an authentication error (e.g., HTTP 401 Unauthorized).
- Network Connectivity: Ensure your development environment has an active internet connection and that no firewalls or proxies are blocking outgoing requests to the Cloudmersive API endpoints.
- Incorrect Endpoint or Method: Verify that you are calling the correct API endpoint and using the appropriate HTTP method (GET, POST, etc.) for the specific Cloudmersive API you are trying to use. Refer to the Cloudmersive API documentation for exact endpoint details.
- Missing Required Parameters: Some API calls require specific parameters or a body in the request. Check the API documentation for the exact requirements for the method you are using.
- SDK Configuration Issues: If using an SDK, ensure it is correctly installed and configured. Verify that the API key is being passed to the SDK client correctly.
- File Path Errors: For file-based APIs, ensure the file path provided is correct and that your application has the necessary permissions to read the file.
- Rate Limiting: While less likely on a first call, be aware of rate limits. If you make too many requests in a short period, the API might temporarily block further requests (HTTP 429 Too Many Requests). The free tier has a monthly limit of 800 calls.
- Error Messages: Pay close attention to the error messages returned by the API. These often provide specific clues about what went wrong. Cloudmersive API error responses are designed to be informative.
- Consult Documentation: The Cloudmersive developer documentation is a primary resource for detailed information on each API, error codes, and examples.