# Update a DID

Users are able to update DID Documents for various reasons, such as to include a new section (such as `service`) or to rotate the `verificationMethod` or `authentication` keys within the DID Document.&#x20;

With the `/did/update` API, users are able to input either:

1. &#x20;The specific section(s) of the DID Document to be updated; or
2. The full updated DID Document body.

{% hint style="info" %}
For the `/did/update` function, users are recommended to use the `application/json` request format for the API.
{% endhint %}

## Example Request formats

#### Update Service Section

To update individual sections of the DID Document, users are able to pass only the section they would like to update. For example, users may often want to update the `service` section to add or change a `serviceEndpoint`:

```json
{
  "did": "did:cheqd:mainnet:71e24492-e62c-4e55-a581-007a6e36e881",
  "service": [
      {
        "id": "did:cheqd:mainnet:71e24492-e62c-4e55-a581-007a6e36e881#website",
        "type": "LinkedDomains",
        "serviceEndpoint": [
          "https:example.com"
        ]
      }
    ]
}
```

The above request format will replace the `service` section of the existing DID Document with the new section. No extra information, such as the verificationMethod or `authentication` keys need to be passed with the request, because cheqd Studio custodies the keys on behalf of the user.&#x20;

#### Rotate Keys

Users may regularly want to rotate the keys used to control the DID. Like with the `service` section above, users are able to pass the sections of the DID Document that include the rotated keys, usually contained within the`verificationMethod` and `authentication` sections.

{% hint style="info" %}
Other sections such as `keyAgreement`, `capabilityInvocation`, `capabilityDelegation`, `assertionMethod`, etc. may also be updated via this method
{% endhint %}

```json
{
  "did": "did:cheqd:mainnet:71e24492-e62c-4e55-a581-007a6e36e881",
  "verificationMethod": [
     {
       "id":"did:cheqd:mainnet:71e24492-e62c-4e55-a581-007a6e36e881#key-2",
       "type":"Ed25519VerificationKey2018",
       "controller":"did:cheqd:mainnet:71e24492-e62c-4e55-a581-007a6e36e881",
       "publicKeyBase58":"4sjwZ3VGWupJ26ytxjhU6LhjKiPrHV5reZbaNseyHtf8"
     }
  ],
  "authentication": [
       "did:cheqd:mainnet:71e24492-e62c-4e55-a581-007a6e36e881#key-2"
  ]
}
```

The example above will rotate the keys that control the DID Document, updating the DID Document's `verificationMethod` and `authentication` sections accordingly.&#x20;

{% hint style="info" %}
Any top level section of the DID Document may be updated this way, including the likes of `alsoKnownAs`, `assertionMethod`, `capabilityDelegation`, etc.&#x20;
{% endhint %}

### Pass full updated DID Document body

Users may alternatively want to update the DID Document body in full, and pass the updated DID Document to the API. For example:

```json
{
  "didDocument": {
    "@context": [
      "https://www.w3.org/ns/did/v1",
      "https://w3id.org/security/suites/ed25519-2018/v1"
    ],
    "id": "did:cheqd:mainnet:71e24492-e62c-4e55-a581-007a6e36e881",
    "controller": [
      "did:cheqd:mainnet:71e24492-e62c-4e55-a581-007a6e36e881"
    ],
    "verificationMethod": [
      {
        "id": "did:cheqd:mainnet:71e24492-e62c-4e55-a581-007a6e36e881#key-1",
        "type": "Ed25519VerificationKey2018",
        "controller": "did:cheqd:mainnet:71e24492-e62c-4e55-a581-007a6e36e881",
        "publicKeyBase58": "4sjwZ3VGWupJ26ytxjhU6LhjKiPrHV5reZbaNseyHtf8"
      }
    ],
    "authentication": [
      "did:cheqd:mainnet:71e24492-e62c-4e55-a581-007a6e36e881#key-1"
    ],
    "service": [
      {
        "id": "did:cheqd:mainnet:71e24492-e62c-4e55-a581-007a6e36e881#website",
        "type": "LinkedDomains",
        "serviceEndpoint": [
          "https://example.com"
        ]
      }
    ]
  }
}
```

This method may be better for users wanting to update larger portions of the DID Document, or for having full visibility over the updated body.

## Get started with the API below

Use the `/did/update` API below to pass your DID Document update as a request, using either the full body or a specific section.

## Update a DID Document.

> This endpoint updates a DID Document. As an input, it can take JUST the sections/parameters that need to be updated in the DID Document (in this scenario, it fetches the current DID Document and applies the updated section). Alternatively, it take the fully-assembled DID Document with updated sections as well as unchanged sections.

```json
{"openapi":"3.0.0","info":{"title":"cheqd Studio API for cheqd network","version":"2.0.0"},"tags":[{"name":"Decentralized Identifiers (DIDs)"}],"servers":[{"url":"https://studio-api.cheqd.net","description":"Main (production) server"},{"url":"https://studio-api-staging.cheqd.net","description":"Staging server for testing"},{"url":"http://localhost:3000","description":"Local server for testing"}],"security":[{"ApiKeyAuth":[]}],"components":{"securitySchemes":{"ApiKeyAuth":{"type":"apiKey","name":"x-api-key","in":"header"}},"schemas":{"DidUpdateRequest":{"type":"object","properties":{"did":{"description":"DID identifier to be updated.","type":"string"},"service":{"type":"array","description":"Service section of the DID Document.","items":{"$ref":"#/components/schemas/Service"}},"verificationMethod":{"type":"array","description":"Verification Method section of the DID Document.","items":{"$ref":"#/components/schemas/VerificationMethod"}},"authentication":{"description":"Authentication section of the DID Document.","type":"array","items":{"type":"string"}},"publicKeyHexs":{"description":"List of key references (publicKeys) which will be used for signing the message. The should be in hexadecimal format and placed in the wallet of current user.","type":"array","items":{"type":"string"}},"didDocument":{"$ref":"#/components/schemas/DidDocument"}}},"Service":{"description":"Communicating or interacting with the DID subject or associated entities via one or more service endpoints. See <a href=\"https://www.w3.org/TR/did-core/#services\">DID Core specification</a> for more details.","type":"object","properties":{"id":{"description":"DID appended with Service fragment ID (e.g., `#service-1` in `did:cheqd:mainnet:7bf81a20-633c-4cc7-bc4a-5a45801005e0#service-1`)","type":"string"},"type":{"description":"Service type as defined in <a href=\"https://www.w3.org/TR/did-spec-registries/#service-types\">DID Specification Registries</a>.","type":"string"},"serviceEndpoint":{"description":"Service endpoint as defined in <a href=\"https://www.w3.org/TR/did-core/#services\">DID Core Specification</a>.","type":"array","items":{"type":"string"}},"priority":{"description":"(Optional) Priority of the service endpoint, used for distinction when multiple did-communication service endpoints are present in a single DID document.","type":"integer"},"recipientKeys":{"description":"(Optional) List of recipient keys used to denote the default recipients of an endpoint.","type":"array","items":{"type":"string"}},"routingKeys":{"description":"(Optional) List of routing keys used to used to denote the individual routing hops in between the sender and recipients.","type":"array","items":{"type":"string"}},"accept":{"description":"(Optional) List of media types that the service endpoint accepts.","type":"array","items":{"type":"string"}}}},"VerificationMethod":{"type":"object","properties":{"id":{"type":"string"},"type":{"type":"string"},"controller":{"type":"string"},"publicKeyMultibase":{"type":"string"},"publicKeyJwk":{"type":"array","items":{"type":"string"}}}},"DidDocument":{"description":"This input field contains either a complete DID document, or an incremental change (diff) to a DID document. See <a href=\"https://identity.foundation/did-registration/#diddocument\">Universal DID Registrar specification</a>.","type":"object","properties":{"@context":{"type":"array","items":{"type":"string"}},"id":{"type":"string"},"controllers":{"type":"array","items":{"type":"string"}},"verificationMethod":{"type":"array","items":{"$ref":"#/components/schemas/VerificationMethod"}},"service":{"type":"array","items":{"$ref":"#/components/schemas/Service"}},"authentication":{"type":"array","items":{"type":"string"}},"assertionMethod":{"type":"array","items":{"type":"string"}},"capabilityInvocation":{"type":"array","items":{"type":"string"}},"capabilityDelegation":{"type":"array","items":{"type":"string"}},"keyAgreement":{"type":"array","items":{"type":"string"}}}},"DidUpdateResponse":{"type":"object","properties":{"did":{"type":"string"},"controllerKeyId":{"type":"string","description":"The default key id of which is the key associated with the first verificationMethod"},"keys":{"type":"array","description":"The list of keys associated with the list of verificationMethod's of DIDDocument","items":{"type":"object"}},"services":{"type":"array","items":{"$ref":"#/components/schemas/Service"}},"controllerKeyRefs":{"type":"array","description":"The list of keyRefs which were used for signing the transaction","items":{"type":"string"}},"controllerKeys":{"type":"array","description":"The list of all possible keys, inlcuding all controller's keys","items":{"type":"string"}}}},"InvalidRequest":{"description":"A problem with the input fields has occurred. Additional state information plus metadata may be available in the response body.","type":"object","properties":{"error":{"type":"string"}}},"UnauthorizedError":{"description":"Access token is missing or invalid","type":"object","properties":{"error":{"type":"string"}}},"InternalError":{"description":"An internal error has occurred. Additional state information plus metadata may be available in the response body.","type":"object","properties":{"error":{"type":"string"}}}}},"paths":{"/did/update":{"post":{"tags":["Decentralized Identifiers (DIDs)"],"summary":"Update a DID Document.","description":"This endpoint updates a DID Document. As an input, it can take JUST the sections/parameters that need to be updated in the DID Document (in this scenario, it fetches the current DID Document and applies the updated section). Alternatively, it take the fully-assembled DID Document with updated sections as well as unchanged sections.","requestBody":{"content":{"application/x-www-form-urlencoded":{"schema":{"$ref":"#/components/schemas/DidUpdateRequest"}},"application/json":{"schema":{"$ref":"#/components/schemas/DidUpdateRequest"}}}},"responses":{"200":{"description":"The request was successful.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/DidUpdateResponse"}}}},"400":{"$ref":"#/components/schemas/InvalidRequest"},"401":{"$ref":"#/components/schemas/UnauthorizedError"},"500":{"$ref":"#/components/schemas/InternalError"}}}}}}
```
