0
votes

I'm trying to insert a stock item into Acumatica using the API, but I'm getting a 400 error - Bad Request. I'm using HttpClient to login, retrieve a stock item, and send the insert request. All is working except the insert request. I have tried the following url (including expand parameter):

http://localhost/AcumaticaERP/entity/Default/6.00.001/StockItem?$expand=Attributes,CrossReferences,UOMConversions,VendorDetails,WarehouseDetails

... and also the following url (without expand parameter)

http://localhost/AcumaticaERP/entity/Default/6.00.001/StockItem

I'm calling via HttpClient PutAsync, passing in the URLs mentioned above, and the data is JSON from a stock item retrieved with the API, and which doesn't exist in the current db.

client.PutAsync(insertUrl, new StringContent(data, Encoding.UTF8, "application/json")).Result;

Any ideas what I'm missing?

NEW DETAILS: After further debugging and testing with Postman, the error from the PUT seems to be "Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray. Path '', line 1, position 1." The JSON was taken directly from a GET though, so I'm not sure what the problem could be. Below is the JSON returning an error from the PUT.

[
  {
    "id": "cc27ce56-6302-4f1b-97aa-49cca3ed32ea",
    "rowNumber": 1,
    "note": "",
    "Attributes": [],
    "BaseUOM": {
      "value": "EA"
    },
    "CrossReferences": [],
    "DefaultIssueLocationID": {
      "value": "R1S1"
    },
    "DefaultReceiptLocationID": {
      "value": "RECEIVING"
    },
    "DefaultWarehouseID": {
      "value": "WHOLESALE"
    },
    "Description": {
      "value": "tonyitem2"
    },
    "ImageUrl": {},
    "InventoryID": {
      "value": "TONYITEM2"
    },
    "IsAKit": {
      "value": false
    },
    "ItemClass": {
      "value": "CONSUMER  300TOYS"
    },
    "ItemStatus": {
      "value": "Active"
    },
    "ItemType": {
      "value": "Finished Good"
    },
    "LastModified": {
      "value": "2018-08-03T12:09:19.907-04:00"
    },
    "LotSerialClass": {
      "value": "NOTTRACKED"
    },
    "PurchaseUOM": {
      "value": "EA"
    },
    "SalesUOM": {
      "value": "EA"
    },
    "UOMConversions": [],
    "VendorDetails": [],
    "Volume": {
      "value": 0
    },
    "WarehouseDetails": [
      {
        "id": "3ca5ea4c-c651-498e-8e6c-49119481982c",
        "rowNumber": 1,
        "note": "",
        "DefaultIssueLocationID": {
          "value": "R1S1"
        },
        "DefaultReceiptLocationID": {
          "value": "RECEIVING"
        },
        "IsDefault": {
          "value": true
        },
        "QtyOnHand": {
          "value": 0
        },
        "WarehouseID": {
          "value": "WHOLESALE"
        },
        "custom": {},
        "files": []
      }
    ],
    "Weight": {
      "value": 0
    },
    "custom": {},
    "files": []
  }
]

I also tried removing the brackets surrounding the JSON, and then the error is: "No entity satisfies the condition.". Could the issue be that the ids have GUIDs, but I'm trying to do an insert? How do you indicate that the PUT is supposed to be inserting?

1
Could you add the complete error message if there is more and the content of the JSON data that you are sending that might help us point you in the right tracksamol518
By the way, first I try to retrieve the stock item to determine if it already exists... localhost/AcumaticaERP/entity/Default/6.00.001/… eq 'TONYITEM93'&$expand=Attributes,CrossReferences,UOMConversions,VendorDetails,WarehouseDetails This returns a 500 error. Then I try the insert with the url mentioned above. There is no other error information that I can see besides the 400 error that I mentioned. The JSON is too large to post as a comment, but I can post some of it...Tony Lanzer
[{"id":"5547a1e7-1871-4b36-b2d2-8d9a417bcc94","rowNumber":1,"note":"","Attributes":[],"BaseUOM":{"value":"EA"},"CrossReferences":[],"DefaultIssueLocationID":{"value":"R1S1"},"DefaultReceiptLocationID":{"value":"RECEIVING"},"DefaultWarehouseID":{"value":"WHOLESALE"},"Description":{"value":"tonyitem93"},"ImageUrl":{},"InventoryID":{"value":"TONYITEM93"},"IsAKit":{"value":false},"ItemClass":{"value":"CONSUMER 300TOYS"},"ItemStatus":{"value":"Active"},"ItemType":{"value":"Finished Good"},"LastModified":{"value":"2018-07-31T16:26:03.06-04:00"},"LotSerialClass":{"value":"NOTTRACKED"},"PurchaseUOM":Tony Lanzer
I backed up a step and tried to just do simple GETs of the same inventory item on two different sites with the same syntax and one returns the item successfully, but the other returns a 500 error. I used Postman to look at the specific error and it is "The view doesn't exist". StockItem is an endpoint in both sites, so what could it be complaining about?Tony Lanzer
I think the real issue is that the StockItem endpoint for one site is throwing an error. The other endpoints are fine, but not StockItem. Any ideas? I guess I can try reinstalling my site.Tony Lanzer

1 Answers

1
votes

I finally got the PUT to insert. What finally worked was removing the wrapping braces "[" and "]" around the entire JSON; plus removing all "id", "rowNumber", "custom", and "files" fields, and all empty collections (e.g. Attributes, CrossReferences) in my JSON. I'm not sure which of these being removed resolved it and allowed me to insert, but it finally worked.

It's real unfortunate that the JSON you retrieve via GET can't be inserted via PUT without stripping all of this out first though. What a pain.