BookmarkSubscribeRSS Feed
Amulraj
Fluorite | Level 6

I created client id and password following the steps mentioned in the below blog

https://blogs.sas.com/content/sgf/2023/02/07/authentication-to-sas-viya/

 

After generating the access token ran a sas api to run a job definition 

import http.client

conn = http.client.HTTPConnection("example.com")

payload = "{\n  \"name\": \"proc print example\",\n  \"description\": \"ods output with age 14 cutoff\",\n  \"jobDefinitionUri\": \"/jobDefinitions/definitions/2cbe5f60-1391-42db-a857-271e83eb7e48\",\n  \"arguments\": {\n    \"AGE\": \"14\"\n  }\n}"

headers = {
    'Delegate-Domain': "",
    'Content-Type': "application/json",
    'Authorization': "Bearer <access-token-goes-here>",
    'Accept': "application/json, application/vnd.sas.job.execution.job+json, application/vnd.sas.error+json"
}

conn.request("POST", "/jobExecution/jobs", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))

The output i recieved is 

{
  "version": 2,
  "httpstatusCode": 500,
  "errorCode": 30081,
  "message": "Invalid user: \"clientid\"",
  "details": [
    "traceId: cf313c5d4b62431f",
    "path: /launcher/processes",
    "path: /compute/contexts/8c3023b8-9fe1-4b4b-ba67-7ced166e9b49/sessions",
    "correlator: 531e7c41-d3d9-48ed-86e6-bdce959e48d7"
  ]
}

 Details of the job definition 

proc print data=sashelp.iris (obs=&n_rows);
        title "First &n_rows Rows of the Iris Dataset";
    run;

When i create access token using sas user id and password, the job request executes successfully.  But the request gets failed while using auth token of client id. What necessary Authorization should be given to client id to run a job in compute.

 

5 REPLIES 5
joeFurbee
Community Manager

Hi @Amulraj,

Please reference the steps in this Jupyter notebook to create the client id that will include the proper credentials to generate a valid access and refresh token. You'll need to have admin rights when creating the client id. Also in that repository there is an example end-to-end use case for job creation and execution. The scripts are available for Postman, Python, and R.


Join us for SAS Community Trivia
SAS Bowl XLVII, SAS Visual Text Analytics
Wednesday, December 18, 2024, at 10:30 a.m. ET | #SASBowl

Amulraj
Fluorite | Level 6

Hi @joeFurbee ,

 

I performed the same activity as mentioned in the notebook using sasboot to create client id, job definition. while executing the job definition as a job request  using the access token from the client id generated ,  i am getting the following error in postman

"error": {
"errosCode:30154,
"message": "Failed to retrieve identifier information user: \"@currentUser\"",
"details":[
"traceld: 50df36fa9c78627b",
"path: /launcher/processes",
"path: /compute/contexts/8c3023b8-9fel-4b4b-ba67-7ced166e9b49/sessions",
"correlator: 09429966-83c0-41b2-6383-3d0b49672e7d;lle006aa-92e9-471c-blbd-bcbcff7cd9f1"
"errors":[
{
"errorCode": 10500,
"message": "The identifier values for USER \"sasboot\" were not found.",
"detail": [
"traceld: 504f36fa9c78627b",
"path: /identities/users/@currentUser/identifier"
]
"httpStatusCode": 404

What can be the solution to run the job using the client id authenticated by sasboot or are there any alternative 

joeFurbee
Community Manager

Hi @Amulraj,

sasboot is a pre-existing client id. You need to create a NEW client id that is unique. In the first cell of the Jupyter notebook use something like the following to create variables for the client id and secret.

import requests
import json
import os
import base64

# PLEASE SET OR CREATE the following variables BEFORE YOU EXECUTE THE FOLLOWING CELLS
# The client_id and client_secret values are up to you
# The client is either an application or acts on behalf of a user when making API calls
client_id="api.client"     # api.client
client_secret="api.secret" # api.secret
baseURL = ""     # https://sasserver.sas.com

You can use any values for the client_id and client_secret variables, but they cannot already exist. Note, you'll also need to add a baseURL value, which is your SAS Viya server URL. Once you've created these variables, you should be able to run through the rest of the notebook, following the prompts to generate the access token to create the client id and generate the access token for the REST call, without further adjustments to the code.


Join us for SAS Community Trivia
SAS Bowl XLVII, SAS Visual Text Analytics
Wednesday, December 18, 2024, at 10:30 a.m. ET | #SASBowl

Amulraj
Fluorite | Level 6

Hi @joeFurbee ,

 

Yes i created a new client id  named sas1 and for the Authorization code step i logged in through sasboot 

joeFurbee
Community Manager

Hi @Amulraj,

We may have to walk through this together to see if we can identify the issue. Let me know if this is acceptable and I'll set up a meeting.


Join us for SAS Community Trivia
SAS Bowl XLVII, SAS Visual Text Analytics
Wednesday, December 18, 2024, at 10:30 a.m. ET | #SASBowl

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 856 views
  • 0 likes
  • 2 in conversation