assign dedicated external bamboo agent to project
Asked by phlo_z:

### Hello, {#toc-hId-1084591281}

I am trying to do a dedicated assigment between a external agent and a plan/job or whatever, using the bamboo rest api.

I found in the Documentation this.

### /agent/assignment?executorType\&executorId\&assignmentType\&entityId {#toc-hId--722863182}

**executorType**

*[string](http://www.w3.org/TR/xmlschema-2/#string)*

should be AGENT or IMAGE

**executorId**

*[long](http://www.w3.org/TR/xmlschema-2/#long)*

executor id. Id of agent or elastic image.

**assignmentType**

*[string](http://www.w3.org/TR/xmlschema-2/#string)*

should be PROJECT, PLAN, JOB, ENVIRONMENT, DEPLOYMENT_PROJECT

**entityId**

*[long](http://www.w3.org/TR/xmlschema-2/#long)*

entity id. Identifier of project, plan, job, deployment project or environment.

I am wondering what entityId really is and where i can find it from eacht Plan, job ..

Its waiting for a long so, jobkey or plankey will not work.

Also on the get

### /agent/assignment/search?executorType\&executorId\&entityType\&searchTerm {#toc-hId-1764649651}

What the heck should entityType be?

The rest api seems to be not very good documented :-(

Any help would be much appriciated.


Answers:
author: Jonathan Ghellere
body: The only way to get plans, jobs... entityIds is through the agent assignment search API. Still, you first need an agent ID.

1. First get any agent id:  
   /rest/api/latest/agent \| jq -r '.\[\] \| \[.id, .name, .active\] \| @csv'
2. Then, run the following  
   /rest/api/latest/agent/assignment/search?searchTerm=\&**entityType**=PLAN\&executorType=AGENT\&executorId=**\<THE-ID-U-GOT-UP-THERE\>** " \| jq -r '.searchResults\[\] \| \[.id, .searchEntity.id\] \| @csv

Where, in the (2.), the entityType can be: PLAN, JOB..  
I also provided some jq queries, you can ignore if you want.

I know, it's crazy and does not make any sense.. : )

ps. For JOBs it will only work if the agent's capacities matches your job requirements!


author: Daniel Santos
body: Hi [@phlo_z](/t5/user/viewprofilepage/user-id/520810),

**entityID**

The ++entityID++ is the ID used to identify the project/plan/job in the Bamboo database. That is a design issue that blocks this API to be used only through a sequence of rest APIs.

There are some improvement requests related to this issue already reported:

* [\[BAM-19660\] REST APIs for Projects should show the Project id](https://jira.atlassian.com/browse/BAM-19660)  
  workaround through DB:

  ```
  select title, project_key, project_id from the project;
  ```

* [\[BAM-18382\] REST APIs for plans should return the plan id](https://jira.atlassian.com/browse/BAM-18382)  
  workaround through DB:

  ```
  select title, full_key, build_id from build where build_type='CHAIN';
  ```

* [\[BAM-19659\] REST APIs for Jobs should show the Job id](https://jira.atlassian.com/browse/BAM-19659)  
  workaround through DB:

  ```
  select title, full_key, build_id from build where build_type='JOB';
  ```

<br />

There are also internal discussions to change the agent assignment REST endpoint to make it use only project/plan/job keys which would make things a lot easier.

The API will work completely through APIs if you need to assign deployments/environments.

To get the de IDs you need to call:

* /rest/api/latest/deploy/project/all

**executorID**

Regarding the executorID, you can get it from:

* /rest/api/latest/agent  
  The field is **id** (agent id).

**Steps to do the agent assignment**

1. Get the ++executorID++ which is the agent ++id++ using the following call:

   ```
   curl -X GET -u <USER>:<PASSWORD> "<BAMBOO_URL>/rest/api/latest/agent"
   ```

2. Get the ++entityID++ from either the DB (project/plan/job) as shared above or use the deployment call below:

   ```
   curl -X GET -u <USER>:<PASSWORD> "<BAMBOO_URL>/rest/api/latest/deploy/project/all"
   ```

3. Assign the agent with the following call:

   ```
   curl -X POST -u <USER>:<PASSWORD> "<BAMBOO_URL>/rest/api/latest/agent/assignment?executorType=AGENT&executorId=<EXECUTOR_ID>&assignmentType=<ASSIGNMENT_TYPE>&entityId=<ENTITY_ID>" 

   ```

I hope that helps.

comments: author: HN
body: It is disappointing at the least that the API does not provide the build project id nor is it visible in the UI. Are you aware of any plugins that expose this data?