Skip to main content

AfasConnector

The AfasConnector class provides a convenient interface for interacting with AFAS Connectors via HTTP requests. It simplifies the process of sending GET, POST, and PUT requests to your AFAS Connectors and handling their responses.

Features

  • Easy configuration through environment variables.
  • Support for GET, POST, and PUT requests.
  • Integrated filtering, ordering, and pagination for GET requests.
  • Automatic handling of AFAS token authentication.

Usage

First, set the necessary environment variables:

AFAS_CONNECTORS_URL: The base URL for your AFAS Connectors. AFAS_TOKEN: Your AFAS token. Here's an example of how to use AfasConnector in your Python code:

from afas import AfasConnector

# Initialize the connector
connector = AfasConnector()

# GET request example
status_code, response = connector.get(endpoint='Profit_OData/SomeEndpoint', filters=[...])
if status_code == 200:
    print(response)

# PUT request example
payload = {...}
status_code, response = connector.put(endpoint='Profit_OData/SomeEndpoint', payload=payload)
if status_code == 200:
    print(response)

# POST request example
payload = {...}
status_code, response = connector.post(endpoint='Profit_OData/SomeEndpoint', payload=payload)
if status_code == 200:
    print(response)

Handling Responses and Errors

Each method returns a tuple containing the HTTP status code and the response from the AFAS Connector. A successful request will return a status code of 200. If the request is unsuccessful, the status code can be used to diagnose the issue. The second element of the tuple will be the JSON response for successful requests or None in case of an error.

AfasFilter

The AfasFilter class provides a way to define filters for the AFAS Connectors. It allows you to specify the field, value(s), and operator for the filter.

Usage

Here's an example of how to use the AfasFilter class:

# Create an example of using the AfasFilter class
filter = AfasFilter(field='Itemcode', value='1234', operator=AfasFilter.EQUAL_TO)
filter_OR = AfasFilter(field='Itemcode', value=['1234', '4321'], operator=[AfasFilter.EQUAL_TO, AfasFilter.EQUAL_TO])

# Convert the filters to a query string
query = afas_filters_to_query([filter, filter_OR])

# Print the query string
print(query)

AfasObject

The AfasObject is a wrapper for updating an item in Afas. The object has an update method that uses the AfasConnector class to update an item in a single line.

Usage

Here's an exampke of how to use the AfasObject class:

from afas.afas_object import AfasObject

# Create an instance of AfasObject
obj = AfasObject('FbItemArticle', {'Field1': 'Value1', 'Field2': 'Value2'})

# Update the object in AFAS Profit
status_code, response = obj.update()
if status_code == 200:
    print("Object updated successfully")
else:
    print("Failed to update object")

# Get a string representation of the object
print(str(obj))

Metadata

Release files for afas-connector 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for afas-connector 0.1.5
File Size Uploaded
afas_connector-0.1.5.tar.gz 5.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for afas-connector 0.1.5
File Interpreter ABI Platform
afas_connector-0.1.5-py3-none-any.whl Python 3 none any Details

Total release size: 12.9 kB

Release files / afas_connector-0.1.5.tar.gz

Download URL afas_connector-0.1.5.tar.gz
Size 5.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ec9921a99f54b661072782d488a1a677a4f64d2ba3ceab93687c3c889705f5fd
BLAKE2b-256 checksum
How to use checksums
5598acaedc32076c2abd2d8025819388a3da4328b27c7ad5bb404c79556922d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.19

Release files / afas_connector-0.1.5-py3-none-any.whl

Download URL afas_connector-0.1.5-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5a1bacfaf0c6b16b6dd1b6842d8dffc6c15e3ded6f8c7b76da30432887b5aa90
BLAKE2b-256 checksum
How to use checksums
a8e802eeb9a6b06f0d4e6cb378b5a524903a1c252be233b9ee49063b61393f7b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.19

Release history Release notifications | RSS feed

This release

0.1.5 This release

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page