# Class SASViyaApiClient

A client for interfacing with the SAS Viya REST API.

### Hierarchy

- SASViyaApiClient

### Constructors

- constructor

### Methods

- createContext
- createFolder
- createJobDefinition
- createSession
- deleteClient
- deleteContext
- deleteFolder
- editContext
- executeComputeJob
- executeJob
- executeScript
- getAccessToken
- getAllContexts
- getAuthCode
- getComputeContextByName
- getConfig
- getExecutableContexts
- getJobsInFolder
- moveFolder
- refreshTokens
- setConfig
- setCsrfTokenLocal
- setFileUploadCsrfToken

## Constructors

### constructor

- new SASViyaApiClient(serverUrl: string, rootFolderName: string, contextName: string, setCsrfToken: function): SASViyaApiClient

- - Defined in SASViyaApiClient.ts:28

  #### Parameters

  - ##### serverUrl: string

  - ##### rootFolderName: string

  - ##### contextName: string

  - ##### setCsrfToken: function

    - - (csrfToken: CsrfToken ): void

      - #### Parameters

        - ##### csrfToken: CsrfToken

        #### Returns void

  #### Returns SASViyaApiClient

## Methods

### createContext

- createContext(contextName: string, launchContextName: string, sharedAccountId: string, autoExecLines: string[], authorizedUsers: string[], accessToken?: undefined | string): Promise< Context >

- - Defined in SASViyaApiClient.ts:230

  Creates a compute context on the given server.

  #### Parameters

  - ##### contextName: string

    the name of the context to be created.

  - ##### launchContextName: string

    the name of the launcher context used by the compute service.

  - ##### sharedAccountId: string

    the ID of the account to run the servers for this context.

  - ##### autoExecLines: string[]

    the lines of code to execute during session initialization.

  - ##### authorizedUsers: string[]

    an optional list of authorized user IDs.

  - ##### Optional accessToken: undefined | string

    an access token for an authorized user.

  #### Returns Promise< Context >

### createFolder

- createFolder(folderName: string, parentFolderPath?: undefined | string, parentFolderUri?: undefined | string, accessToken?: undefined | string, isForced?: undefined | false | true): Promise< Folder >

- - Defined in SASViyaApiClient.ts:601

  Creates a folder. Path to or URI of the parent folder is required.

  #### Parameters

  - ##### folderName: string

    the name of the new folder.

  - ##### Optional parentFolderPath: undefined | string

    the full path to the parent folder. If not provided, the parentFolderUri must be provided.

  - ##### Optional parentFolderUri: undefined | string

    the URI (eg /folders/folders/UUID) of the parent folder. If not provided, the parentFolderPath must be provided.

  - ##### Optional accessToken: undefined | string

    an access token for authorizing the request.

  - ##### Optional isForced: undefined | false | true

    flag that indicates if target folder already exists, it and all subfolders have to be deleted.

  #### Returns Promise< Folder >

### createJobDefinition

- createJobDefinition(jobName: string, code: string, parentFolderPath?: undefined | string, parentFolderUri?: undefined | string, accessToken?: undefined | string): Promise<object>

- - Defined in SASViyaApiClient.ts:710

  Creates a Job in the specified folder (or folder uri).

  #### Parameters

  - ##### jobName: string

    the name of the new job to be created.

  - ##### code: string

    the SAS code for the new job.

  - ##### Optional parentFolderPath: undefined | string

    the location of the new job.

  - ##### Optional parentFolderUri: undefined | string

    the URI location of the new job. The function is a little faster if the folder URI is supplied instead of the path.

  - ##### Optional accessToken: undefined | string

  #### Returns Promise<object>

### createSession

- createSession(contextName: string, accessToken?: undefined | string): Promise< Session >

- - Defined in SASViyaApiClient.ts:185

  Creates a session on the given context.

  #### Parameters

  - ##### contextName: string

    the name of the context to create a session on.

  - ##### Optional accessToken: undefined | string

    an access token for an authorized user.

  #### Returns Promise< Session >

### deleteClient

- deleteClient(clientId: string, accessToken?: undefined | string): Promise<object>

- - Defined in SASViyaApiClient.ts:897

  Deletes the client representing the supplied ID.

  #### Parameters

  - ##### clientId: string

    the client ID to authenticate with.

  - ##### Optional accessToken: undefined | string

    an access token for authorizing the request.

  #### Returns Promise<object>

### deleteContext

- deleteContext(contextName: string, accessToken?: undefined | string): Promise<object>

- - Defined in SASViyaApiClient.ts:362

  Deletes a compute context on the given server.

  #### Parameters

  - ##### contextName: string

    the name of the context to be deleted.

  - ##### Optional accessToken: undefined | string

    an access token for an authorized user.

  #### Returns Promise<object>

### deleteFolder

- deleteFolder(folderPath: string, accessToken: string): Promise<undefined | Folder >

- - Defined in SASViyaApiClient.ts:1480

  For performance (and in case of accidental error) the `deleteFolder` function does not actually delete the folder (and all its content and subfolder content). Instead the folder is simply moved to the recycle bin. Deletion time will be added to the folder name.

  #### Parameters

  - ##### folderPath: string

    the full path (eg `/Public/example/deleteThis`) of the folder to be deleted.

  - ##### accessToken: string

    an access token for authorizing the request.

  #### Returns Promise<undefined | Folder >

### editContext

- editContext(contextName: string, editedContext: EditContextInput, accessToken?: undefined | string): Promise<object>

- - Defined in SASViyaApiClient.ts:299

  Updates a compute context on the given server.

  #### Parameters

  - ##### contextName: string

    the original name of the context to be updated.

  - ##### editedContext: EditContextInput

    an object with the properties to be updated.

  - ##### Optional accessToken: undefined | string

    an access token for an authorized user.

  #### Returns Promise<object>

### executeComputeJob

- executeComputeJob(sasJob: string, contextName: string, debug: boolean, data?: any, accessToken?: undefined | string): Promise<any>

- - Defined in SASViyaApiClient.ts:920

  Executes a job via the SAS Viya Compute API.

  #### Parameters

  - ##### sasJob: string

    the relative path to the job.

  - ##### contextName: string

    the name of the context where the job is to be executed.

  - ##### debug: boolean

    sets the _debug flag in the job arguments.

  - ##### Optional data: any

    any data to be passed in as input to the job.

  - ##### Optional accessToken: undefined | string

    an optional access token for an authorized user.

  #### Returns Promise<any>

### executeJob

- executeJob(sasJob: string, contextName: string, debug: boolean, data?: any, accessToken?: undefined | string): Promise<object>

- - Defined in SASViyaApiClient.ts:1017

  Executes a job via the SAS Viya Job Execution API

  #### Parameters

  - ##### sasJob: string

    the relative or absolute path to the job.

  - ##### contextName: string

    the name of the context where the job is to be executed.

  - ##### debug: boolean

    sets the _debug flag in the job arguments.

  - ##### Optional data: any

    any data to be passed in as input to the job.

  - ##### Optional accessToken: undefined | string

    an optional access token for an authorized user.

  #### Returns Promise<object>

### executeScript

- executeScript(jobPath: string, linesOfCode: string[], contextName: string, accessToken?: undefined | string, silent?: boolean, data?: null, debug?: boolean, expectWebout?: boolean): Promise<any>

- - Defined in SASViyaApiClient.ts:400

  Executes code on the current SAS Viya server.

  #### Parameters

  - ##### jobPath: string

    the path to the file being submitted for execution.

  - ##### linesOfCode: string[]

    an array of code lines to execute.

  - ##### contextName: string

    the context to execute the code in.

  - ##### Optional accessToken: undefined | string

    an access token for an authorized user.

  - ##### Default value silent: boolean = false

    optional flag to disable logging.

  - ##### Default value data: null = null

    execution data.

  - ##### Default value debug: boolean = false

    when set to true, the log will be returned.

  - ##### Default value expectWebout: boolean = false

    when set to true, the automatic _webout fileref will be checked for content, and that content returned. This fileref is used when the Job contains a SASjs web request (as opposed to executing arbitrary SAS code).

  #### Returns Promise<any>

### getAccessToken

- getAccessToken(clientId: string, clientSecret: string, authCode: string): Promise<any>

- - Defined in SASViyaApiClient.ts:810

  Exchanges the auth code for an access token for the given client.

  #### Parameters

  - ##### clientId: string

    the client ID to authenticate with.

  - ##### clientSecret: string

    the client secret to authenticate with.

  - ##### authCode: string

    the auth code received from the server.

  #### Returns Promise<any>

### getAllContexts

- getAllContexts(accessToken?: undefined | string): Promise<object[]>

- - Defined in SASViyaApiClient.ts:87

  Returns all available compute contexts on this server.

  #### Parameters

  - ##### Optional accessToken: undefined | string

    an access token for an authorized user.

  #### Returns Promise<object[]>

### getAuthCode

- getAuthCode(clientId: string): Promise<null | string>

- - Defined in SASViyaApiClient.ts:762

  Performs a login redirect and returns an auth code for the given client.

  #### Parameters

  - ##### clientId: string

    the client ID to authenticate with.

  #### Returns Promise<null | string>

### getComputeContextByName

- getComputeContextByName(contextName: string, accessToken?: undefined | string): Promise< Context >

- - Defined in SASViyaApiClient.ts:1396

  Returns a JSON representation of a compute context.

  example:

    { "createdBy": "admin", "links": [...], "id": "ID", "version": 2, "name": "context1" }

  #### Parameters

  - ##### contextName: string

    the name of the context to return.

  - ##### Optional accessToken: undefined | string

    an access token for an authorized user.

  #### Returns Promise< Context >

### getConfig

- getConfig(): object

- - Defined in SASViyaApiClient.ts:66

  Returns an object containing the server URL and root folder name.

  #### Returns object

  - ##### rootFolderName: string

  - ##### serverUrl: string

### getExecutableContexts

- getExecutableContexts(accessToken?: undefined | string): Promise<any[]>

- - Defined in SASViyaApiClient.ts:116

  Returns all compute contexts on this server that the user has access to.

  #### Parameters

  - ##### Optional accessToken: undefined | string

    an access token for an authorized user.

  #### Returns Promise<any[]>

### getJobsInFolder

- getJobsInFolder(folderPath: string): Promise<undefined | Job []>

- - Defined in SASViyaApiClient.ts:51

  Returns a list of jobs in the currently set root folder.

  #### Parameters

  - ##### folderPath: string

  #### Returns Promise<undefined | Job []>

### moveFolder

- moveFolder(sourceFolder: string, targetParentFolder: string, targetFolderName: string, accessToken: string): Promise<undefined | Folder >

- - Defined in SASViyaApiClient.ts:1431

  Moves a Viya folder to a new location. The folder may be renamed at the same time.

  #### Parameters

  - ##### sourceFolder: string

    the full path (eg `/Public/example/myFolder`) or URI of the source folder to be moved. Providing URI instead of path will save one extra request.

  - ##### targetParentFolder: string

    the full path or URI of the parent folder to which the `sourceFolder` will be moved (eg `/Public/newDestination`). To move a folder, a user has to have write permissions in targetParentFolder. Providing URI instead of path will save one extra request.

  - ##### targetFolderName: string

    the name of the "moved" folder. If left blank, the original folder name will be used (eg `myFolder` in `/Public/newDestination/myFolder` for the example above). Optional field.

  - ##### accessToken: string

    an access token for authorizing the request.

  #### Returns Promise<undefined | Folder >

### refreshTokens

- refreshTokens(clientId: string, clientSecret: string, refreshToken: string): Promise<any>

- - Defined in SASViyaApiClient.ts:854

  Exchanges the refresh token for an access token for the given client.

  #### Parameters

  - ##### clientId: string

    the client ID to authenticate with.

  - ##### clientSecret: string

    the client secret to authenticate with.

  - ##### refreshToken: string

  #### Returns Promise<any>

### setConfig

- setConfig(serverUrl: string, rootFolderName: string): void

- - Defined in SASViyaApiClient.ts:78

  Updates server URL and root folder name, if it was not set.

  #### Parameters

  - ##### serverUrl: string

    the URL of the server.

  - ##### rootFolderName: string

    the name for root folder.

  #### Returns void

### setCsrfTokenLocal

- setCsrfTokenLocal(csrfToken: CsrfToken ): void

- - Defined in SASViyaApiClient.ts:1497

  #### Parameters

  - ##### csrfToken: CsrfToken

  #### Returns void

### setFileUploadCsrfToken

- setFileUploadCsrfToken(csrfToken: CsrfToken ): void

- - Defined in SASViyaApiClient.ts:1502

  #### Parameters

  - ##### csrfToken: CsrfToken

  #### Returns void

Generated using TypeDoc