# Add Link through API

**URL:** <https://community.bluescape.com/t/add-link-through-api/3847>\
**Category:** Developer\
**Created:** [July 25, 2023, 2:00am UTC](https://community.bluescape.com/t/add-link-through-api/3847 "2023-07-25T02:00:47Z")\
**Posts on this page:** 3\
**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:** [July 25, 2023, 2:00am UTC](https://community.bluescape.com/t/add-link-through-api/3847/1 "2023-07-25T02:00:47Z")

</div>

in the Bluescape workspace we have a “Add link” option for texts. I couldn’t find it in the RESTful or GraphQL API. How can I add link using API?

---

<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:** [July 25, 2023, 9:28pm UTC](https://community.bluescape.com/t/add-link-through-api/3847/2 "2023-07-25T21:28:49Z")

</div>

You can add a link from an element to another using [element traits metadata](https://community.bluescape.com/t/traits-api-for-elements-traits/2138).

**The appLink format is:**  
`https://client.apps.us.bluescape.com/applink/<yourWorkspaceId>?objectId=<objectToLinkTo>`

You can set traits to create an appLink using the following format, using traits **`vocab`** and **`content.link`** :

```auto
traits:{
  vocab: "http://bluescape.dev/hyperlinks/v1/", 
    content: {
        link: "#64c01b747b56b021723c62f8"
    }
}

```

You can either use this to create an element, or you can use updateTraits to update an existing element. These can be done with either REST or graphQL APIs.

A graphQL example of creating a new shape with an appLink linked to another element:

```auto
#create shape with json-ld traits data
mutation createShapeWithLinkTraits($ws: String! $x:Float! $y:Float!, $width:Float!, $height:Float!, $textContent:String!) {
        shape1:createShape(
        workspaceId: $ws
            input: {
                text:$textContent
                traits:{
                    vocab: "http://bluescape.dev/hyperlinks/v1/", 
                    content: {
                        link: "#64c01b747b56b021723c62f8"
                    }
                }
                
                mirrorY: false 
                style: {
                    regularShape:{

                        kind:Rectangle
                        width:$width height:$height strokeWidth: 5 
                        #fillColor not working in beta1
                        fillColor: {r:255 g:34 b:255 a:1}
                        strokeColor:{r:0 g:255 b:0 a:1}
                    }   
                }
                transform:{x:$x y:$y}
                textStyle:{
                    fontSize:12
                    verticalAlign:bottom
                    color:{
                        r:0
                        g:0
                        b:255
                        a:1
                    }
                }
            })

        #return values:
        {id kind mirrorY traits}
    }

```

with variables:

```auto
{
    "ws": "{{workspaceID}}",
    "textContent" : "graphQL shape with simple traits",
    "x": 0,
    "y": 0,
    "width": 800,
    "height": 300
}

```

Or you can use **`updateTraits`** to update traits for an existing element:

```auto
#update element JSON-LD traits metadata
mutation updateTraitsForLink ($workspaceId:String!, $id:String!, $linkToId:String!){
  updateTraits(workspaceId: $workspaceId id:$id input: {
    vocab: "http://bluescape.dev/hyperlinks/v1/"
    content: {
      link: $linkToId
    }
  })
}

```

with variables:

```auto
{
    "workspaceId": "{{workspaceID}}",
    "id" : "64c031db65246380966440a3",
    "linkToId":"#64c01b747b56b021723c62f8"
}

```

---

<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:** [August 24, 2023, 9:29pm UTC](https://community.bluescape.com/t/add-link-through-api/3847/3 "2023-08-24T21:29:38Z")

</div>

Closed on August 24, 2023, 9:29pm UTC

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