delete via API works a couple of times then dies  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

Re: delete via API works a couple of times then dies

Postby JuiceyBrucey » Thu Nov 02, 2023 5:10 pm

This is really hard to pin down.
When using CURL, with the same request, I get: 'http_code' => 0
When using Postman, I get 401
When using Swagger, I get:
Response Body
{
"ResponseStatus": {
"ErrorCode": "Exception",
"Message": "Can Not Delete. In use by : \r\n\r\nStock On Hand Transfer.\r\n",
"Errors": []
}
}
Response Code
500
JuiceyBrucey
Frequent Contributor
Frequent Contributor
 
Posts: 132
Joined: Tue Aug 18, 2020 7:19 pm
Topics Solved: 1

Re: delete via API works a couple of times then dies

Postby Mike.Sheen » Thu Nov 02, 2023 5:20 pm

JuiceyBrucey wrote:This is really hard to pin down.
When using CURL, with the same request, I get: 'http_code' => 0
When using Postman, I get 401
When using Swagger, I get:
Response Body
{
"ResponseStatus": {
"ErrorCode": "Exception",
"Message": "Can Not Delete. In use by : \r\n\r\nStock On Hand Transfer.\r\n",
"Errors": []
}
}
Response Code
500


I don't see the issue.

You're supposed to get that error - it's an integrity rule that says you can't delete an inventory item when it's being used. Find the stock transfer(s) the item is being used on and remove it from them and then you will be able to delete it.

Postman is giving you a 401 because you have got your API key wrong or are aiming at the wrong host.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: delete via API works a couple of times then dies

Postby JuiceyBrucey » Mon Nov 06, 2023 9:17 am

***** see update below *****
On the issue of the suggestion that my API Key is incorrect, it works for all other requests including patch, and has done for months. It is just not working for this request.

Ok, so I tried creating an entirely new product.
I then logged into the server and used swagger to delete that product.
So in this case, the product has not even been touched yet ******* sorry, the product had been viewed via API using Inventory method to get all inventory*********, so no chance of stock transfer. I have bypassed http tunnel, so no auth issues or chance of log in error. I have logged in using auth on Swagger, so I am authorised and no auth error message. The product has not bee selected for purchase or any other task, so cannot be locked.

i got the same result.

{
"ResponseStatus": {
"ErrorCode": "Exception",
"Message": "Can Not Delete. In use by : \r\n\r\nStock On Hand Transfer.\r\nSales Orders.\r\nSales Quotes.\r\nPurchases Orders.\r\nReceived Ordered Goods.\r\nPurchasing Invoice.\r\nInventory Sales.\r\nInventory SOH.\r\n",
"Errors": []
}
}

When attempting to delete using CURL via http tunnel, this is the response I get:
array (
'url' => 'https://********.ngrok.io/Inventory/77b1d760d9d74fb9972e',
'content_type' => NULL,
'http_code' => 0,
'header_size' => 0,
'request_size' => 0,
'filetime' => -1,
'ssl_verify_result' => 0,
etc etc.

Any suggestions?
JuiceyBrucey
Frequent Contributor
Frequent Contributor
 
Posts: 132
Joined: Tue Aug 18, 2020 7:19 pm
Topics Solved: 1

Re: delete via API works a couple of times then dies

Postby JuiceyBrucey » Mon Nov 06, 2023 9:36 am

So using swagger, on an inventory item that has never been extracted by a method from a plugin, it returns 204, item deleted.
But once the inventory item has been extracted in any way, it seems to be locked somehow and cannot be deleted.
But the item is only extracted for viewing, not for transfer or any other operation.
Is there any reason you can think of that would cause that?
Thank you.
Cheers
JuiceyBrucey
Frequent Contributor
Frequent Contributor
 
Posts: 132
Joined: Tue Aug 18, 2020 7:19 pm
Topics Solved: 1

Re: delete via API works a couple of times then dies

Postby Mike.Sheen » Mon Nov 06, 2023 10:31 am

JuiceyBrucey wrote:So using swagger, on an inventory item that has never been extracted by a method from a plugin, it returns 204, item deleted.
But once the inventory item has been extracted in any way, it seems to be locked somehow and cannot be deleted.
But the item is only extracted for viewing, not for transfer or any other operation.
Is there any reason you can think of that would cause that?
Thank you.
Cheers


The message is telling you why it cannot be deleted.

Jiwa has a philosophy that once an inventory item is present on a document, or it has stock movements that you cannot delete it. In your case the error message is telling you that particular item is on a stock transfer document, so you cannot delete it.

I don't see a problem here.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: delete via API works a couple of times then dies

Postby Mike.Sheen » Mon Nov 06, 2023 10:44 am

JuiceyBrucey wrote:When attempting to delete using CURL via http tunnel, this is the response I get:
array (
'url' => 'https://********.ngrok.io/Inventory/77b1d760d9d74fb9972e',
'content_type' => NULL,
'http_code' => 0,
'header_size' => 0,
'request_size' => 0,
'filetime' => -1,
'ssl_verify_result' => 0,
etc etc.

Any suggestions?


Please provide something I can test with - something I can repro such as the exact cURL command-line, not your PHP or whatever you are using. Or you could provide the raw HTTP request and response including headers.

What you've provided isn't enough to being to troubleshoot your issue.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: delete via API works a couple of times then dies

Postby JuiceyBrucey » Mon Nov 06, 2023 5:21 pm

So this is the guts of the problem:
"Jiwa has a philosophy that once an inventory item is present on a document, or it has stock movements that you cannot delete it. In your case the error message is telling you that particular item is on a stock transfer document, so you cannot delete it."
How, after merely viewing a problem via an Inventory select plugin, do I unlock the items that have been viewed.
It is absolutely useless if all products viewed are then locked and cannot be worked with. My script uses a plugin to select ALL inventory, then compares to the website so I can see differences and redundancies and rectify them.
"once an inventory item is present on a document"
so it is present for display on a document, then it is locked. The purpose of making it present on a document is to see if anything needs to be done with it. So if it is locked, I cant do this.
The plugin script should extract the data, the immediately free it. I cannot see the logic in locking it.
So is there any way around this?
can additional code be added to ALL of the inventory methods that immediately frees up the items once the data is obtained?
Locking the inventory item up would make sense if it was being transferred or put on hold etc, but just viewing it and locking it up does not make sense at all.
How long does this lock up last?
JuiceyBrucey
Frequent Contributor
Frequent Contributor
 
Posts: 132
Joined: Tue Aug 18, 2020 7:19 pm
Topics Solved: 1

Re: delete via API works a couple of times then dies

Postby Mike.Sheen » Mon Nov 06, 2023 5:57 pm

JuiceyBrucey wrote:How, after merely viewing a problem via an Inventory select plugin, do I unlock the items that have been viewed.


We don't prevent deleting an item if it's merely been viewed.

JuiceyBrucey wrote:The purpose of making it present on a document is to see if anything needs to be done with it


What document are you putting it on? Are you creating the item, then adding it to a stock transfer and THEN trying to delete it? If so, then my earlier comment applies - you need to remove the item from the stock transfer before attempting to delete the item.

I don't know exactly what you are doing, and for me to understand fully you're going to have to provide exact steps to reproduce the scenario.

An example of what I would expect:

1. Create item via POST to /Inventory with following json body:
Code: Select all
{
   "PartNo" : "MyTestItem",
   "Description": "This is a test item",
   "DefaultPrice": 5.40
}

Response is 201, and relevant response fragment:
Code: Select all
{
   "InventoryID": "bfa6f1a5b4ff43b3a9ce"
}


2. Add Item to Stock Transfer via POST to /StockTransfers with the following body
Code: Select all
{
  "TransferDate" : "2023-11-06",
   "Reference" : "Test Transfer",
   "Lines": [
      { "FromInventoryRecID" : "bfa6f1a5b4ff43b3a9ce", "TransferQuantity": 5 }
   ]
}


Response is 201, and relevant response fragment:
Code: Select all
{
   "TransferID": "c6748300e5ee4e61acdb",
   "TransferNo": "000056"
}


3. Delete inventory item via DELETE to /Inventory/bfa6f1a5b4ff43b3a9ce and error occurs - Exact response is HTTP 500
Code: Select all
{
    "ResponseStatus": {
        "ErrorCode": "Exception",
        "Message": "Can Not Delete. In use by : \r\n\r\nPurchases Orders.\r\nReceived Ordered Goods.\r\nInventory SOH.\r\nBill Maintenance Inputs\r\nWork Order Inputs\r\n",
        "Errors": []
    }
}


It needs to be accurate and complete, or I cannot help you.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: delete via API works a couple of times then dies

Postby JuiceyBrucey » Mon Nov 06, 2023 6:22 pm

"We don't prevent deleting an item if it's merely been viewed."
This is exactly what is happening. Once the item has been viewed, I cannot delete it.
When I created a new item and did not view it or do anything at all with it, I was able to delete it via Swagger no problem. Once it has been viewed I cannot delete it as it has been locked. This would make sense with some other operations, but for just extracting the inventory data for use in any purpose that does not make the product unavailable, does not make sense.
To replicate my issue, simply add an inventory item, view it using the attached plugin, then try to use swagger to delete the item. It wont delete.
I am extracting the inventory data using a the plugin that is attached.
That data is then used on the website. But that part is not relevant as I have tried every step of this using swagger after using auth method thus bypassing http tunnels, authentication on the tunnel etc etc.
Thank you.
Cheers
Attachments
Plugin REST API Get all inventory limited fields.xml
(24.82 KiB) Downloaded 270 times
JuiceyBrucey
Frequent Contributor
Frequent Contributor
 
Posts: 132
Joined: Tue Aug 18, 2020 7:19 pm
Topics Solved: 1

Re: delete via API works a couple of times then dies

Postby Mike.Sheen » Mon Nov 06, 2023 7:13 pm

JuiceyBrucey wrote:"We don't prevent deleting an item if it's merely been viewed."
This is exactly what is happening. Once the item has been viewed, I cannot delete it.


Do you think it possible that someone else added the item you created to a stock transfer?

The error says very plainly why you cannot delete the item, so have you bothered to verify the claim that it is on a stock transfer?

The following SQL Query can be used to determine if there are any stock transfers referring to the item - just substitute the ''<InventoryID HERE>" with the ID of the item you are trying to delete.

Code: Select all
SELECT IN_Transfer.TransferID, IN_Transfer.TransferNo, IN_TransferLines.FromPartNo, IN_Transferlines.ToPartNo, IN_Transferlines.TransferLineNo
FROM IN_TransferLines
JOIN IN_Transfer ON IN_Transfer.TransferID = IN_TransferLines.TransferID
WHERE IN_TransferLines.FromPartInventoryID = '<InventoryID HERE>' OR IN_TransferLines.FromPartInventoryID = '<InventoryID HERE>'


If that returns any rows, then the item has been added to a stock transfer.

JuiceyBrucey wrote:To replicate my issue, simply add an inventory item, view it using the attached plugin, then try to use swagger to delete the item. It wont delete.


I did and it deleted just fine.

My steps were as follows:

Step 1. Create the inventory item with a POST to Inventory with the following body:
Code: Select all
{
    "PartNo": "Test Item #1",
    "Description": "This is test item #1"
}

The response was 201 Created and the body contained the newly created inventory ID of 2ea9e7a0db2449a08f44
POST_Inventory.png


Step 2. Perform a GET on the /Custom/GetAllInventoryMinFields route - you never provided what parameters so I used /Custom/GetAllInventoryMinFields/1/5
The response was 200 OK and the body can be seen below:
GET_GetAllInventoryMinFields.png


Step 3. Perform a DELETE on /Inventory, with the ID of the previously created item - so /Inventory/2ea9e7a0db2449a08f44
The response was 204 No content - as is expected with deletes.
Note the body is empty for this request - nothing placed in there.
DELETE_Inventory.png


Now it's your turn. Document exactly as I have the steps you follow to get the error. Include screenshots showing both the request URL, HTTP Verb and the request body along with at least part of the response.
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

PreviousNext

Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 18 guests