Solved

Add attachment to Purchase Receipt item via PUT request


Userlevel 4
Badge +2

Hi,

Previously I sent documents to Acumatica files for bills with the help of such request

https://myacumatica.com/entity/ARTSEndpoint/20.200.001/Bill/INV/002272/files/image (3).pdf

For Checks and Payments it worked via such request

https://myacumatica.com/entity/ARTSEndpoint/20.200.001/Payment/payment/002272/files/file.pdf

How to do same for Purchase Receipt tab ? I tried several variations but did not succeed in it 

icon

Best answer by rosenjon 15 August 2022, 23:55

View original

23 replies

Userlevel 7
Badge +11

Hi @Ivan 

Please try like below sample
 

Instanceurl/entity/Default/20.200.001/PurchaseReceipt/Receipt/PR001557/files/Image.jpg

Userlevel 4
Badge +2

Hi @jinin 

I tried such request previously and received such error : “Operation is not valid due to the current state of the object. “

I thought something wrong with my request, that is the reason why I created this case.

this my request for creating receipts

URL : Instanceurl/entity/ARTSEndpoint/18.200.001/PurchaseReceipt?$expand=Details&$select=Branch,Type,ReceiptNbr,CurrencyID,Details/InventoryID,Details/POOrderNbr,Details/POOrderType,Details/ReceiptQty,Details/TransactionDescription,Details/UnitCost,Details/UOM,Details/Warehouse

BODY:

The receipt successfully created

I also tried request without fields enumeration in URL

 URL : Instanceurl/entity/ARTSEndpoint/18.200.001/PurchaseReceipt

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

 

 

 

Userlevel 7
Badge +11

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.

Please refer the below ticket

 

Add Files to Salesorder line item using REST API | Community (acumatica.com)

Userlevel 4
Badge +2

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.

Please refer the below ticket

 

Add Files to Salesorder line item using REST API | Community (acumatica.com)

@jinin No

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

Userlevel 6
Badge +5

@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": [
"PurchaseReceipt"
],
"summary": "Attaches a file to a record.",
"operationId": "PurchaseReceipt_PutFile",
"consumes": [],
"produces": [
"application/json",
"text/json"
],
"parameters": [
{
"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"
}
}
}
}

 

Userlevel 4
Badge +2

@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": [
"PurchaseReceipt"
],
"summary": "Attaches a file to a record.",
"operationId": "PurchaseReceipt_PutFile",
"consumes": [],
"produces": [
"application/json",
"text/json"
],
"parameters": [
{
"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 

 this is set of requests that I have tested :

1)entity/ARTSEndpoint/18.200.001/PurchaseReceipt/receipt/PR001281/files/po1.jpg

2)entity/ARTSEndpoint/18.200.001/PurchaseReceipt/PR001281/files/po1.jpg

3)entity/ARTSEndpoint/18.200.001/PurchaseReceipt/receipt/f163758c-731c-ed11-8193-0ae25d490b86/files/po1.jpg

4)entity/ARTSEndpoint/18.200.001/PurchaseReceipt/f163758c-731c-ed11-8193-0ae25d490b86/files/po1.jpg

5)entity/ARTSEndpoint/18.200.001/PurchaseReceipt/Receipt/f163758c-731c-ed11-8193-0ae25d490b86/files/po1.jpg

6)entity/ARTSEndpoint/18.200.001/PurchaseReceipt/receipt/PR001281/files/po1.jpg

And none of them worked, where is the mistake ?

 

Userlevel 6
Badge +5

@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.

https://hostname/instancedirectory/entity/Default/18.200.001/PurchaseOrder/Normal/000029/files/test.xlsx

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.

 

Userlevel 6
Badge +5

@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.

 

https://myhost/subdirectory/entity/Default/18.200.001/PurchaseReceipt/Receipt/000033/files/test.xlsx

Userlevel 4
Badge +2

@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.

 

https://myhost/subdirectory/entity/Default/18.200.001/PurchaseReceipt/Receipt/000033/files/test.xlsx

@rosenjon 

I did not understand what is the difference between example that you have provided https://myhost/subdirectory/entity/Default/18.200.001/PurchaseReceipt/Receipt/000033/files/test.xlsx and example, provided by @jinin  - Instanceurl/entity/Default/20.200.001/PurchaseReceipt/Receipt/PR001557/files/Image.jpg

I receive same error

This is my code 

string att = "C:\Test\image.jpg”;

                               if (!File.Exists(att))
                                continue;
                            FileInfo fileInfo = new FileInfo(att);
                            string tempAttMethod = "";

//here tempAttMethod  variable is equal entity/ARTSEndpoint/18.200.001/PurchaseReceipt/Receipt/PR001286/files/po1.jpg
                 tempAttMethod = string.Concat(method, "/", type, "/", refNmbr, "/files/", fileInfo.Name);

 

              //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);
                            }

Userlevel 4
Badge +2

@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.

 

https://myhost/subdirectory/entity/Default/18.200.001/PurchaseReceipt/Receipt/000033/files/test.xlsx

@rosenjon

I did not understand what is the difference between example that you have provided https://myhost/subdirectory/entity/Default/18.200.001/PurchaseReceipt/Receipt/000033/files/test.xlsx and example, provided by @jinin  - Instanceurl/entity/Default/20.200.001/PurchaseReceipt/Receipt/PR001557/files/Image.jpg

I receive same error

This is my code 

string att = "C:\Test\image.jpg”;

                               if (!File.Exists(att))
                                continue;
                            FileInfo fileInfo = new FileInfo(att);
                            string tempAttMethod = "";

//here tempAttMethod  variable is equal entity/ARTSEndpoint/18.200.001/PurchaseReceipt/Receipt/PR001286/files/po1.jpg
                 tempAttMethod = string.Concat(method, "/", type, "/", refNmbr, "/files/", fileInfo.Name);

 

              //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 

 

 

Userlevel 6
Badge +5

LIke I said, way easier to test with Postman (also because it is easier to compare calls than between everyone’s custom code). 

//here tempAttMethod  variable is equal entity/ARTSEndpoint/18.200.001/PurchaseReceipt/Receipt/PR001286/files/po1.jpg                 tempAttMethod = string.Concat(method, "/", type, "/", refNmbr, "/files/", fileInfo.Name);

If you look closely, the /PurchaseReceipt/Receipt/PR001286/files/po1.jpg is not correct.

It should be /PurchaseReceipt/Receipt/001286/files/po1.jpg

I would try that first. There may be other problems with your code...but that is the starting point. What happens when you remove the PR?

Userlevel 4
Badge +2

LIke I said, way easier to test with Postman (also because it is easier to compare calls than between everyone’s custom code). 

//here tempAttMethod  variable is equal entity/ARTSEndpoint/18.200.001/PurchaseReceipt/Receipt/PR001286/files/po1.jpg                 tempAttMethod = string.Concat(method, "/", type, "/", refNmbr, "/files/", fileInfo.Name);

If you look closely, the /PurchaseReceipt/Receipt/PR001286/files/po1.jpg is not correct.

It should be /PurchaseReceipt/Receipt/001286/files/po1.jpg

I would try that first. There may be other problems with your code...but that is the starting point. What happens when you remove the PR?

Happens this error 

 

Userlevel 6
Badge +5

Did you make the change that I suggested? Please post the relevant code again.

Userlevel 6
Badge +5
string att = "C:\Test\image.jpg”;

if (!File.Exists(att))
continue;
FileInfo fileInfo = new FileInfo(att);
string tempAttMethod = "";

//here tempAttMethod variable is equal entity/ARTSEndpoint/18.200.001/PurchaseReceipt/Receipt/001286/files/po1.jpg
tempAttMethod = string.Concat(method, "/", type, "/", refNmbr, "/files/", fileInfo.Name);



//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?

Userlevel 4
Badge +2

Did you make the change that I suggested? Please post the relevant code again.

Yes. Hope this is the only difference, I removed PR

same error in code and in postman

Userlevel 6
Badge +5

https://url/entity/ARTSEndpoint/18.200.001/PurchaseReceipt/Receipt/001276/files/dropBox.txt

The name of your server is “url”…. something tells me its not.

Userlevel 4
Badge +2

https://url/entity/ARTSEndpoint/18.200.001/PurchaseReceipt/Receipt/001276/files/dropBox.txt

The name of your server is “url”…. something tells me its not.

I just hide our acumatica address. If I execute this it will even not being processed

 

Userlevel 6
Badge +5

You are mixing up the order of the url path parameters.

https://url/ARTSEndpoint/entity/Default/18.200.001/PurchaseReceipt/Receipt/001276/files/dropBox.txt

Userlevel 6
Badge +5

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 = "";

//here tempAttMethod variable is equal ARTSEndpoint/entity/Default/18.200.001/PurchaseReceipt/Receipt/001286/files/po1.jpg
tempAttMethod = string.Concat(method, "/", type, "/", refNmbr, "/files/", fileInfo.Name);



//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);
}

 

Userlevel 4
Badge +2

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 = "";

//here tempAttMethod variable is equal ARTSEndpoint/entity/Default/18.200.001/PurchaseReceipt/Receipt/001286/files/po1.jpg
tempAttMethod = string.Concat(method, "/", type, "/", refNmbr, "/files/", fileInfo.Name);



//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 ?

My URL : 

https://acumatica.com/entity/ARTSEndpoint/18.200.001/PurchaseReceipt/Receipt/001276/files/dropBox.txt

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. 

Userlevel 6
Badge +5

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.

 

https://servername/subdirectory/entity/Default/18.200.001/PurchaseReceipt/Receipt/000033/files/dropBox.txt

Userlevel 4
Badge +2

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.

 

https://servername/subdirectory/entity/Default/18.200.001/PurchaseReceipt/Receipt/000033/files/dropBox.txt

I found mistake, once i switched to default endpoint everything worked, problem with my custom endpoint

thank you very much for help

Userlevel 6
Badge +5

No problem, glad you got it fixed. Please mark my answer as the solution, I don’t usually ask, but I worked for this one 🤣

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved