Acumatica API insert data "Bad Request" - acumatica

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?

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.

Related

Update Note System field on a PUT request using Endpoint Rest API

Hi I want to set the Note field as part of my PUT request when adding a new activity record in Advanced.
I have my custom endpoint setup and I can insert the activity record no worries except setting the Note system field doesnt seem to do anything?
Here is an example of my JSON for the request
{
"Note": "narrtion test five",
"Summary": {
"value": "Test Task Status"
},
"Type": {
"value": "W"
},
"ActivityDate": {
"value": "2020-03-04T00:00:00"
},
"StartTime": {
"value": "0001-01-01T15:00:00"
},
"Owner": {
"value": "MATTMCD"
},
"Status": {
"value": "Completed"
},
"CostCode": {
"value": "0000"
},
"EarningType": {
"value": "RG"
},
"Billable": {
"value": true
},
"LabourItem": {
"value": "LABOUR-MAT"
},
"Project": {
"value": "PR00000001"
},
"ProjectTask": {
"value": "TESTTASK"
},
"TimeSpent": {
"value": "0:30"
},
"ActivityDetails": {
"value": "narrtion test five"
}
}
Would appreciate some help with this?
Can you try with "note" instead of "Note" ?
{
"note": "narrtion test five",
...
}

How to add a new top-level entity (to rest web service endpoint) using acumatica screenID?

Acumatica cloud ERP has a screen that displays failed push notifications (screenID = SM502000). I have created a new Web Services Endpoint, and added a new top-level entity from that screenID. However, no matter what fields I try to add, I get a variation on this error:
Optimization cannot be performed.The following fields cause the error:\r\nSelected: View FailedToSend has BQL delegate\r\n
Edit. I was able to create a REST end-point to fetch the results using a generic inquiry. Here is the JSON returned:
{
"id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"rowNumber": 1,
"note": null,
"Result": [
{
"id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"rowNumber": 1,
"note": null,
"Date": {
"value": 637167021636873690
},
"DateTimeStamp": {
"value": "2020-02-07T19:56:03.687369+00:00"
},
"DestinationNamePushNotifications_hookId": {
"value": "test"
},
"DestinationNamePushNotifications_hookId_description": {
"value": "test"
},
"Error": {
"value": "Send to target test failed. Message: WebHook returns not success code: NotFound; Message: Tunnel webhook.local not found"
},
"NotificationBody": {
"value": "..."
},
"PushNotifications_selected": {},
"Selected": {
"value": false
},
"SourceName": {
"value": "SO-SalesOrder"
},
"TransactionId": {
"value": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
},
"custom": {},
"files": []
},
{
"id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"rowNumber": 2,
"note": null,
"Date": {
"value": 637167021636873690
},
"DateTimeStamp": {
"value": "2020-02-07T19:56:03.687369+00:00"
},
"DestinationNamePushNotifications_hookId": {
"value": "test"
},
"DestinationNamePushNotifications_hookId_description": {
"value": "test"
},
"Error": {
"value": "Send to target test failed. Message: WebHook returns not success code: NotFound; Message: Tunnel webhook.local not found"
},
"NotificationBody": {
"value": "..."
},
"PushNotifications_selected": {},
"Selected": {
"value": false
},
"SourceName": {
"value": "SO-SalesOrder"
},
"TransactionId": {
"value": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
},
"custom": {},
"files": []
}
]
}
Here's a good tutorial for using GI to access data via API:
https://www.acumatica.com/blog/contract-based-apis-in-generic-inquiries/
Try retrieving the records one by one with a REST filter in the URL. The issue is that the target graph you added has a data view (FailedToSend) which uses a data view delegate.
Because data view delegates can be slower than no delegates the API refuses to return more than one record as an optimization.

Azure Devops unable to populate picklist

I followed the tutorial found at
https://learn.microsoft.com/en-us/azure/devops/extend/develop/service-endpoints?view=azure-devops
The api call is right because if I don't authenticate it shows the correct path in the error message. Entering the url that it shows in the message in a browser gives the correct json.
The picklist object will act like it is trying to load but will end up showing no results found.
Can you use a personal company api to load a picklist using server endpoint?
How do you debug this. All I see in the network tab on debugging tools is the 200 from azure making the post.
This is the JSON
{
"meta": {
"record_count": 5,
"source": "mongodb",
"searchParams": {
"versions.start_date": {
"$gte": "2019-08-30T00:11:55.329Z"
}
},
"paging": {
"num": 10,
"start": 0
}
},
"screenshots": [
{
"screenshot_test_id": 3946619,
"url": "https://www.google.com",
"test_name": null,
"created_date": "2019-10-27T21:26:32.0 ```
This is the datasources from the vss.extension
"dataSources": [
{
"name": "CBTAPIReturn",
"endpointUrl": "{{endpoint.url}}",
"resultSelector": "jsonpath:$[*].screenshots"
}
]
inputs and bindings from the task
"inputs": [
{
"name": "CBTService",
"type": "connectedService:CBTServiceEndpoint",
"label": "CBT service/server end point",
"defaultValue": "",
"required": true,
"helpMarkDown": "Select the CBT end point to use. If needed,selecton 'manage', and add a new service endpoint of type 'CBT server connection'"
},
{
"name": "CBT API Response",
"type": "pickList",
"label": "CBT API Response",
"required": true,
"helpMarkDown": "Select the name combination that you want to use.",
"properties": {
"EditableOptions": "True"
}
}
],
"dataSourceBindings": [
{
"target": "CBT API Response",
"endpointId": "$(CBTService)",
"dataSourceName": "CBTAPIReturn"
```

Issues with Acumatica REST Contract-Based API SalesInvoice Entity 18.200.001

Automating creation of Sales Invoice via Rest API
Unable to get CustomerLocation to populate
In the WebService EndPoint the Mapped Object and Mapped Fields are blank for this item
Has any one successfully used this API to modify Location?
Does any one know if I have a formatting error in my JSON for Linked Entities, it matches the documentation but may not be up to date?
Tried several formats of JSON based on the guide and experience including Linked, Summary, Custom and Detail
Tried both BillToSettings and BillingSetting Entities
Searched Known issues, Newton JSon
"Type": { "value": "Invoice" },
"CustomerID": { "value": "C0004055" },
/// bit does not create in Acumatica
"BillToSettings": { "CustomerLocation": { "value": "67217" } },
/// "BillingSettings" : {"CustomerLocation" : {"value" : "67217"}
/// also LocationID, CustomerLocationID and many combinations there of
"CustomerOrder": { "value": 1942 },
"Date": { "value": "2/14/2019" },
"Description": { "value": "SO S048773" },
"Details": [
{
"InventoryID": { "value": "POLLING-HOSTING" },
"TransactionDescr": { "value": "GPRS Monitoring" },
"UOM": { "value": "PNTS" },
"Qty": { "value": "3" },
"UnitPrice": { "value": "68.25" }
},
{
"InventoryID": { "value": "AIRTIME" },
"TransactionDescr": { "value": "GPRS Airtime" },
"UOM": { "value": "EACH" },
"Qty": { "value": "3" },
"UnitPrice": { "value": "20" }
}
]
I expect the Default MAIN location to be overridden with 67217 instead every record shows main
If I add the address Override fields (as below) then I get data for them on the successful creation of the invoice but no CustomerLocation data is returned.
Nor does the LocationID update correctly
BillingSettings = new
{
BillToAddressOverride = new {value = true},
BillToContactOverride = new { value = true },
CustomerLocation = new { value = "67217"}
},
I tried to use your JSON example on a clean SalesDemo install of 2019R1 and could replicate the same issue that you're experiencing.
I think it has to do with the CustomerLocation field not being mapped in the Default 18.200.001 endpoint. It actually makes sense if we look at the response object - there is no CustomerLocation field in the response either.
First Attempt, without extending the API endpoint:
{
"Type": {
"value": "Invoice"
},
"CustomerID": {
"value": "ABARTENDE"
},
"Date": {
"value": "5/10/2019"
},
"Description": {
"value": "Test SalesInvoice Creation"
},
"BillingSettings" : {
"CustomerLocation" : {
"value" : "VEGAS"
}
}
}
Response from the first attempt:
"BillingSettings": {
"BillToAddress": {
"AddressLine1": {
"value": "201 Lower Notch Rd"
},
"AddressLine2": {},
"City": {
"value": "Little Falls"
},
"Country": {
"value": "US"
},
"PostalCode": {
"value": "07424"
},
"State": {
"value": "NJ"
}
},
"BillToAddressOverride": {
"value": false
},
"BillToContact": {
"Attention": {
"value": "Accounts Receivable"
},
"BusinessName": {
"value": "USA Bartending School"
},
"Email": {
"value": "barkeep#usabartend.con"
},
"Phone1": {
"value": "+1 (908) 532-9522"
}
},
"BillToContactOverride": {
"value": false
}
}
If you extend the endpoint and implement the Location field which can be found under the Invoice Summary selection when populating the field, you should be able to achieve your intended outcome. PS. I added the Location on the SalesInvoice object itself, and not on the BillingSettings object:
Second Request, the extended endpoint includes the Location field that was added:
{
"Type": {
"value": "Invoice"
},
"CustomerID": {
"value": "ABARTENDE"
},
"Date": {
"value": "5/10/2019"
},
"Description": {
"value": "Test SalesInvoice Creation"
},
"Location" : {
"value" : "VEGAS"
}
}
Second Response:
{
"Amount": {
"value": 0
},
"Balance": {
"value": 0
},
"BillingSettings": {
"BillToAddressOverride": {
"value": false
},
"BillToContactOverride": {
"value": false
}
},
"Currency": {
"value": "USD"
},
"CustomerID": {
"value": "ABARTENDE"
},
"Date": {
"value": "2019-05-10T00:00:00+00:00"
},
"Description": {
"value": "Test SalesInvoice Creation"
},
"DueDate": {
"value": "2019-06-09T00:00:00+02:00"
},
"Hold": {
"value": false
},
"Location": {
"value": "VEGAS"
},
"ReferenceNbr": {
"value": "AR006994"
},
"Status": {
"value": "Balanced"
},
"Type": {
"value": "Invoice"
}
}
As to whether the CustomerLocation holds any meaningful value/purpose, I'm not sure, so I left it in the BillingSettings as is.

Commercetools - Use query predicates to filter on a collection attribute

I'd like to get all the Category items that have between their ancestors an ancestor with a certain "id".
Here is the JSON of one of the categories returned by GETting from /categories:
{
"id": "4627f3b0-fe52-4cc6-b03e-3fd72e701342",
"version": 1,
"lastMessageSequenceNumber": 1,
"createdAt": "2019-02-18T13:48:51.677Z",
"lastModifiedAt": "2019-02-18T13:48:51.677Z",
"lastModifiedBy": {
"clientId": "_anonymous"
},
"createdBy": {
"clientId": "_anonymous"
},
"key": "snowboard-gloves",
"name": {
"en": "Snowboard Gloves"
},
"slug": {
"en": "snowboard-gloves"
},
"description": {
"en": "Gloves specifically designed for snowboarding"
},
"ancestors": [
{
"typeId": "category",
"id": "b27086d2-33f2-43c3-aad1-4c01b2b9a886"
}
],
"parent": {
"typeId": "category",
"id": "b27086d2-33f2-43c3-aad1-4c01b2b9a886"
},
"orderHint": "0.000016",
"metaTitle": {
"en": "Snowboard Gloves"
},
"metaDescription": {
"en": "Gloves specifically designed for snowboarding"
},
"assets": []
}
I'd like to call the /categories API with a where clause on ancestors[x].id = "b27086d2-33f2-43c3-aad1-4c01b2b9a886" but from the documentation I don't understand how I should write the query predicate.
Can anyone help me?
The query predicate follows the structure of the json response. Nested fields are accessed with () brackets.
Try this out
ancestors(id = "idb27086d2-33f2-43c3-aad1-4c01b2b9a886")

Resources