Main Content


Change token of REST function connector

Since R2024a


    changeToken(conn) generates a new personal access token and updates the RESTPersonalAccessToken property of the connector conn. The default lifetime of the token is 30 days. The function also updates the TokenExpirationDate property to the expiration date of the newly generated token. When you generate a new token, the function overwrites the existing token which becomes invalid.

    The token is not lost or invalidated due to a machine crash or shutdown. For more information, see Tokens.


    You must not share tokens with other users in keeping with your license agreement. Protecting the token is important to ensure that only you are able to execute functions on your MATLAB® and not other users with access to your machine.


    changeToken(conn,days) specifies the number of days for the new token to remain valid.


    collapse all

    First, get a REST function connector. Stop the existing connection.

    conn = restFunctionConnector;
    conn.ClientAccessMode = remote;

    Generate a new personal access token, specifying its valid timespan as 45 days. The TokenExpirationDate value indicates that you made the change 45 days earlier, on October 20, 2023.

    conn = 
      RESTFunctionConnector with properties: 
                                 Port: 9920 
                          LogLocation: "<mwPath>\restfcnconnector\logs" 
                             HostName: "" 
                     ClientAccessMode: remote 
                         ServiceNames: 1x0 string 
              RESTPersonalAccessToken: "QADIABUGwBgJCgsMDQ4PEBESExQVFhcYGRobHB0eBcD=" 
                  TokenExpirationDate: 04-Dec-2023 
                          Certificate: "<mwPath>\restfcnconnector\publickey.pem" 
            CertificateExpirationDate: 20-Sep-2023 
                              BaseUrl: "" 
                               Status: notrunning

    Input Arguments

    collapse all

    The REST function connector, specified as a RESTFunctionConnector object.

    Number of days for the token to remain valid, specified as a scalar from 1 to 365 or a duration type.

    Data Types: double | duration

    Version History

    Introduced in R2024a