acumatica - How to insert attribute values with the REST API?

Acumatica - How to insert attribute values with the REST API?

In Acumatica ERP, inserting attribute values via the REST API involves a structured approach to ensure that data is correctly formatted and mapped to the appropriate fields in the system. Here's a general guide on how to insert attribute values using Acumatica's REST API:

Understanding Attributes in Acumatica

Attributes in Acumatica represent additional data fields that can be associated with various entities such as Customers, Orders, Items, etc. These attributes are defined in Acumatica and can vary depending on your customization and setup.

Inserting Attribute Values via REST API

To insert attribute values via Acumatica's REST API, follow these steps:

  1. Authenticate and Obtain Session ID:

    Before making any API calls, authenticate and obtain a session ID using OAuth2 or basic authentication. Ensure your credentials have sufficient permissions to create or update data.

  2. Identify the Entity and Attributes:

    Determine the entity (e.g., Customer, Order, Item) for which you want to insert attribute values. Also, identify the specific attributes you need to populate.

  3. Construct the API Endpoint:

    Construct the API endpoint to insert attribute values. The endpoint typically follows this format:

    POST /entity/endpoint
    

    Replace /entity/endpoint with the specific endpoint for the entity you are working with. For example, if you are inserting attributes for Customers, the endpoint might look like /entity/Default/18.200.001/Customer.

  4. Prepare the Request Payload:

    Prepare the request payload (JSON format) with the attribute values you want to insert. The JSON structure should match the expected format defined by Acumatica for attributes.

    Here's a basic example for inserting attributes for a Customer:

    {
        "Attributes": [
            {
                "AttributeID": "MyCustomAttribute",
                "Value": "Attribute value"
            }
        ]
    }
    
    • AttributeID: Replace with the actual ID or name of the attribute defined in Acumatica.
    • Value: Replace with the value you want to assign to this attribute for the specified entity.
  5. Send the POST Request:

    Use a tool like Postman, cURL, or a programming language library (e.g., Python requests, JavaScript fetch) to send the POST request to the constructed API endpoint.

    • Include the appropriate headers (e.g., Content-Type: application/json) and authentication details in your request.
  6. Handle the Response:

    After sending the request, handle the response from Acumatica's REST API. Ensure to check for success or any error messages returned by the API.

Example in Postman

Here's a quick example of how you might structure the POST request in Postman:

  • Method: POST

  • URL: https://your-acumatica-instance/entity/Default/18.200.001/Customer

  • Headers:

    • Authorization: Bearer your_access_token
    • Content-Type: application/json
  • Body (raw JSON):

    {
        "Attributes": [
            {
                "AttributeID": "MyCustomAttribute",
                "Value": "Attribute value"
            }
        ]
    }
    

    Adjust AttributeID and Value according to your actual attribute and data.

Notes:

  • AttributeID: Ensure the AttributeID matches exactly with what is defined in your Acumatica instance.
  • Permissions: Ensure your API user has sufficient permissions to insert attribute values for the specified entity.
  • Testing: Always test your API calls in a non-production environment before deploying changes to production.

By following these steps, you can effectively insert attribute values using Acumatica's REST API, providing flexibility to extend and customize data fields as needed within your ERP system. Adjust the endpoint, payload, and authentication details based on your specific setup and requirements.

Examples

  1. How to authenticate and get a token in Acumatica REST API?

    import requests
    
    url = "https://acumatica-instance.com/entity/auth/login"
    payload = {
        "name": "admin",
        "password": "password",
        "tenant": "tenantName",
        "locale": "en-US",
        "company": "companyName"
    }
    
    response = requests.post(url, json=payload)
    token = response.json().get('token')
    

    Description: This code authenticates and retrieves a token required for making subsequent REST API calls to Acumatica.

  2. How to get an entity using Acumatica REST API?

    headers = {
        'Authorization': f'Bearer {token}',
        'Content-Type': 'application/json'
    }
    response = requests.get("https://acumatica-instance.com/entity/Default/17.200.001/Customer?$filter=CustomerID eq 'ABC'", headers=headers)
    customer = response.json()
    

    Description: This code retrieves an entity (Customer) using the Acumatica REST API with proper authentication headers.

  3. How to update an attribute value for an entity in Acumatica using REST API?

    url = "https://acumatica-instance.com/entity/Default/17.200.001/Customer"
    payload = {
        "CustomerID": "ABC",
        "Attributes": [
            {
                "AttributeID": "CUSTOMATTR",
                "Value": "NewValue"
            }
        ]
    }
    response = requests.put(url, headers=headers, json=payload)
    

    Description: This code updates an attribute value for a Customer entity in Acumatica using the REST API.

  4. How to insert a new entity with attributes using Acumatica REST API?

    url = "https://acumatica-instance.com/entity/Default/17.200.001/Customer"
    payload = {
        "CustomerID": "NEWCUST",
        "CustomerName": "New Customer",
        "Attributes": [
            {
                "AttributeID": "CUSTOMATTR",
                "Value": "AttributeValue"
            }
        ]
    }
    response = requests.post(url, headers=headers, json=payload)
    

    Description: This code inserts a new Customer entity with attributes into Acumatica using the REST API.

  5. How to filter entities by attribute values using Acumatica REST API?

    url = "https://acumatica-instance.com/entity/Default/17.200.001/Customer?$filter=Attributes/any(a:a/AttributeID eq 'CUSTOMATTR' and a/Value eq 'Value')"
    response = requests.get(url, headers=headers)
    customers = response.json()
    

    Description: This code retrieves Customers filtered by attribute values using the Acumatica REST API.

  6. How to delete an entity in Acumatica using REST API?

    url = "https://acumatica-instance.com/entity/Default/17.200.001/Customer('ABC')"
    response = requests.delete(url, headers=headers)
    

    Description: This code deletes a Customer entity in Acumatica using the REST API.

  7. How to insert attribute values for an existing entity using Acumatica REST API?

    url = "https://acumatica-instance.com/entity/Default/17.200.001/Customer"
    payload = {
        "CustomerID": "EXISTCUST",
        "Attributes": [
            {
                "AttributeID": "NEWATTR",
                "Value": "NewValue"
            }
        ]
    }
    response = requests.put(url, headers=headers, json=payload)
    

    Description: This code inserts attribute values for an existing Customer entity using the Acumatica REST API.

  8. How to get the list of available attributes for an entity in Acumatica using REST API?

    url = "https://acumatica-instance.com/entity/Default/17.200.001/Customer/Attributes"
    response = requests.get(url, headers=headers)
    attributes = response.json()
    

    Description: This code retrieves the list of available attributes for the Customer entity using the Acumatica REST API.

  9. How to handle errors when inserting attribute values using Acumatica REST API?

    try:
        url = "https://acumatica-instance.com/entity/Default/17.200.001/Customer"
        payload = {
            "CustomerID": "ERRCUST",
            "Attributes": [
                {
                    "AttributeID": "ATTR",
                    "Value": "InvalidValue"
                }
            ]
        }
        response = requests.put(url, headers=headers, json=payload)
        response.raise_for_status()
    except requests.exceptions.RequestException as e:
        print(f"Error: {e}")
    

    Description: This code handles errors when inserting attribute values using the Acumatica REST API by catching exceptions.

  10. How to check if an entity with specific attributes already exists using Acumatica REST API?

    url = "https://acumatica-instance.com/entity/Default/17.200.001/Customer?$filter=CustomerID eq 'EXISTCUST' and Attributes/any(a:a/AttributeID eq 'ATTR' and a/Value eq 'Value')"
    response = requests.get(url, headers=headers)
    exists = response.json()
    if exists:
        print("Entity with specified attributes exists.")
    else:
        print("Entity with specified attributes does not exist.")
    

    Description: This code checks if an entity with specific attributes already exists using the Acumatica REST API.


More Tags

jupyterhub laravel-3 applicationcontext android-dialogfragment presentation typescript fibonacci sweetalert ajaxform rfc5766turnserver

More Programming Questions

More Statistics Calculators

More Cat Calculators

More Retirement Calculators

More General chemistry Calculators