Jump to content

REST API - How to checkin deleted files


baptiste

Recommended Posts

Hi,

When using Plastic SCM GUI, a item removed locally (a deleted file) appears in the "Pending Changes" section and this change can be checkin.

I cannot figure out how to to replicate this using the REST API, i.e I would like to checkin a file deletion. I tried setting the `paths` parameter to the path of the deleted file or of the directory where the deleted file was located.

url = __api_url + f"/wkspaces/myworkspace/checkin"
params = {
    "paths": [
        "wkpath/to/file" # also tried "wkpath/to/file_dir"
    ],
    "comment": "Deleting a file",
    "recurse": True,
}
res = requests.post(
    url,
    headers={
        "Content-type": "application/json",
        "Accept": "application/json",
    },
    data=json.dumps(params),
)
print(res.json())
# will print: {'totalSize': 0, 'transferredSize': 0, 'status': 'Checkin operation starting...'}

And the response returned by a GET at "api/v1/wkspaces/myworkspace/checkin" is:
 

{"status":"Failed", "message":"There are no changes in the workspace c:\\Users\\Baptiste\\wkspaces\\myworkspace"}

 

What am I missing? How do you submit a file deletion when using the REST API?

Thank you!

Link to comment
Share on other sites

  • 2 weeks later...

Hi,
 
Sorry for the delayed response.

Leaving the path parameter empty while you have a pending deleted file should checkin the deletion. Have you tried that?

https://www.plasticscm.com/documentation/restapi/plastic-scm-version-control-rest-api-guide#Checkin

Let me know if I understood your question correctly.
 
Regards,
 
Rafael
Unity Plastic SCM Support
Virtualize your Workspace. Make it dynamic.

Link to comment
Share on other sites

Hi Rafael,

I tried leaving the `paths` parameter empty, either by passing an empty list:
 

params = {
    "paths": [],
    "comment": "Deleting a file",
    "recurse": True,
}

or by omitting the parameter:
 

params = {
    "comment": "Deleting a file",
    "recurse": True,
}

In both cases, I tried with recurse set to `True` or `False`.  The returned response is always:
 

{'totalSize': 0, 'transferredSize': 0, 'status': 'Checkin operation starting...'}

 

The item still appears in the "Pending Changes " as "Removed locally".

 

Cheers,

 

Baptiste

Link to comment
Share on other sites

Hi @ollieblanks,

 

Thank your answer. Does it mean it's not possible to check in an item deletion if the file has already been removed from the workspace?

 

I tried your suggestion, but I still can't' check in the deletion.  Here's what I've been trying to do:

 

I have a workspace named "test_decentralized", with a "cube.glb" file at the root of this workspace. I want to be able to delete this file and check in this deletion.

 

wkname = "test_decentralized"
path = "cube.glb" # Its actual filepath on my system is "C:\\Users\\Baptiste\\wkspaces\\test_decentralized\\cube.glb"


# Checkout the file
url = __api_url + f"/wkspaces/{wkname}/content/{path}"
res = requests.put(url)
print(f"req.status_code = {res.status_code}")
if res.status_code != 200:
    raise
print(res.json()) # -> seems to work, I get "{'affectedPaths': ['c:\\Users\\Baptiste\\wkspaces\\test_decentralized\\cube.glb']}"

# Locally remove the file
os.remove("C:\\Users\\Baptiste\\wkspaces\\test_decentralized\\cube.glb")

# Try to checkin this deletion
url = __api_url + "wkspaces/test_decentralized/checkin"
params = {
    "paths": ["cube.glb"], # I also tried passing an empty list this empty 
    "comment": "Deleting a file",
    "recurse": True,
}
res = requests.post(
    url,
    headers={
        "Content-type": "application/json",
        "Accept": "application/json",
    },
    data=json.dumps(params),
)
print(res.json()) # -> {'totalSize': 0, 'transferredSize': 0, 'status': 'Checkin operation starting...'}

res = requests.get(__api_url + f"wkspaces/{wkname}/checkin")
print(res.json()) # -> {'status': 'Failed', 'message': 'The item c:\\Users\\Baptiste\\wkspaces\\test_decentralized\\cube.glb does not exist in the workspace.'}

The cube.glb file is liested in Plastic GUI in the "Pending Changes" tab, as a deleted item with a status "Removed locally".

 

Cheers,

 

Baptiste

Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...