Hello SAS community,
I am trying to create folder authorization rules with PROC HTTP by requesting the SAS Viya REST API. But I keep getting a '400 Bad Request'. My reference source is a Python script - link.
I can create folders and usergroups with the REST API.
How can I get this patch request working without Pyhton or CLI?
%let base_url = https://%scan(&_baseurl.,2,"/"); %put &base_url.; filename input temp; filename output temp ; filename header temp; proc stream outfile=input; begin &streamdelim; [ { "op":"add", "value": { "description": "test", "objectUri":"/folders/folders/c7496325-eabf-474b-a499-e9de0ae5a6a1", "permissions":["read", "update","secure","add","remove"], "principalType":"group", "principal":"test", "type":"grant" } }, { "op":"add", "value": { "description": "test", "containerUri":"/folders/folders/c7496325-eabf-474b-a499-e9de0ae5a6a1", "permissions":["read", "update","delete","add","remove"], "principalType":"group", "principal":"test", "type":"grant" } } ] ;;;; proc http url="&base_url/authorization/rules" oauth_bearer=sas_services out=output in=input headerout=header method=patch; debug level = 2; headers "Accept"="application/vnd.sas.collection+json" "Content-Type"="application/json-patch+json"; run;
response:
{ "errorCode": 0, "message": "Unable to parse valid patch operations from provided patch.", "details": [ "traceId: 0c972600186e4596", "path: /authorization/rules" ], "links": [], "version": 2, "httpStatusCode": 400 }
found the solution, had to add "path": "/authorization/rules/" to the json input. it is working now:
%let base_url = https://%scan(&_baseurl.,2,"/");
%put &base_url.;
filename input temp ;
filename output temp ;
filename header temp;
proc stream outfile=input; begin &streamdelim;
[
{
"op": "add",
"path": "/authorization/rules/",
"value": {
"description": "test",
"objectUri": "/folders/folders/c7496325-eabf-474b-a499-e9de0ae5a6a1",
"permissions": [
"read",
"update",
"add",
"remove"
],
"principalType": "group",
"principal": "test",
"type": "grant"
}
},
{
"op": "add",
"path": "/authorization/rules/",
"value": {
"description": "test",
"containerUri": "/folders/folders/c7496325-eabf-474b-a499-e9de0ae5a6a1",
"permissions": [
"read",
"update",
"add",
"remove",
"delete"
],
"principalType": "group",
"principal": "test",
"type": "grant"
}
}
]
;;;;
proc http url="&base_url/authorization/rules"
oauth_bearer=sas_services
out=output
in=input
headerout=header
method=patch;
debug level = 2;
headers
"Accept"="application/vnd.sas.collection+json"
"Content-Type"="application/json-patch+json";
run;
found the solution, had to add "path": "/authorization/rules/" to the json input. it is working now:
%let base_url = https://%scan(&_baseurl.,2,"/");
%put &base_url.;
filename input temp ;
filename output temp ;
filename header temp;
proc stream outfile=input; begin &streamdelim;
[
{
"op": "add",
"path": "/authorization/rules/",
"value": {
"description": "test",
"objectUri": "/folders/folders/c7496325-eabf-474b-a499-e9de0ae5a6a1",
"permissions": [
"read",
"update",
"add",
"remove"
],
"principalType": "group",
"principal": "test",
"type": "grant"
}
},
{
"op": "add",
"path": "/authorization/rules/",
"value": {
"description": "test",
"containerUri": "/folders/folders/c7496325-eabf-474b-a499-e9de0ae5a6a1",
"permissions": [
"read",
"update",
"add",
"remove",
"delete"
],
"principalType": "group",
"principal": "test",
"type": "grant"
}
}
]
;;;;
proc http url="&base_url/authorization/rules"
oauth_bearer=sas_services
out=output
in=input
headerout=header
method=patch;
debug level = 2;
headers
"Accept"="application/vnd.sas.collection+json"
"Content-Type"="application/json-patch+json";
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.