Tony Lanzer
Tony Lanzer

Reputation: 291

How do I insert attribute values with the REST API?

Including them in the Attribute collection of a Stock Item doesn't seem to work -- even if I make sure the attribute ids already exist in the db. When I do the PUT request, the rest of the data in the record is inserted, but not the attributes. The response even returns an empty attribute array instead of what I sent to it.

Do I need to extend the API for this to work? If so, does anyone have any examples? I haven't been able to find any yet.

The request is: http://localhost/acum172100034/entity/Default/17.200.001/StockItem

The body is:

{
  "InventoryID": {
    "value": "RGTONYIT166"
  },
  "Attributes": [
    {
      "AttributeID": {
        "value": "Item Attribute"
      },
      "Value": {
        "value": "2"
      }
    }
  ]
}

The PUT response is:

{
    "id": "665e403c-d310-4bb4-9759-e2487dd5abc7",
    "rowNumber": 1,
    "note": null,
    "ABCCode": {},
    "Attributes": [],
    "AutoIncrementalValue": {},
    "AverageCost": {
        "value": 0
    },
    "BaseUOM": {
        "value": "EA"
    },
    "COGSAccount": {
        "value": "50000"
    },
    "COGSSubaccount": {
        "value": "CON000"
    },
    "Content": {},
    "CurrentStdCost": {
        "value": 0
    },
    "DefaultIssueLocationID": {
        "value": "R1S1"
    },
    "DefaultPrice": {
        "value": 0
    },
    "DefaultReceiptLocationID": {
        "value": "RECEIVING"
    },
    "DefaultWarehouseID": {
        "value": "WHOLESALE"
    },
    "DeferralAccount": {},
    "DeferralSubaccount": {},
    "Description": {
        "value": "tonyitem166 - blah blah 2"
    },
    "DimensionVolume": {
        "value": 3
    },
    "DimensionWeight": {
        "value": 2
    },
    "DiscountAccount": {},
    "DiscountSubaccount": {},
    "ImageUrl": {},
    "InventoryAccount": {
        "value": "12100"
    },
    "InventoryID": {
        "value": "RGTONYIT166"
    },
    "InventorySubaccount": {
        "value": "CON000"
    },
    "IsAKit": {
        "value": false
    },
    "ItemClass": {
        "value": "CONSUMER  200FITNESS"
    },
    "ItemStatus": {
        "value": "Active"
    },
    "ItemType": {
        "value": "Finished Good"
    },
    "LandedCostVarianceAccount": {
        "value": "52400"
    },
    "LandedCostVarianceSubaccount": {
        "value": "CON000"
    },
    "LastCost": {
        "value": 0
    },
    "LastModified": {
        "value": "2018-10-02T17:13:38.707-04:00"
    },
    "LastStdCost": {
        "value": 0
    },
    "LotSerialClass": {
        "value": "NOTTRACKED"
    },
    "Markup": {
        "value": 0
    },
    "MaxCost": {
        "value": 0
    },
    "MinCost": {
        "value": 0
    },
    "MinMarkup": {
        "value": 0
    },
    "MSRP": {
        "value": 0
    },
    "PackagingOption": {
        "value": "Manual"
    },
    "PackSeparately": {
        "value": false
    },
    "PendingStdCost": {
        "value": 0
    },
    "POAccrualAccount": {
        "value": "20100"
    },
    "POAccrualSubaccount": {
        "value": "CON000"
    },
    "PostingClass": {
        "value": "CON"
    },
    "PriceClass": {},
    "PriceManager": {},
    "PriceWorkgroup": {},
    "ProductManager": {},
    "ProductWorkgroup": {},
    "PurchasePriceVarianceAccount": {
        "value": "52300"
    },
    "PurchasePriceVarianceSubaccount": {
        "value": "CON000"
    },
    "PurchaseUOM": {
        "value": "EA"
    },
    "ReasonCodeSubaccount": {
        "value": "CON000"
    },
    "SalesAccount": {
        "value": "40000"
    },
    "SalesSubaccount": {
        "value": "CON000"
    },
    "SalesUOM": {
        "value": "EA"
    },
    "StandardCostRevaluationAccount": {
        "value": "52110"
    },
    "StandardCostRevaluationSubaccount": {
        "value": "CON000"
    },
    "StandardCostVarianceAccount": {
        "value": "52100"
    },
    "StandardCostVarianceSubaccount": {
        "value": "CON000"
    },
    "SubjectToCommission": {
        "value": false
    },
    "TaxCategory": {
        "value": "TAXABLE"
    },
    "ValuationMethod": {
        "value": "Average"
    },
    "VolumeUOM": {},
    "WeightUOM": {},
    "custom": {},
    "files": []
}

Upvotes: 0

Views: 1418

Answers (3)

Tony Lanzer
Tony Lanzer

Reputation: 291

This ended up being an issue with my own code that was apparently hiding the attributes from the view so that they wouldn’t update. Once I resolved that, now it's working by just include them in the Attributes collection.

Upvotes: 0

Patrick Chen
Patrick Chen

Reputation: 1056

This is a guess, but I think you need to add your attributes to your stock item class. Go to IN201000

Upvotes: 0

samol518
samol518

Reputation: 1404

If the Attributes are already present on the Stock Item screen, then you can use the Default endpoint and you only need to make a PUT call specifying the Inventory ID and the Attribute ID like so:

PUT : localhost/demo172u10/entity/Default/17.200.001/StockItem

{
    "InventoryID": {"value": "AACOMPUT01"},
    "Attributes": 
    [
        {
            "AttributeID": {"value": "Color"},
            "Value": {"value": "Black"}
        },
        {
            "AttributeID": {"value": "Configurable Attributes"},
            "Value": {"value": "Test"}
        }
    ]
}

This would update the "Color" and "Configurable Attributes" Attributes of the AACOMPUT01 Stock Item with the value specified.

If the Attribute is not on the Stock Item screen then you would need to use the API to target the Item Class screen to add the Attributes that you want there. As if you go to the Stock Item screen you might notice that you cannot add new attributes directly on that screen and that they are actually coming from the Item Class of the Item itself.

This test was done using the Sales Demo Data with Acumatica Version 17.210.0034

Upvotes: 1

Related Questions