stratoCumulus
Contributor
Contributor

vRA 8.6.1 - Approval API

Jump to solution

Hi, I'm trying to access all approvals via REST API. I'm getting a 200 response but the content is empty, even though I have pending approvals.

I've been accessing other API's such as iaas successfully like this so I'm wondering what I'm doing wrong with approvals? Is my path correct? Do I need additional parameters? I get the same response whether or not I use a trailing / in the pathUri.  I'm thinking I should see content like swagger shows examples of in between the brackets of "content":[] in the response?

I'm using the vRA:Host plugin: 

// Get approval details
var pathUri = "/approval/api/approvals" 
var restClient = vRAHost.createRestClient();
var request = restClient.createRequest("GET", pathUri, null);
var response = restClient.execute(request);
// Result
var statusCode = response.statusCode;
var contentAsString = response.contentAsString;
log("statusCode: " + statusCode);
log("contentAsString: " + contentAsString);

and getting a response back (I would parse later):
 
statusCode: 200
contentAsString: {"content":[],"pageable":{"offset":0,"sort":{"sorted":false,"unsorted":true,"empty":true},"queryInfo":{"customOptions":{},"expand":[],"select":[],"properties":[],"sort":{"sorted":false,"unsorted":true,"empty":true}},"pageNumber":0,"pageSize":20,"unpaged":false,"paged":true},"last":true,"totalPages":0,"totalElements":0,"sort":{"sorted":false,"unsorted":true,"empty":true},"first":true,"number":0,"numberOfElements":0,"size":20,"empty":true}

 Thanks

Labels (6)
0 Kudos
1 Solution

Accepted Solutions
xian_
Expert
Expert

If you use the vRA plugin, you need an endpoint created with the user account you wish to approve by. You can dynamically create it with VraHostManager.createHost or create it beforehand, if you want to use an API user to approve (that's what I recommend, see the blog post).

If you use the REST endpoint, you need to authenticate with the user account you wish to approve by, to get the appropriate token. You need the password stored somewhere, so the first method is more secure (one cannot print the password).

 

View solution in original post

4 Replies
xian_
Expert
Expert

You need to use the approver's token.

0 Kudos
stratoCumulus
Contributor
Contributor

Could you explain how to include that in the REST request? I'm using a similar process to this link you sent:

https://kuklis.github.io/cma/post/vra8-servicenow-approval/ 

I'm using the vRA plugin for my REST operations. FullType: VRA:Host and pointing to my vraHost, similar to how the above link has their "vra-snow" resource set up, except I'm using vro-integration as the user. This has worked for all other API calls such as iaas. 

My rest request seems very similar to what is in the link as well, though they do leave some details out. Are you saying I need to alter the configuration of the vRA REST Host resource I'm binding my VRA:Host variable to? Or do I need to change how I'm performing the request in the code?

 

Thanks!

0 Kudos
xian_
Expert
Expert

If you use the vRA plugin, you need an endpoint created with the user account you wish to approve by. You can dynamically create it with VraHostManager.createHost or create it beforehand, if you want to use an API user to approve (that's what I recommend, see the blog post).

If you use the REST endpoint, you need to authenticate with the user account you wish to approve by, to get the appropriate token. You need the password stored somewhere, so the first method is more secure (one cannot print the password).

 

stratoCumulus
Contributor
Contributor

I understand what you mean now. I was going to create a separate endpoint/account for approvals, but realized I was thinking too deep in the weeds. I ended up just adding my service account I'm using for vRO integration as an approver in the project and policy.

Now I'm getting a response back with content populated. Thanks for your help!

0 Kudos