The result remain the same, PurchaseReceipt item was created, but when I tried to attach file to it, I get error “Operation is not valid due to the current state of the object. “
I thought, the reason of it is “Balanced” state of Purchase receipt item, I tried to release it and only after that make attachment but result remains the same.
I also checked attachments adding via Acumatica interface, it worked for both statuses, so the problem not in Acumatica instance, I think there is some configuration parameter that does not allow me to do this or request lacks something
Hi @Ivan
You are trying to attach the image to the details tab?
If yes, Rest API won't support it. We can attach a file on the summary level. But grid level means you need to create a screen and custom endpoint.
I do not know where I wrongly described my goal, maybe presence of Details table in request caused it.
I need to create Purchasereceipt, after that attach a file to it
The first step is done, requests that I sent to you are working
After PurchaseReceipt was created
I need to attach file to it, in previous message I pointed everything about error that I receive. I am not trying to attach to Details, just to new Purchase Receipt item that I created
@Ivan You can use the following REST endpoint to attach to the Purchase Receipt header. You can test it with Postman. If you're still having issues I can be more specific about how to do this.
If you want to attach to individual PO Lines, this isn’t available for REST API yet, but it will be in 2022 R2 based on the current API preview.
"/PurchaseReceipt/{ids}/files/{filename}": { "put": { "tags": s "PurchaseReceipt" ], "summary": "Attaches a file to a record.", "operationId": "PurchaseReceipt_PutFile", "consumes": s], "produces": s "application/json", "text/json" ], "parameters": s { "name": "ids", "in": "path", "description": "The values of the key fields of the record.", "required": true, "type": "array", "items": { "type": "string" }, "collectionFormat": "pipes" }, { "name": "filename", "in": "path", "description": "The name of the file that you are going to attach with the extension.", "required": true, "type": "string" } ], "responses": { "204": { "description": "The file is successfully attached.", "headers": { "Location": { "description": "A URL that can be used to retrieve the file from the system.", "type": "string", "format": "uri" } } }, "401": { "description": "The user is not logged in to the system.", "schema": { "$ref": "#/definitions/HttpError" } }, "500": { "description": "Internal server error.", "schema": { "$ref": "#/definitions/HttpError" } } } }
@Ivan You can use the following REST endpoint to attach to the Purchase Receipt header. You can test it with Postman. If you're still having issues I can be more specific about how to do this.
If you want to attach to individual PO Lines, this isn’t available for REST API yet, but it will be in 2022 R2 based on the current API preview.
"/PurchaseReceipt/{ids}/files/{filename}": { "put": { "tags": s "PurchaseReceipt" ], "summary": "Attaches a file to a record.", "operationId": "PurchaseReceipt_PutFile", "consumes": s], "produces": s "application/json", "text/json" ], "parameters": s { "name": "ids", "in": "path", "description": "The values of the key fields of the record.", "required": true, "type": "array", "items": { "type": "string" }, "collectionFormat": "pipes" }, { "name": "filename", "in": "path", "description": "The name of the file that you are going to attach with the extension.", "required": true, "type": "string" } ], "responses": { "204": { "description": "The file is successfully attached.", "headers": { "Location": { "description": "A URL that can be used to retrieve the file from the system.", "type": "string", "format": "uri" } } }, "401": { "description": "The user is not logged in to the system.", "schema": { "$ref": "#/definitions/HttpError" } }, "500": { "description": "Internal server error.", "schema": { "$ref": "#/definitions/HttpError" } } } }
Hi @rosenjon
i tried following request for attaching file to header but still receive 500 error with message : “No entity satisfies the following condition”
In URL that you have provided what is “{ids}” parameter ?
I tried to insert Receipt Number in here and ID of this receipt
@Ivan This one was a little tricky. Acumatica has done a bad job of documenting these endpoints. I think the new file api coming out in the next release will help with some of these problems.
I tested this myself and here is what you have to do. There was a hint in this thread, but it was specific to a different type of documents (Bills), so not directly applicable to this use case.
In the GUI for POs, you can see that there are three types of POs (Normal, Blanket and Standard). So the correct url format to post looks like this, where PurchaseOrder is the top-level endpoint, Normal is the type of Purchase Order (could be blanket, for example), 000029 is the PO number, and then the other parts should be obvious.
You will need to PUT to that endpoint with binary encoding. I have tested it with Postman and it works.
Let me know if that fixes your problem. It looks like your doing this via curl or a programming language, which is fine, but I would highly recommend learning Postman and testing with that first. It will save you a lot of time when working with Acumatica, because it is often the case that these rest endpoints are extensions of the DACs, and so they tend to be a little weird compared to your normal REST API. It’ a lot faster to prototype in Postman vs. writing code first.
@Ivan Oops, I forgot you wanted PurchaseReceipt, not PurchaseOrder. But the principle is the same. You can see that PurchaseReceipt has three different types...Receipt, Return, Transfer Receipt. Therefore, url format below is correct. Also tested and it works.
@Ivan Oops, I forgot you wanted PurchaseReceipt, not PurchaseOrder. But the principle is the same. You can see that PurchaseReceipt has three different types...Receipt, Return, Transfer Receipt. Therefore, url format below is correct. Also tested and it works.
//CreateApiCall just performs PUT request using (StreamReader sr = new StreamReader(fileInfo.FullName)) { WebClientHelper.CreateApiCall(HttpClient, WebClientHelper.HttpMethod.Put, out var respContentAttach, streamContent: new StreamContent(sr.BaseStream), method: tempAttMethod); }
@Ivan Oops, I forgot you wanted PurchaseReceipt, not PurchaseOrder. But the principle is the same. You can see that PurchaseReceipt has three different types...Receipt, Return, Transfer Receipt. Therefore, url format below is correct. Also tested and it works.
//CreateApiCall just performs PUT request using (StreamReader sr = new StreamReader(fileInfo.FullName)) { WebClientHelper.CreateApiCall(HttpClient, WebClientHelper.HttpMethod.Put, out var respContentAttach, streamContent: new StreamContent(sr.BaseStream), method: tempAttMethod); }
Howerver via code I get this error
LIke I said, way easier to test with Postman (also because it is easier to compare calls than between everyone’s custom code).
//CreateApiCall just performs PUT request using (StreamReader sr = new StreamReader(fileInfo.FullName)) { WebClientHelper.CreateApiCall(HttpClient, WebClientHelper.HttpMethod.Put, out var respContentAttach, streamContent: new StreamContent(sr.BaseStream), method: tempAttMethod); }
Or trying this another way. What happens if you replace the code you sent me with this code?
Did you make the change that I suggested? Please post the relevant code again.
Yes. Hope this is the only difference, I removed PR
//CreateApiCall just performs PUT request using (StreamReader sr = new StreamReader(fileInfo.FullName)) { WebClientHelper.CreateApiCall(HttpClient, WebClientHelper.HttpMethod.Put, out var respContentAttach, streamContent: new StreamContent(sr.BaseStream), method: tempAttMethod); }
Here the url is corrected in your code.
string att = "C:\Test\image.jpg”;
if (!File.Exists(att)) continue; FileInfo fileInfo = new FileInfo(att); string tempAttMethod = "";
//CreateApiCall just performs PUT request using (StreamReader sr = new StreamReader(fileInfo.FullName)) { WebClientHelper.CreateApiCall(HttpClient, WebClientHelper.HttpMethod.Put, out var respContentAttach, streamContent: new StreamContent(sr.BaseStream), method: tempAttMethod); }
ARTSEndpoint is the name of the custom endpoint, so instead of Default I use it
Can you please suggest what is the difference in the code ?
First part is the site of my acumatica instance, after that goes “entity” and after that name of the endpoint, after that it’s version.
Why don’t you use the Default endpoint first so that we can test with that, and take the custom endpoint out of the picutre. Please fix the url in postman, and then send another screenshot. Just black out the url with paint if you want to redact it. Use the Default endpoint, not your custom endpoint. You don’t need a custom endpoint to attach to purchase receipt.
Why don’t you use the Default endpoint first so that we can test with that, and take the custom endpoint out of the picutre. Please fix the url in postman, and then send another screenshot. Just black out the url with paint if you want to redact it. Use the Default endpoint, not your custom endpoint. You don’t need a custom endpoint to attach to purchase receipt.