BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
idziemianczyk
Obsidian | Level 7

Hello community,

 

We need to automate the process of a copying of existing jobs "Job Definition" .

The information I found is very limited:

1. Using CLI

For CLI SAS Help Center: Scheduling Command Line Interface

I'm able to create a new jobDefinitions file using CLI

 

sas-admin.exe -k job definitions create --file-in "<path>\template.txt"

the content of template file:

{
"name": "New Job",
"type": "jobDefinition",
"code": ""
}

 

The JobDefinition is created, but I don't understand how I can use it. There is no information about parentFolder and I can't reuse it in the Environment Manager.

 

2. Using REST API

I found this piece of code Compute – Visualization API Reference (sas.com)

I haven't tried it, but it seems to be similar to the CLI. I don't have parentFolderURI and can't process it.

 

Could you please help me to understand what is wrong and what steps should be done to copy existing Job1 to a new Job2 using REST API or CLI?

 

Thanks in advance,

Ivan

1 ACCEPTED SOLUTION

Accepted Solutions
gwootton
SAS Super FREQ

I was able to create the jobDefinition in a folder by sending a POST containing the example job definition from developer.sas.com:

{
  "version":2,
  "name":"Simple proc print",
  "description":"Show the contents of sashelp.class using PROC PRINT",
  "type":"Compute",
  "parameters":[
        {
        "version": 1,
        "name": "_contextName",
        "defaultValue": "SAS Job Execution compute context",
        "type": "CHARACTER",
        "label": "Context Name",
        "required": false
    }
  ],
  "code":"ods html style=HTMLBlue;\nproc print data=sashelp.class; run; quit;\nods html close;"
}

  to {{baseurl}}/jobDefinitions/definitions?parentFolderUri=/folders/folders/a3c382dc-0de3-41d1-9e96-a3c7c20ab23c (this is the URI of a folder in My Folder) along with my bearer token in the header and it created successfully.

 

gwootton_0-1613500774261.png

--
Greg Wootton | Principal Systems Technical Support Engineer

View solution in original post

7 REPLIES 7
gwootton
SAS Super FREQ

You need to also create a jobRequest, that is what is displayed in Environment Manager's schedule list:

 

In the CLI:

https://go.documentation.sas.com/?cdcId=calcdc&cdcVersion=3.5&docsetId=caljobs&docsetTarget=p1g6z2wn...

In the REST API:

https://developer.sas.com/apis/rest/v3.5/Compute/#create-a-job-request

 

 

 

--
Greg Wootton | Principal Systems Technical Support Engineer
idziemianczyk
Obsidian | Level 7

I can create JobDefinition and then JobExecution, I can see the job using rest API query

GET https://<servername>/jobDefinitions/definitions?filter=eq(name,'<jobname>')

 

but I can't see the job in the Env Manager. No wonder, there are no parentFolderUri parameter in query and body parameter. 

 

When I try to add parentFolderUri 

https://pvmict002.health.fgov.be/jobDefinitions/definitions?parentFolderUri=/folders/folders/cc993804-82e2-477c-ad4e-d5039a441554

 

I have error: 

Unable to add job definition to parent folder. Http status: 403.

 

I didn't find any "working" example of creation and reusing JobDefinition and JobExecution with folders. Do you have any ideas how to set the parentFolderUri for the jobs? 

gwootton
SAS Super FREQ
Do you have permission to write to that folder? Are you creating a new definition or trying to modify your existing one?
https://developer.sas.com/apis/rest/v3.5/Compute/#create-a-job-definition
https://developer.sas.com/apis/rest/v3.5/Compute/#update-a-job-definition
--
Greg Wootton | Principal Systems Technical Support Engineer
idziemianczyk
Obsidian | Level 7

Do you have permission to write to that folder?

- I have the permission to modify the folder. 

 

Are you creating a new definition or trying to modify your existing one?

- I created a new one. It looks OK but there is no link to any folder. I suppose this is the reason why I can't find the job in Env Manager. 

 

dandycomp_1-1613496529438.png

 

dandycomp_2-1613496546828.png

 

 

 

 

gwootton
SAS Super FREQ

I was able to create the jobDefinition in a folder by sending a POST containing the example job definition from developer.sas.com:

{
  "version":2,
  "name":"Simple proc print",
  "description":"Show the contents of sashelp.class using PROC PRINT",
  "type":"Compute",
  "parameters":[
        {
        "version": 1,
        "name": "_contextName",
        "defaultValue": "SAS Job Execution compute context",
        "type": "CHARACTER",
        "label": "Context Name",
        "required": false
    }
  ],
  "code":"ods html style=HTMLBlue;\nproc print data=sashelp.class; run; quit;\nods html close;"
}

  to {{baseurl}}/jobDefinitions/definitions?parentFolderUri=/folders/folders/a3c382dc-0de3-41d1-9e96-a3c7c20ab23c (this is the URI of a folder in My Folder) along with my bearer token in the header and it created successfully.

 

gwootton_0-1613500774261.png

--
Greg Wootton | Principal Systems Technical Support Engineer
idziemianczyk
Obsidian | Level 7

I tested and it works for "MyFolder" too 🙂 

 

The strange thing it doesn't work for another folder(from my example). User assigned to group with write access(tested the same steps with ENV manager and JobExecution and the user can create a job).

 

Anyway, the good news we know that query is ok and I need to solve credential problems issue. Thanks a lot for the help.   

gwootton
SAS Super FREQ
This probably has to do with the scope of the client being used when you get your bearer token. If the scope isn't * or specifies the group granting permission to the folder, it won't be included in the token, so permissions honored will only be those directly assigned to the user (like those of My Folder).
--
Greg Wootton | Principal Systems Technical Support Engineer

suga badge.PNGThe SAS Users Group for Administrators (SUGA) is open to all SAS administrators and architects who install, update, manage or maintain a SAS deployment. 

Join SUGA 

Get Started with SAS Information Catalog in SAS Viya

SAS technical trainer Erin Winters shows you how to explore assets, create new data discovery agents, schedule data discovery agents, and much more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 7 replies
  • 2193 views
  • 2 likes
  • 2 in conversation