cURL Examples

Command line integration and testing

Setup

cURL is pre-installed on most Unix-based systems (Linux, macOS). For Windows, use Git Bash or WSL.

💡 Tip: Use Environment Variables

Export your API key as an environment variable for convenience:

export API_KEY="c2p_live_your_api_key_here"

Then use $API_KEY in your commands.

1. Simple GET Request

Fetch account information:

curl -X GET "https://app1.connect2print.com/api/v1/account" \ -H "Authorization: Bearer c2p_live_your_api_key_here" \ -H "Accept: application/json"

With Environment Variable

curl -X GET "https://app1.connect2print.com/api/v1/account" \ -H "Authorization: Bearer $API_KEY" \ -H "Accept: application/json"

Pretty Print JSON Output

curl -X GET "https://app1.connect2print.com/api/v1/account" \ -H "Authorization: Bearer $API_KEY" \ -H "Accept: application/json" | jq .

2. List Orders

Fetch orders with pagination:

curl -X GET "https://app1.connect2print.com/api/v1/orders?page=1&per_page=25" \ -H "Authorization: Bearer $API_KEY" \ -H "Accept: application/json"

Filter by Status

curl -X GET "https://app1.connect2print.com/api/v1/orders?status=completed&page=1" \ -H "Authorization: Bearer $API_KEY" \ -H "Accept: application/json"

Filter by Date Range

curl -X GET "https://app1.connect2print.com/api/v1/orders?created_after=2026-01-01&created_before=2026-01-31" \ -H "Authorization: Bearer $API_KEY" \ -H "Accept: application/json"

3. Get Single Order

Fetch a specific order by ID:

curl -X GET "https://app1.connect2print.com/api/v1/orders/123" \ -H "Authorization: Bearer $API_KEY" \ -H "Accept: application/json"

Save Response to File

curl -X GET "https://app1.connect2print.com/api/v1/orders/123" \ -H "Authorization: Bearer $API_KEY" \ -H "Accept: application/json" \ -o order_123.json

4. Create a Customer (POST)

Create a new customer with JSON data:

curl -X POST "https://app1.connect2print.com/api/v1/customers" \ -H "Authorization: Bearer $API_KEY" \ -H "Content-Type: application/json" \ -H "Accept: application/json" \ -d '{ "email": "john.doe@example.com", "company_name": "Acme Corporation", "contact_name": "John Doe", "phone": "+45 12 34 56 78", "billing_address": { "street_address": "Main Street 123", "city": "Copenhagen", "postal_code": "1000", "country": "DK" } }'

Using Data from File

curl -X POST "https://app1.connect2print.com/api/v1/customers" \ -H "Authorization: Bearer $API_KEY" \ -H "Content-Type: application/json" \ -H "Accept: application/json" \ -d @customer.json

5. Update an Order (PATCH)

Update specific fields of an order:

curl -X PATCH "https://app1.connect2print.com/api/v1/orders/123" \ -H "Authorization: Bearer $API_KEY" \ -H "Content-Type: application/json" \ -H "Accept: application/json" \ -d '{ "status": "processing", "internal_notes": "Printing started on machine #2" }'

6. Upload a File (Multipart)

Upload a production file:

curl -X POST "https://app1.connect2print.com/api/v1/files/upload" \ -H "Authorization: Bearer $API_KEY" \ -H "Accept: application/json" \ -F "file=@/path/to/your/file.pdf" \ -F "related_type=order" \ -F "related_id=123"

Upload with Progress Bar

curl -X POST "https://app1.connect2print.com/api/v1/files/upload" \ -H "Authorization: Bearer $API_KEY" \ -H "Accept: application/json" \ -F "file=@brochure.pdf" \ -F "related_type=order" \ -F "related_id=123" \ --progress-bar

7. Delete a Resource (DELETE)

Delete an address:

curl -X DELETE "https://app1.connect2print.com/api/v1/addresses/456" \ -H "Authorization: Bearer $API_KEY" \ -H "Accept: application/json"

8. View Response Headers

Include headers in output to see rate limits and other metadata:

curl -X GET "https://app1.connect2print.com/api/v1/orders" \ -H "Authorization: Bearer $API_KEY" \ -H "Accept: application/json" \ -i

View Only Headers

curl -X GET "https://app1.connect2print.com/api/v1/orders" \ -H "Authorization: Bearer $API_KEY" \ -H "Accept: application/json" \ -I

Look for these important headers:

X-RateLimit-Limit: 60 X-RateLimit-Remaining: 58 X-RateLimit-Reset: 1643723400 X-Request-Id: abc123def456

9. Test Webhook Signature

Simulate a webhook call with signature:

# Generate signature PAYLOAD='{"event":"order.created","data":{"id":123}}' SECRET="your_webhook_secret" SIGNATURE=$(echo -n "$PAYLOAD" | openssl dgst -sha256 -hmac "$SECRET" | cut -d ' ' -f 2) # Send webhook test curl -X POST "http://your-server.com/webhooks/connect2print" \ -H "Content-Type: application/json" \ -H "X-Webhook-Signature: $SIGNATURE" \ -d "$PAYLOAD"

10. Error Handling

Capture HTTP status code and handle errors:

# Save HTTP status code to variable HTTP_STATUS=$(curl -X GET "https://app1.connect2print.com/api/v1/orders/123" \ -H "Authorization: Bearer $API_KEY" \ -H "Accept: application/json" \ -o response.json \ -w '%{http_code}' \ -s) # Check status code if [ "$HTTP_STATUS" -eq 200 ]; then echo "Success!" cat response.json | jq . elif [ "$HTTP_STATUS" -eq 404 ]; then echo "Order not found" elif [ "$HTTP_STATUS" -eq 401 ]; then echo "Authentication failed - check your API key" else echo "Error: HTTP $HTTP_STATUS" cat response.json fi

11. Pagination Loop

Fetch all pages in a bash script:

#!/bin/bash API_KEY="c2p_live_your_api_key_here" BASE_URL="https://app1.connect2print.com/api/v1" PAGE=1 HAS_MORE=true # Fetch all orders while [ "$HAS_MORE" = "true" ]; do echo "Fetching page $PAGE..." RESPONSE=$(curl -s -X GET "$BASE_URL/orders?page=$PAGE&per_page=50" \ -H "Authorization: Bearer $API_KEY" \ -H "Accept: application/json") # Save orders from this page echo "$RESPONSE" | jq '.data[]' >> all_orders.json # Check if there are more pages HAS_MORE=$(echo "$RESPONSE" | jq -r '.pagination.has_more') if [ "$HAS_MORE" = "true" ]; then PAGE=$((PAGE + 1)) sleep 0.1 # Rate limit protection fi done echo "All orders fetched!"

12. Batch Operations

Update multiple resources from a CSV file:

#!/bin/bash # orders.csv format: order_id,new_status # 123,processing # 124,completed # 125,processing API_KEY="c2p_live_your_api_key_here" BASE_URL="https://app1.connect2print.com/api/v1" while IFS=',' read -r order_id status; do echo "Updating order $order_id to $status..." curl -X PATCH "$BASE_URL/orders/$order_id" \ -H "Authorization: Bearer $API_KEY" \ -H "Content-Type: application/json" \ -H "Accept: application/json" \ -d "{\"status\":\"$status\"}" \ -s -o /dev/null -w "HTTP %{http_code}\n" sleep 0.1 # Rate limit protection done < orders.csv echo "Batch update complete!"

Useful cURL Flags

Common Flags

-X METHOD - Specify HTTP method (GET, POST, PATCH, DELETE)

-H "Header: Value" - Add HTTP header

-d 'data' - Send data in request body

-d @file.json - Send data from file

-F "field=value" - Send multipart form data

-F "file=@path" - Upload file

-o file - Save output to file

-i - Include response headers

-I - Fetch headers only

-s - Silent mode (no progress bar)

-w - Output format after transfer

-v - Verbose output (debugging)

--progress-bar - Show progress bar

Best Practices

1. Use environment variables for secrets

Never hardcode API keys in scripts. Use export API_KEY="..." and $API_KEY.

2. Save responses for debugging

Use -o response.json to save responses for later inspection.

3. Check HTTP status codes

Always check the status code with -w '%{http_code}' to detect errors.

4. Use jq for JSON processing

Install jq (brew install jq or apt-get install jq) for parsing JSON responses.

5. Add delays in loops

Use sleep 0.1 between requests to respect rate limits.

6. Use verbose mode for debugging

Add -v flag to see full request/response for troubleshooting.