SAS Viya REST APIs let developers and enterprise applications create, access, and manage SAS resources programmatically using any client technology. They make it possible to work with Visual Analytics reports by retrieving data, exporting content, and automating tasks without relying solely on the Visual Analytics user interface.
REST APIs offer great flexibility, but many SAS users are more comfortable working directly in SAS Studio. To bridge that gap, this article translates five commonly used SAS Visual Analytics REST APIs into ready-to-use SAS Studio programs built with PROC HTTP. The goal is to give customers and internal teams a practical, low-barrier starting point for automating report retrieval and export tasks, without needing deep REST API expertise.
This article is written for readers who may not have a technical background in REST APIs. Each section explains not just what a program does, but why it works the way it does, so you can adapt these examples with confidence.
If you're new to REST APIs, it helps to think of one like ordering at a restaurant. You, the client, do not need to know how the kitchen works; you just need to know how to ask for what you want using a shared menu of requests. SAS Viya's REST APIs work the same way: your SAS Studio program asks a SAS Viya service for something, and the service responds.
Every request uses one of a small set of standard actions, called HTTP methods:
Because all five programs in this article use GET, they are read-only: they retrieve or export information but never change anything in your SAS Viya environment. This makes them safe to test and learn with.
A typical REST API request has four parts:
SAS Viya's REST APIs are also link-driven, meaning many responses include links to related resources or next actions. You do not need to memorize every possible URL; once you retrieve a resource, its response often tells you where to go next.
Using these REST APIs through SAS Studio programs offers several advantages:
Before using the programs described in this article, confirm the following:
This article covers five commonly used APIs from the Visualization and Reports category of the SAS REST API catalog, available at developer.sas.com/rest-apis. Each API below has a corresponding SAS Studio program that authenticates, calls the API, and returns the result. For each one, this article explains the endpoint, what happens step by step, what you need to provide, when to use it, and what you get back.
|
HTTP Method |
GET |
|
Endpoint |
GET /reports/&report_id/package |
|
Purpose |
Exports a report, or selected report objects, as a compressed ZIP package. The package contains the report source files, data query results, and rendered images — everything needed to view the report remotely without a live connection back to the original environment. |
|
Link |
https://developer.sas.com/rest-apis/visualAnalytics/getExportedReportPackage
|
How it works, step by step
What you need to provide (inputs)
When to use it
What you get back (output)
A binary ZIP file (application/zip) containing the report package. It is not human-readable JSON; it is meant to be saved and opened later or moved to another SAS Viya environment.
Sample SAS Code Snippet
|
HTTP Method |
GET |
|
Endpoint |
GET /reports/&report_id/pdf |
|
Purpose |
Exports a Visual Analytics report as a PDF document. The connection stays open while the PDF is generated, which can take some time for larger reports. Query parameters can override the rendering service's defaults and any export defaults saved with the report itself. |
|
Link |
https://developer.sas.com/rest-apis/visualAnalytics/getExportedReportPdf |
How it works, step by step
What you need to provide (inputs)
When to use it
What you get back (output)
A binary PDF file (application/pdf), ready to save, print, email, or archive.
Sample SAS Code Snippet
|
HTTP Method |
GET |
|
Endpoint |
GET /reports/&report_id/png |
|
Purpose |
Exports a report, or part of a report, as a PNG image. The image format returned is controlled by the Accept header of the request. |
|
Link |
https://developer.sas.com/rest-apis/visualAnalytics/getExportedReportImagePNG |
How it works, step by step
What you need to provide (inputs)
When to use it
What you get back (output)
A binary PNG image, ready to embed, email, or display.
Sample SAS Code Snippet
Note: Confirm the exact Accept header value against the current SAS REST API documentation for your Viya release, as header formats can change between versions.
|
HTTP Method |
GET |
|
Endpoint |
GET /reports/&report_id |
|
Purpose |
Retrieves the specified report, including metadata such as report name, ID, creation date, owner, and last-modified date. |
|
Link |
How it works, step by step
What you need to provide (inputs)
When to use it
What you get back (output)
A JSON response describing the report: its unique ID, name, who created it, when it was created and last modified, and links to related resources.
Sample SAS Code Snippet
Illustrative Sample Output
Field names and values below are illustrative only, to show the shape of the response — your actual output will reflect your own report.
|
{ "id": "12345-abcde-67890", "name": "Sales Performance", "createdBy": "analyst_user", "creationTimeStamp": "2026-05-04T09:15:00Z", "modifiedTimeStamp": "2026-05-04T09:45:00Z", "links": [ { "rel": "self", "href": "/reports/reports/12345-abcde-67890" } ] } |
|
HTTP Method |
GET |
|
Endpoint |
GET /reports/&report_id/content |
|
Purpose |
Retrieves the detailed content of a report, including objects, layouts, visual elements, and data bindings — essentially the structure that makes up the report. |
|
Link |
How it works, step by step
What you need to provide (inputs)
When to use it
What you get back (output)
A JSON response describing the report's internal structure: its sections, visual objects, layout definitions, and the data each object is bound to.
Sample SAS Code Snippet
Illustrative Sample Output
Field names and values below are illustrative only, to show the shape of the response — your actual output will reflect your own report.
|
{ "reportId": "12345-abcde-67890", "sections": [ { "name": "Overview", "objects": [ "Bar Chart 1", "KPI Tile 1" ] } ], "dataBindings": [ { "object": "Bar Chart 1", "dataSource": "SALES_TABLE" } ] } |
SAS Viya REST APIs use OAuth2 access tokens. In the SAS Studio examples in this article, the programs use the SAS_SERVICES oauth_bearer, which uses the current SAS Studio login session to generate an access token automatically. This token is then included as a Bearer token in the Authorization header of each REST API request. Without a valid token, calls fail with a 401 Unauthorized error.
Why use SAS_SERVICES?
At a high level, the flow looks like this:
Figure: Using SAS_SERVICES to request a token
The program uses SAS_SERVICES to obtain an access token from the current SAS Studio login session, so no separate authentication details need to be added to the code.
If a program doesn't behave as expected, the HTTP status code returned in the response is usually the fastest way to diagnose why. REST APIs use standard, well-known status codes, so learning to recognize a handful of them will get you a long way:
|
Status / Error |
What It Means |
Likely Cause |
Suggested Action |
|
200 OK |
Success |
Request succeeded. |
No action needed. |
|
201 Created |
Success, resource created |
A create/POST operation succeeded. |
No action needed (not applicable to the GET-only programs in this article). |
|
204 No Content |
Success, empty response |
Request succeeded but returned no body. |
No action needed; confirm this is expected for the call. |
|
401 Unauthorized |
Not authenticated |
Token missing, invalid, or expired. |
Refresh the SAS Studio session, request a new token through SAS_SERVICES, and retry. |
|
403 Forbidden |
Not authorized |
User lacks permission for the report. |
Check report access permissions with your admin. |
|
404 Not Found |
Resource not found |
Incorrect report ID or URL. |
Verify the report ID and base URL. |
|
409 / 412 |
Conflict |
Update conflict or conditional header (ETag) mismatch. |
Refresh the resource and retry the request. |
|
SSL / Certificate error |
Connection not trusted |
Trust chain issue with the environment's certificate. |
Check with your admin about the environment's certificate setup. |
|
Timeout |
No response in time |
Large export (for example, a large PDF or package). |
Increase the client timeout and retry. |
A few general troubleshooting habits that help regardless of the specific error:
Because these programs use access tokens generated from the current SAS Studio session, treat tokens with the same care you would any other sensitive credential. A leaked token can be used by anyone to act as you within the token's lifetime and permissions.
Important Disclaimer
These examples are intended for general guidance. For complex applications, review the SAS Help Center for detailed documentation.
The source code is available in the https://gitlab.sas.com/techsupport/technical-support-code/-/tree/main/usage/programming/sas-visual-a... project.
Visit the Tips & Tricks page for setup guidance, demos, and practical examples that show how Copilot supports your workflows.
The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.