# How to clone an element?

**URL:** <https://community.bluescape.com/t/how-to-clone-an-element/5574>\
**Category:** Developer\
**Created:** [February 13, 2024, 3:24pm UTC](https://community.bluescape.com/t/how-to-clone-an-element/5574 "2024-02-13T15:24:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amerehei](https://sea1.discourse-cdn.com/bluescape/user_avatar/community.bluescape.com/amerehei/32/5629_2.png) [@Amerehei](https://community.bluescape.com/u/Amerehei)\
**Post date:** [February 13, 2024, 3:24pm UTC](https://community.bluescape.com/t/how-to-clone-an-element/5574/1 "2024-02-13T15:24:11Z")

</div>

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`?

---

<div class="post-metadata">

**Author:** ![kkoechley](https://sea1.discourse-cdn.com/bluescape/user_avatar/community.bluescape.com/kkoechley/32/2474_2.png) [@kkoechley](https://community.bluescape.com/u/kkoechley)\
**Post date:** [February 13, 2024, 7:22pm UTC](https://community.bluescape.com/t/how-to-clone-an-element/5574/2 "2024-02-13T19:22:39Z")

</div>

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:

```auto
#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:

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

```

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

```auto
{
    "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:

```auto
# 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:

```auto
{
    "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
}

```

---

<div class="post-metadata">

**Author:** ![Amerehei](https://sea1.discourse-cdn.com/bluescape/user_avatar/community.bluescape.com/amerehei/32/5629_2.png) [@Amerehei](https://community.bluescape.com/u/Amerehei)\
**Post date:** [February 13, 2024, 8:26pm UTC](https://community.bluescape.com/t/how-to-clone-an-element/5574/3 "2024-02-13T20:26:24Z")

</div>

Thank you for your great answer!

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/bluescape/user_avatar/community.bluescape.com/system/32/710_2.png) [@system](https://community.bluescape.com/u/system)\
**Post date:** [March 14, 2024, 8:27pm UTC](https://community.bluescape.com/t/how-to-clone-an-element/5574/4 "2024-03-14T20:27:18Z")

</div>

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