---
agentTools:
  projectIndex: https://uspacy.readme.io/llms.txt
---

# Update Email Credentials

Updates existing email credentials for IMAP and SMTP access. Only accessible by authorized users.

# OpenAPI definition

````json
{
  "openapi": "3.1.0",
  "info": {
    "description": "This is [Uspacy](https://uspacy.com)  API documentation. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/).\nor on [irc.freenode.net, #swagger](http://swagger.io/irc/).\n\n# Introduction\nTo use this API you need to get Bearer token. To get Bearer token you have two options:\n  - sign in on user's Uspacy using email and password\n  - create Marketplace application and get token in callback after your application was installed by user\n\n# SDKs and boilerplates\nWe provide SDKs for different languages to simplify integration with Uspacy API. You can find them on [Uspacy GitHub](https://github.com/Uspacy/)\nWe have also prepared a few boilerplates to help you start developing your application\n  - [Uspacy Marketplace application boilerplate](https://github.com/Uspacy/app-laravel-template) - Laravel application with Uspacy authentication and token refreshment\n  - [Uspacy Golang SDK](https://github.com/Uspacy/uspacy-go-sdk) – Golang SDK for Uspacy API, in active development\n  - [Uspacy TypeScript SDK](https://github.com/Uspacy/uspacy-sdk) – TypeScript SDK for Uspacy API, deprecated\n\n# Marketplace applications development\nTo develop Marketplace application you need to create an application in Uspacy Marketplace. You can do it via request to [Uspacy support](mailto:support@uspacy.com).\nYou will receive ```client_id``` and ```client_secret``` for your application. You will also need to provide ```callback_url``` for your application.\nAfter that, the install/uninstall endpoints for your applications should be implemented. Please note that the path for these endpoints should follow this format:\n```{{callback_url}}/portals/install``` and ```{{callback_url}}/portals/uninstall```, respectively.\nFor example, if your ```callback_url``` is ```https://google.com/handler/v1```, we will send webhook to ```https://google.com/handler/v1/portals/install``` on install and ```https://google.com/handler/v1/portals/uninstall``` on uninstall.\nAfter a user installs your application, you will receive a POST request with JSON in the callback.\nThis will contain the ```token```, ```refresh_token```, and ```expiry_date``` fields.\nAdditionally, the ```integration_token``` will be provided as a Bearer token in the Authorization header.\nIt is signed using the ```client_secret``` and the SHA-256 algorithm. All future requests from your application's frontend to its backend should be secured with the ```integration_token```.\nThe ```integration_token``` is accessible through using the [appService](#tag/appService) for users with administrative rights.\nExample of request:\n```json\n{\n  \"expiry_date\": 1683649235,\n  \"token\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjEyMzEyMzEyMyIsImZpcnN0TmFtZSI6IlN0YXMiLCJsYXN0TmFtZSI6IlJhcmFuZXRza3lpIiwiZW1haWwiOiJyYXIuc3Rhc0BnbWFpbC5jb20iLCJyb2xlcyI6WyJVU0VSIiwiQURNSU4iLCJPV05FUiJdfQ.au16u5LHJqdvhiPrpXDhN4NZn8Cae09I6BEmed7mt8w\",\n  \"refresh_token\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjEyMzEyMzEyMyIsImZpcnN0TmFtZSI6IlN0YXMiLCJsYXN0TmFtZSI6IlJhcmFuZXRza3lpIiwiZW1haWwiOiJyYXIuc3Rhc0BnbWFpbC5jb20iLCJyb2xlcyI6WyJVU0VSIiwiQURNSU4iLCJPV05FUiJdfQ.au16u5LHJqdvhiPrpXDhN4NZn8Cae09I6BEmed7mt8w\"\n}\n```\nYou need to save ```token```, ```refresh_token``` and ```expiry_date```  in your database. You will need to use ```token``` to make requests to Uspacy API. ```refresh_token``` is used to refresh ```token``` when it expires.\nYou should refresh the ```token``` before it expires. To do this, make a POST request to ```https://{domain}/auth/v1/auth/refresh_token/``` with the ```refresh_token``` in the body. The ```domain``` refers to the portal's domain that you received from the user's token headers upon application installation.\nYou will receive new ```jwt```, ```refreshToken``` and ```expireInSeconds``` in response. You need to save new ```token```, ```refresh_token``` and update ```expiry_date``` in your database.\n",
    "title": "Uspacy api",
    "version": "v1"
  },
  "servers": [
    {
      "url": "https://{domain}.uspacy.ua",
      "description": "Ukrainian server"
    },
    {
      "url": "https://{domain}.uspacy.eu",
      "description": "EU server"
    },
    {
      "url": "https://{domain}.uspacy.com.br",
      "description": "Brazilian server"
    },
    {
      "url": "https://{domain}.uspacy.com",
      "description": "International server"
    }
  ],
  "tags": [
    {
      "name": "emailService"
    }
  ],
  "paths": {
    "/email/v1/emails/credentials/{emailId}": {
      "patch": {
        "summary": "Update Email Credentials",
        "description": "Updates existing email credentials for IMAP and SMTP access. Only accessible by authorized users.",
        "tags": [
          "emailService"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/emailId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateEmailCredentialsDto"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EmailDetails"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedError"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "422": {
            "$ref": "#/components/responses/ValidationError"
          }
        },
        "security": [
          {
            "bearerAuth": []
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT"
      }
    },
    "responses": {
      "UnauthorizedError": {
        "description": "Access token is missing or invalid"
      },
      "Forbidden": {
        "description": "Forbidden",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "errors": {
                  "type": "object",
                  "properties": {
                    "text": {
                      "type": "array",
                      "items": {
                        "example": "Forbidden message"
                      }
                    }
                  }
                },
                "status": {
                  "type": "boolean",
                  "example": true
                }
              }
            }
          }
        }
      },
      "NotFound": {
        "description": "Resource not found",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "message": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "ValidationError": {
        "description": "Validation error response",
        "content": {
          "application/json": {
            "schema": {
              "type": "object",
              "properties": {
                "errors": {
                  "type": "object",
                  "additionalProperties": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "example": {
                    "field_name": [
                      "The field_name field is required."
                    ]
                  }
                },
                "status": {
                  "type": "boolean",
                  "example": true
                }
              }
            }
          }
        }
      }
    },
    "parameters": {
      "emailId": {
        "name": "emailId",
        "in": "path",
        "description": "The ID of the email",
        "required": true,
        "schema": {
          "type": "integer",
          "example": 10
        }
      }
    },
    "schemas": {
      "EmailItem": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "example": 2
          },
          "added_by": {
            "type": "integer",
            "example": 1
          },
          "auth_user_id": {
            "type": "integer",
            "example": 557
          },
          "imap_host": {
            "type": "string",
            "example": "imap.gmail.com"
          },
          "imap_port": {
            "type": "integer",
            "example": 993
          },
          "smtp_host": {
            "type": "string",
            "nullable": true,
            "example": "smtp.gmail.com"
          },
          "smtp_port": {
            "type": "integer",
            "nullable": true,
            "example": 587
          },
          "email": {
            "type": "string",
            "example": "stark@gmail.com"
          },
          "name": {
            "type": "string",
            "example": "Uspacy"
          },
          "sender_name": {
            "type": "string",
            "example": "Sender Name"
          },
          "access_level": {
            "type": "string",
            "enum": [
              "shared",
              "personal"
            ],
            "example": "shared"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending_settings",
              "first_sync",
              "connected",
              "auth_fail"
            ],
            "example": "connected"
          },
          "created_at": {
            "type": "integer",
            "example": 1711385960
          },
          "updated_at": {
            "type": "integer",
            "example": 1729099182
          },
          "oauth_provider": {
            "type": "string",
            "nullable": true,
            "example": null
          },
          "crm_integration_enabled": {
            "type": "boolean",
            "example": false
          }
        }
      },
      "EmailDetails": {
        "allOf": [
          {
            "$ref": "#/components/schemas/EmailItem"
          },
          {
            "type": "object",
            "properties": {
              "sync_folders": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/EmailSyncFolders"
                }
              },
              "folders": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/EmailFolders"
                }
              },
              "access_roles": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/EmailAccessRole"
                }
              }
            }
          }
        ]
      },
      "EmailFolder": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "example": 61
          },
          "email_id": {
            "type": "integer",
            "example": 10
          },
          "parent_id": {
            "type": "integer",
            "nullable": true,
            "example": null
          },
          "folder_name": {
            "type": "string",
            "example": "INBOX"
          },
          "path": {
            "type": "string",
            "example": "INBOX"
          },
          "delimitter": {
            "type": "string",
            "example": "/"
          },
          "is_trash": {
            "type": "boolean",
            "example": false
          },
          "is_spam": {
            "type": "boolean",
            "example": false
          },
          "is_draft": {
            "type": "boolean",
            "example": false
          },
          "is_junk": {
            "type": "boolean",
            "example": false
          },
          "is_sent": {
            "type": "boolean",
            "example": false
          },
          "is_inbox": {
            "type": "boolean",
            "example": true
          },
          "is_pending": {
            "type": "boolean",
            "example": false
          },
          "has_children": {
            "type": "boolean",
            "example": false
          },
          "is_root": {
            "type": "boolean",
            "example": true
          },
          "is_deleted": {
            "type": "boolean",
            "example": false
          },
          "message_count": {
            "type": "integer",
            "example": 4998
          },
          "unread_message_count": {
            "type": "integer",
            "example": 43
          }
        }
      },
      "EmailFolders": {
        "type": "array",
        "items": {
          "$ref": "#/components/schemas/EmailFolder"
        },
        "example": [
          {
            "id": 61,
            "email_id": 10,
            "parent_id": null,
            "folder_name": "INBOX",
            "path": "INBOX",
            "delimitter": "/",
            "is_trash": false,
            "is_spam": false,
            "is_draft": false,
            "is_junk": false,
            "is_sent": false,
            "is_inbox": true,
            "is_pending": false,
            "has_children": false,
            "is_root": true,
            "is_deleted": false,
            "message_count": 4998,
            "unread_message_count": 43
          },
          {
            "id": 64,
            "email_id": 10,
            "parent_id": null,
            "folder_name": "Sent Mail",
            "path": "[Gmail]/Sent Mail",
            "delimitter": "/",
            "is_trash": false,
            "is_spam": false,
            "is_draft": false,
            "is_junk": false,
            "is_sent": true,
            "is_inbox": false,
            "is_pending": false,
            "has_children": false,
            "is_root": false,
            "is_deleted": false,
            "message_count": 248,
            "unread_message_count": 0
          },
          {
            "id": 63,
            "email_id": 10,
            "parent_id": null,
            "folder_name": "Drafts",
            "path": "[Gmail]/Drafts",
            "delimitter": "/",
            "is_trash": false,
            "is_spam": false,
            "is_draft": true,
            "is_junk": false,
            "is_sent": false,
            "is_inbox": false,
            "is_pending": false,
            "has_children": false,
            "is_root": false,
            "is_deleted": false,
            "message_count": 73,
            "unread_message_count": 0
          },
          {
            "id": 66,
            "email_id": 10,
            "parent_id": null,
            "folder_name": "Trash",
            "path": "[Gmail]/Trash",
            "delimitter": "/",
            "is_trash": true,
            "is_spam": false,
            "is_draft": false,
            "is_junk": false,
            "is_sent": false,
            "is_inbox": false,
            "is_pending": false,
            "has_children": false,
            "is_root": false,
            "is_deleted": false,
            "message_count": 7612,
            "unread_message_count": 0
          }
        ]
      },
      "EmailAccessRole": {
        "type": "object",
        "properties": {
          "user_id": {
            "type": "integer",
            "example": 5
          },
          "name": {
            "type": "string",
            "enum": [
              "viewer",
              "destroyer",
              "setter"
            ],
            "example": "viewer"
          }
        }
      },
      "UpdateEmailCredentialsDto": {
        "type": "object",
        "properties": {
          "password": {
            "type": "string",
            "example": "newsecurepassword123"
          },
          "imap_host": {
            "type": "string",
            "example": "imap.gmail.com"
          },
          "imap_port": {
            "type": "integer",
            "example": 993
          },
          "smtp_host": {
            "type": "string",
            "nullable": true,
            "example": "smtp.gmail.com"
          },
          "smtp_port": {
            "type": "integer",
            "nullable": true,
            "example": 587
          }
        }
      },
      "EmailSyncFolders": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "folder_name": {
              "type": "string",
              "example": "INBOX"
            },
            "path": {
              "type": "string",
              "example": "INBOX"
            },
            "delimitter": {
              "type": "string",
              "example": "/"
            },
            "has_children": {
              "type": "boolean",
              "example": false
            },
            "is_root": {
              "type": "boolean",
              "example": true
            },
            "is_inbox": {
              "type": "boolean",
              "example": true
            },
            "is_draft": {
              "type": "boolean",
              "example": false
            },
            "is_sent": {
              "type": "boolean",
              "example": false
            },
            "is_junk": {
              "type": "boolean",
              "example": false
            },
            "is_trash": {
              "type": "boolean",
              "example": false
            }
          },
          "required": [
            "folder_name",
            "path",
            "delimitter",
            "has_children",
            "is_root"
          ]
        },
        "example": [
          {
            "folder_name": "INBOX",
            "path": "INBOX",
            "delimitter": "/",
            "has_children": false,
            "is_root": true,
            "is_inbox": true
          },
          {
            "folder_name": "Notes",
            "path": "Notes",
            "delimitter": "/",
            "has_children": false,
            "is_root": true
          },
          {
            "folder_name": "Drafts",
            "path": "[Gmail]/Drafts",
            "delimitter": "/",
            "has_children": false,
            "is_root": false,
            "is_draft": true
          },
          {
            "folder_name": "Sent Mail",
            "path": "[Gmail]/Sent Mail",
            "delimitter": "/",
            "has_children": false,
            "is_root": false,
            "is_sent": true
          },
          {
            "folder_name": "Spam",
            "path": "[Gmail]/Spam",
            "delimitter": "/",
            "has_children": false,
            "is_root": false,
            "is_junk": true
          },
          {
            "folder_name": "Trash",
            "path": "[Gmail]/Trash",
            "delimitter": "/",
            "has_children": false,
            "is_root": false,
            "is_trash": true
          }
        ]
      }
    }
  },
  "x-readme": {
    "explorer-enabled": true,
    "proxy-enabled": true
  },
  "_id": {
    "buffer": {
      "0": 101,
      "1": 36,
      "2": 32,
      "3": 193,
      "4": 231,
      "5": 38,
      "6": 198,
      "7": 0,
      "8": 19,
      "9": 99,
      "10": 232,
      "11": 3
    }
  }
}
````