Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- Be respectful, on topic and if you see a problem, Flag it.
If you would like to contact our Community Manager personally, feel free to send a private message or an email.
POST /elements/copyelement/{did}/workspace/{wid} return Bad Request
I want to copy an element from another workspace to my workspace. The API code I called is as follows, but it returns 400 Bad Request. Why can't I copy it?
def copyElement(self, source_url, target_url):
v_list = source_url.split("/")
sdid, swid, seid = v_list[-5], v_list[-3], v_list[-1]
v_list = target_url.split("/")
tdid, twid, _ = v_list[-5], v_list[-3], v_list[-1]
body = {
"documentIdSource": sdid,
"workspaceIdSource": swid,
"elementIdSource": seid,
"isGroupAnchor": True
}
res = self._api.request("post", "/api/v10/elements" +
"/copyelement/" + tdid +
"/workspace/" + twid,
body=body)
self.to_jsonfile(res.json(), "copyElement") source_url = "https://cad.onshape.com/documents/56fb9fbbe4b01bbb565f8527/w/c64129b1ffea6a9dce644def/e/19e777a0e100efd7c473ef8d"
target_url = {my_workspace_url}
Best Answer
-
chadstoltzfus Member, Developers, csevp Posts: 144 PRO
Intersting, I kept getting a "Bad request" which tells me something else is going on. I created a copy of the workspace and tried just manually copying and pasting the element and got the following
So there might be something wrong with the Part Studio itself. Upon looking at the FeatureScript for that Part Studio (right click on the part studio > Show code) I can see that the FS version is really out of date so that might have something to do with it.
Try deleting the document, then restoring it from the trash, then going into it should prompt you to update the version of the standard library. Doing that fixed it for me.
Applications Developer at Premier Custom Built
chadstoltzfus@premiercb.com1
Answers
A couple of debugging tips:
Thanks for you response @Paul_J_Premakumar , I tried glassworks
https://cad.onshape.com/glassworks/explorer#/Element/copyElementFromSourceDocument
but it still not working with same error:I also double checked the paramters and ensure it's correct.
The request information in glassworks is as follows:
and the source element:
https://cad.onshape.com/documents/56fb9fbbe4b01bbb565f8527/w/c64129b1ffea6a9dce644def/e/19e777a0e100efd7c473ef8d
is public you can check it out.The target document id
did
and workspace idwid
in Request URL is from the document I newly created.I am able to reproduce the issue. Can you copy the document from the Onshape UI and see if it works for you? If you are blocked, please open a support ticket.
Thanks for your help. Copying in Onshape UI works(but the copying in UI is done by copying the entire document, not just a single element)
So it seems to be a problem with the API itself? Will you consider fixing it later?
Now if I want to copy an element via API, is the only way to do this by copying the document?
The only source information I have now is the URL like:
https://cad.onshape.com/documents/56fb9fbbe4b01bbb565f8527/w/c64129b1ffea6a9dce644def/e/19e777a0e100efd7c473ef8d
But I don’t quite understand the parameters in copy document method:
https://cad.onshape.com/glassworks/explorer#/Document/copyWorkspace
POST /documents/{did}/workspaces/{wid}/copy
"isPublic": true,
"newName": "string",
"ownerId": "string",
"ownerTypeIndex": 0,
"parentId": "string",
"projectId": "string"
} (Based on I only have the onshape URL)
@jiahao_lee103 I've been using the copyElement endpoint.
Body params are:
'body' : {
'anchorElementId' : "string",
'documentIdSource' : "string",
"elementIdSource" : "string",
"isGroupAnchor" : boolean,
"workspaceIdSource" : "string"
}
chadstoltzfus@premiercb.com
Hi, @chadstoltzfus
Did you copy this public element ("https://cad.onshape.com/documents/56fb9fbbe4b01bbb565f8527/w/c64129b1ffea6a9dce644def/e/19e777a0e100efd7c473ef8d")?
I tried again and it failed. Can you give me your detailed parameter values? Thank you very much.
Intersting, I kept getting a "Bad request" which tells me something else is going on. I created a copy of the workspace and tried just manually copying and pasting the element and got the following
So there might be something wrong with the Part Studio itself. Upon looking at the FeatureScript for that Part Studio (right click on the part studio > Show code) I can see that the FS version is really out of date so that might have something to do with it.
Try deleting the document, then restoring it from the trash, then going into it should prompt you to update the version of the standard library. Doing that fixed it for me.
chadstoltzfus@premiercb.com