Mass delete Files from records, but leave the records

Dear friends...

Any ideas on a way to mass delete files from records but to leave the record itself intact?

I actually thought I was doing this succesfully, but was deluding myself...  I use a report to ID the records I need, then from that report export do a textjoin to get a string of ID's, then use Postman to do the mass update using that string of ID's:

PUT {{url}}g_Registration/MassUpdate      (a custom module with file field: data-name="filename")

{  
    "massupdate_params": {
        "uid": [
            "a5ee304a-dd33-11ed-927f-0645eac4c674","ID2","ID3"...etc
        ],
    
       "filename" : ""
    }
}

But I now realise if I add a new filename

"filename" : "newFileName.pdf"

the actual file was still there! just with no name.

The Delete method: DELETE {{url}}g_Registration/MassUpdate... perfectly deletes the entire record.

So wondering if there is another way for a mere admin to achieve the same?
I was unable to use process definition to remove the file too.

If you work for Sugar and see this...  if only Data Archiver had some additional functionality to update a record? That'd be cool.

Thank for any tips...
Luke.

Parents
  • Hello  , 

    I was testing in the GUI and when deleting the file in Sugar this is the endpoint being hit: 

    So in postman I tried to hit this endpoint against my records: 

    DELETE  https://{MySugarURL}/rest/v11_23/ddd_Registrations/389c91e8-1924-11ef-aa6d-02a5a97c2d5e/file/uploadfile?delete_if_fails=true&platform=base

    And it seems to do the job.Only the file is deleted. 

    I've only tested a record individually, But if you have a .csv export you could set it up to import in postman and run it as a collection. 
    I've done something similar in the past, if you struggle implementing this let me know and I'll try find the collection that I used. 

    Let me know if this helps. 

    Cheers, 

    André 

  • Thank you  for your reply...
    I do use that endpoint from time to time...  but I had not figured how to use it for multiple records.

    So:  .csv export (yep, I have that from my report) to import in postman and run it as a collection.
    Aha... didn't know how to do that - will be my side job today Grinning

    Thank you for the top tip Andre, I will post my findings up here when done.

    For info, I need to do this as part of Storage Management - which does seem lacking in Sugar sadly.  So once in whatever timescale I hope to run my report, get the ID's into a string for postman (hopefully now using the collection method) ten delete all the proof of purchase files that until now we have stored indefinitely.  Just one part of a bigger project, But... if the collection thing works i can use that elswhere for other modules...

    Will keep this post posted...   Luke.
    (I am away from the office next week, so likely in a couple of weeks)

  • Hello Luke, 

    I've found the one I had and I am happy if you use it as a starting point: 

    {
    	"info": {
    		"_postman_id": "c5b114ed-d0a7-4b13-854f-96b37696c513",
    		"name": "Delete Files Collection Copy",
    		"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
    		"_exporter_id": "3279487"
    	},
    	"item": [
    		{
    			"name": "Authenticate",
    			"event": [
    				{
    					"listen": "test",
    					"script": {
    						"exec": [
    							"var jsonData = JSON.parse(responseBody);",
    							"var access_token = jsonData.access_token;",
    							"",
    							"tests[\"access_token exists\"] = access_token !== null || access_token !== \"\";",
    							"",
    							"postman.setEnvironmentVariable(\"access_token\", access_token);",
    							""
    						],
    						"type": "text/javascript"
    					}
    				}
    			],
    			"request": {
    				"method": "POST",
    				"header": [],
    				"body": {
    					"mode": "raw",
    					"raw": "{\n   \"grant_type\":\"password\",\n   \"client_id\":\"sugar\",\n   \"client_secret\":\"\",\n   \"username\":\"{{username}}\",\n   \"password\":\"{{password}}\",\n   \"platform\":\"base\"\n}"
    				},
    				"url": {
    					"raw": "{{url}}{{rest_endpoint}}/oauth2/token",
    					"host": [
    						"{{url}}{{rest_endpoint}}"
    					],
    					"path": [
    						"oauth2",
    						"token"
    					]
    				},
    				"description": "Retrieving oauth token"
    			},
    			"response": []
    		},
    		{
    			"name": "Delete Registration File",
    			"event": [
    				{
    					"listen": "prerequest",
    					"script": {
    						"exec": [
    							"// Load the CSV data for the current iteration",
    							"const csvData = pm.iterationData.toObject();",
    							"",
    							"// Extract values using column names",
    							"const record_to_delete_id = csvData[\"record_to_delete_id\"];",
    							"",
    							"// Set variables to use in your request",
    							"pm.variables.set(\"record_to_delete_id\", record_to_delete_id);",
    							"",
    							"console.log(\"Record to Delete ID:\", record_to_delete_id);",
    							""
    						],
    						"type": "text/javascript",
    						"packages": {}
    					}
    				},
    				{
    					"listen": "test",
    					"script": {
    						"exec": [
    							"var jsonData = JSON.parse(responseBody);",
    							"",
    							"tests[\"Successful DELETE request\"] = responseCode.code === 200;",
    							""
    						],
    						"type": "text/javascript",
    						"packages": {}
    					}
    				}
    			],
    			"request": {
    				"method": "DELETE",
    				"header": [
    					{
    						"key": "oauth-token",
    						"value": "{{access_token}}",
    						"type": "text"
    					}
    				],
    				"url": {
    					"raw": "{{url}}{{rest_endpoint}}/ddd_Registrations/{{record_to_delete_id}}/file/uploadfile?delete_if_fails=true&platform=base",
    					"host": [
    						"{{url}}{{rest_endpoint}}"
    					],
    					"path": [
    						"ddd_Registrations",
    						"{{record_to_delete_id}}",
    						"file",
    						"uploadfile"
    					],
    					"query": [
    						{
    							"key": "delete_if_fails",
    							"value": "true"
    						},
    						{
    							"key": "platform",
    							"value": "base"
    						}
    					]
    				}
    			},
    			"response": []
    		}
    	]
    }



    If you want to test, after uploading you'll need to adapt the module names to match your instance module. 

    Then you need to press Run in the collection: 



    Then make sure you have the correct Environment Variables: 

    After that you can run  one Authenticate request to get the token

    After that you can load your .csv with the id's to delete, the column name is defined set as record_to_delete_id but you can change it in the collection code
     


    This is a successful test: 



    The tests part might be improved as I realised is returning success even if the record doesn't have a file. 

    However I hope this helps as a first draft for you. 


    Let me know how it goes

    André 

  • Thanks so much  for all the info...

    It works...
    I actually got it working before seeing your info above - a nod to Postman collections was what  I needed... and a quick youtube video later, and decent learning curve...

    Using Postman's Runner, and variables that match (case sensitive) the headers of the csv...   

    Your info above explains what i just learned - wish i checked back sooner now Laughing

    I can document my steps too if it will help anybody... but for now thanks to Andre I go to my weeks holiday knowing the strorage will not be hitting 100% whiole i am away Sunglasses

Reply
  • Thanks so much  for all the info...

    It works...
    I actually got it working before seeing your info above - a nod to Postman collections was what  I needed... and a quick youtube video later, and decent learning curve...

    Using Postman's Runner, and variables that match (case sensitive) the headers of the csv...   

    Your info above explains what i just learned - wish i checked back sooner now Laughing

    I can document my steps too if it will help anybody... but for now thanks to Andre I go to my weeks holiday knowing the strorage will not be hitting 100% whiole i am away Sunglasses

Children
  • Hello Luke,

    I'm glad I could assist you!

    Regarding your feedback on improving the product's storage management, I recommend creating a support case detailing your experience. This will allow our support team to generate an idea and have our Product Managers analyze it and gauge interest from other customers.

    While I can't guarantee implementation, I assure you that your suggestion will be reviewed and considered.

    Enjoy your time off!

    André