VMware Cloud Community
Dlally1
Contributor
Contributor
Jump to solution

REST 404 error help

So I have a weird issue, to me.

 

I'm currently running 8.6.2 and I tested some rest commands to pull deployment resources and it runs successfully.  However, when I call the same command during an actual build, I get a 404 error.  

 

ex:

var restClient = host.createRestClient();
var request = restClient.createRequest("GET",'/deployment/api/deployments/'+deploymentId+'/resources'null);
var keys = inputHeaders.keys;
for(var key in keys){
    request.setHeader(keys[key], inputHeaders.get(keys[key]));
    System.log("Value for key: "+keys[key] +" is: "+inputHeaders.get(keys[key]));
}
 
 
GET Resources failed with status code: 404 Error: {"message":"No value present","statusCode":404,"errorCode":0}
0 Kudos
1 Solution

Accepted Solutions
xian_
Expert
Expert
Jump to solution

Try this code:

 

 

System.log("workflow.runningUserName: " + workflow.runningUserName);
System.log("host.user: " + host.user);
deploymentId = inputProperties.deploymentId;
var restClient = host.createRestClient();
var request = restClient.createRequest("GET",'/deployment/api/deployments/'+deploymentId+'/resources', null);
var response = restClient.execute(request);
System.log(response.contentAsString);

 

 

If you use the Default vRA:Host, you'll get the following output when running via EBS:

 

 

2022-02-28 11:09:05.051 +01:00 INFO __item_stack:/item1
2022-02-28 11:09:05.056 +01:00 INFO workflow.runningUserName: vro-gateway-PI9Tb4JdsJ3u8iIR
2022-02-28 11:09:05.057 +01:00 INFO host.user: null
2022-02-28 11:09:05.076 +01:00 INFO {"message":"No value present","statusCode":404,"errorCode":0}
2022-02-28 11:09:05.082 +01:00 INFO __item_stack:/item0

 

 

What you can see here is that your WF is running with a technical user vro-gateway. When you use the Default vRA:Host, it will connect to vRA with that user and it has no permissions to get deployment data.

What you can do is to create another vRA:Host endpoint with a user (can be a technical user) that has permissions to the API, and use that endpoint in your workflow. Then you'll get this output:

 

 

2022-02-28 12:45:35.089 +01:00 INFO __item_stack:/item1
2022-02-28 12:45:35.095 +01:00 INFO workflow.runningUserName: vro-gateway-PI9Tb4JdsJ3u8iIR
2022-02-28 12:45:35.097 +01:00 INFO host.user: apiuser
2022-02-28 12:45:35.119 +01:00 INFO {"content":[{"id":"7202ac34-627f-48d2-8371-a8dea032602c" ...
2022-02-28 12:45:35.126 +01:00 INFO __item_stack:/item0

 

 

 

View solution in original post

0 Kudos
6 Replies
ronaldod
Enthusiast
Enthusiast
Jump to solution

Best is to log your complete query and test it in a tool like postman. This tool saved me at a lot of moments.

0 Kudos
xian_
Expert
Expert
Jump to solution

Can you print the user the host object is using:

System.log("api user: " + host.user);

Compare the output of your manual run and during provisioning.

Another issue might be that there are no resources yet under your deployment when the API call made. What event are you running your code at?

0 Kudos
Dlally1
Contributor
Contributor
Jump to solution

I'm running it during the Compute post provision.

 

I did test the api user and it returns null on my manual successful run just now.  

0 Kudos
xian_
Expert
Expert
Jump to solution

Try this code:

 

 

System.log("workflow.runningUserName: " + workflow.runningUserName);
System.log("host.user: " + host.user);
deploymentId = inputProperties.deploymentId;
var restClient = host.createRestClient();
var request = restClient.createRequest("GET",'/deployment/api/deployments/'+deploymentId+'/resources', null);
var response = restClient.execute(request);
System.log(response.contentAsString);

 

 

If you use the Default vRA:Host, you'll get the following output when running via EBS:

 

 

2022-02-28 11:09:05.051 +01:00 INFO __item_stack:/item1
2022-02-28 11:09:05.056 +01:00 INFO workflow.runningUserName: vro-gateway-PI9Tb4JdsJ3u8iIR
2022-02-28 11:09:05.057 +01:00 INFO host.user: null
2022-02-28 11:09:05.076 +01:00 INFO {"message":"No value present","statusCode":404,"errorCode":0}
2022-02-28 11:09:05.082 +01:00 INFO __item_stack:/item0

 

 

What you can see here is that your WF is running with a technical user vro-gateway. When you use the Default vRA:Host, it will connect to vRA with that user and it has no permissions to get deployment data.

What you can do is to create another vRA:Host endpoint with a user (can be a technical user) that has permissions to the API, and use that endpoint in your workflow. Then you'll get this output:

 

 

2022-02-28 12:45:35.089 +01:00 INFO __item_stack:/item1
2022-02-28 12:45:35.095 +01:00 INFO workflow.runningUserName: vro-gateway-PI9Tb4JdsJ3u8iIR
2022-02-28 12:45:35.097 +01:00 INFO host.user: apiuser
2022-02-28 12:45:35.119 +01:00 INFO {"content":[{"id":"7202ac34-627f-48d2-8371-a8dea032602c" ...
2022-02-28 12:45:35.126 +01:00 INFO __item_stack:/item0

 

 

 

0 Kudos
Dlally1
Contributor
Contributor
Jump to solution

Xian, thank you so much.  That was the exact problem it was having.

0 Kudos
Commens
Enthusiast
Enthusiast
Jump to solution

I hate to bring this back up, but I'm setting up a new vRA as well and do a similar setup.  I'm getting a 500 error using my service account.  I setup this user as an organization owner, but still getting that error.  Is there another way to setup permissions for API access?  

0 Kudos