Skip to content

Instantly share code, notes, and snippets.

@ibuilder
Created April 24, 2025 16:41
Show Gist options
  • Save ibuilder/2f24dd068061935ded33df434ec9d8a0 to your computer and use it in GitHub Desktop.
Save ibuilder/2f24dd068061935ded33df434ec9d8a0 to your computer and use it in GitHub Desktop.
Python script that makes an API call to import invoices with authentication
import requests
import json
# API configuration
BASE_URL = "https://api.textura.oraclecloud.com" # Replace with your actual Textura API base URL
ENDPOINT = "/invoices/import" # Endpoint for invoice import (adjust if different)
API_KEY = "your_api_key_here" # Replace with your actual API key or token
# Sample invoice data (modify according to your requirements and API specs)
invoice_data = {
"invoice": {
"invoiceNumber": "INV-12345",
"projectId": "PROJECT-001",
"contractorId": "CONTRACTOR-001",
"invoiceDate": "2025-04-24",
"dueDate": "2025-05-24",
"amount": 10000.00,
"currency": "USD",
"lineItems": [
{
"lineItemId": "LI-001",
"description": "Construction Materials",
"quantity": 100,
"unitPrice": 100.00,
"totalAmount": 10000.00
}
]
}
}
# Headers for authentication and content type
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
"Accept": "application/json"
}
# Function to make the API call
def import_invoice():
try:
# Make the POST request to import the invoice
response = requests.post(
f"{BASE_URL}{ENDPOINT}",
headers=headers,
data=json.dumps(invoice_data)
)
# Check the response status
if response.status_code == 201:
print("Invoice imported successfully!")
print("Response:", response.json())
else:
print(f"Failed to import invoice. Status code: {response.status_code}")
print("Error:", response.text)
except requests.exceptions.RequestException as e:
print(f"An error occurred: {e}")
# Execute the function
if __name__ == "__main__":
import_invoice()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment