BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
marlo84
Calcite | Level 5

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
}

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
marlo84
Calcite | Level 5

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;

View solution in original post

1 REPLY 1
marlo84
Calcite | Level 5

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;

SAS Innovate 2025: Register Now

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!

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
  • 1 reply
  • 1612 views
  • 0 likes
  • 1 in conversation