Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
453 views
in Technique[技术] by (71.8m points)

Acumatica Rest API get customer attribute name

I am trying to obtain values for Customer attributes via the Rest API. Currently, I can retrieve customer attributes, but am unable to determine which specific attribute is associated. For example, given this code (based on https://github.com/Acumatica/AcumaticaRESTAPIClientForCSharp, Endpoint = "Default", EndpointVersion = "18.200.001", Endpoint Library = Acumatica.Default_20.200.001, Acumatica version = Cloud ERP 2020 R1, Build 20.110.0017):

            var customerApi = new CustomerApi(configuration);
            var customers = customerApi.GetList(top: 5, expand: "Attributes", select: "Attributes/Attribute,Attributes/Value");

            foreach (var cust in customers)
            {
                Console.WriteLine(cust.ToString());
            }

Yields this output:

{
  
"AccountRef": {},
  "Attributes": [
    {
      "Value": {
        "value": "True"
      },
      "id": "8de7a85d-6d60-4235-9d35-74a9d08d1cc6",
      "rowNumber": 1,
      "custom": {}
    },
    {
      "Value": {
        "value": "Sample Email Body"
      },
      "id": "8da2a21c-2ba3-45ba-9e12-02122c626e11",
      "rowNumber": 2,
      "custom": {}
    }, ...

enter image description here

enter image description here

What am I missing to be able to get the attribute name returned as well? Or how I am supposed to correlate the given values back to a given attribute?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The default configuration of the Customers API is returning the Attributes array as below for the customerApi.GetList(top: 5, expand: "Attributes", select: "Attributes/Attribute,Attributes/Value"); request

 "Attributes": [
    {
      "Attribute": {
        "value": "Company Revenue"
      },
      "Value": {
        "value": "1,000,000 to 5,000,000"
      },
      "id": "6df69428-7157-438f-8b61-99b2d7d1a3ad",
      "rowNumber": 1,
      "custom": {}
    },
    {
      "Attribute": {
        "value": "Number of Employees"
      },
      "Value": {
        "value": "1-100"
      },
      "id": "15c3f47f-36eb-481b-92c0-f6b2f738732f",
      "rowNumber": 2,
      "custom": {}
    }
  ]

Attributes->Attribute->Value is the identifier for the Attribute which is corresponding to the Description of the Attribute record.

Your result is returned for customerApi.GetList(top: 5, expand: "Attributes", select: "Attributes/Value"); request. Please make sure that you have included the Attributes/Attribute in the select part if you are specifying it.

enter image description here

UPDATE

There is a small difference in naming between 18.200 and 20.200.

In 18.200 the Attribute ID is actually named Attribute
In 20.200 the Attribute ID is renamed to Attribute ID

That is why this request is working correctly for 18.200

namespace Acumatica.Default_18_200_001.Model
{
    [DataContract]
    public class AttributeDetail : Entity_v3
    {

        [DataMember(Name="Attribute", EmitDefaultValue=false)]
        public StringValue Attribute { get; set; }

        [DataMember(Name="RefNoteID", EmitDefaultValue=false)]
        public GuidValue RefNoteID { get; set; }

        [DataMember(Name="Required", EmitDefaultValue=false)]
        public BooleanValue Required { get; set; }

        [DataMember(Name="Value", EmitDefaultValue=false)]
        public StringValue Value { get; set; }

    }
}



namespace Acumatica.Default_20_200_001.Model
{
    [DataContract]
    public class AttributeValue : Entity_v4
    {

        [DataMember(Name="AttributeID", EmitDefaultValue=false)]
        public StringValue AttributeID { get; set; }

        [DataMember(Name="AttributeDescription", EmitDefaultValue=false)]
        public StringValue AttributeDescription { get; set; }

        [DataMember(Name="RefNoteID", EmitDefaultValue=false)]
        public GuidValue RefNoteID { get; set; }

        [DataMember(Name="Required", EmitDefaultValue=false)]
        public BooleanValue Required { get; set; }

        [DataMember(Name="Value", EmitDefaultValue=false)]
        public StringValue Value { get; set; }

        [DataMember(Name="ValueDescription", EmitDefaultValue=false)]
        public StringValue ValueDescription { get; set; }

    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...