How to clone an element?

In BS workspace, we can copy and past any elements including documents. It seems when I copy and past a document, BS simply clones it and there is no need to download and re-upload the file.

How can I do the same with GraphQL API? how to clone a document without needing to download it and call createDocument?

Hi @Amerehei,

While we don’t currently have a duplicate element mutation, you can make a copy of of document element without needing to download the document by using element query to get the document asset url, and then use the url with createDocument mutation.

First you query the document element to get the signed S3 asset URL:

#find an element by elementID:
query getElementById($workspaceId: String!, $elementId:String!){
    elements(workspaceId: $workspaceId, id:$elementId) {        
        __typename
        id
        transform{
            x y scaleX scaleY
        }

        boundingBox{
            width
            height
            x
            y
        }

        ... on Document{
            width
            height
            title
            filename
            sourceUrl

            asset{
                documentFormat
                url
            }

        }
    }
}

variables:

{
    "workspaceId": "{{workspaceID}}",
    "elementId": "{{elementId}}"
}

sample response with signed URL which must be used within 300 seconds (5 mins)

{
    "data": {
        "elements": [
            {
                "__typename": "Document",
                "id": "65690d42daa7498342940bf3",
                "transform": {
                    "x": 0,
                    "y": 0,
                    "scaleX": 1,
                    "scaleY": 1
                },
                "boundingBox": {
                    "width": 1280,
                    "height": 998,
                    "x": -1376,
                    "y": 1
                },
                "width": 1280,
                "height": 998,
                "title": "Carrier 4pk[22]_2.pdf",
                "filename": "Carrier 4pk[22]_2.pdf",
                "sourceUrl": null,
                "asset": {
                    "documentFormat": "pdf",
                    "url": "https://s3.us-east-1.amazonaws.com/public-assets.bluescape.com/sessions/objects/NDuSmr2cNP0znblFm-cV/65690d42daa7498342940bf3.pdf?X-Amz-Algorithm=<redacted>"
                }
            }
        ]
    }
}

You can then use the asset.url value from the query in a createDocument mutation, as well as transform and boundingBox to duplicate the document in your desired location and scale:

# Create Document from URL
mutation createDocumentFromUrl($ws: String!, $x: Float!, $y: Float!, $title: String!, $documentFormat: DocumentFormatInput!, $url: String!, $scale: Float) {
  createDocument(workspaceId: $ws, input: {
    title: $title, 
    pinned: true, 
    documentFormat: $documentFormat, 
    sourceUrl: $url, 
    transform: {x: $x, y: $y, scale: $scale}
  }) {
    # Return values after creation:
    content {uploadId url fields}
    preview {uploadId url fields}
    document {id width height ingestionState}
  }
}

variables:

{
    "ws": "{{workspaceID}}",
    "title":"testPDF.pdf",
    "documentFormat":"pdf",
    "previewFormat":"png",
    "url":"https://s3.us-east-1.amazonaws.com/public-assets.bluescape.com/sessions/objects/NDuSmr2cNP0znblFm-cV/65690d42daa7498342940bf3.pdf?X-Amz-Algorithm=<redacted>",
    "x":0,
    "y":0,
    "scale":1
}

Thank you for your great answer!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.