How to Create Multiple Target Servers using curl/Management API Call

Hi,

I am trying to create target servers using managament API call, where in I have multiple entry's in JSON body.

ex:

[{ "name" : "targqqq22", "host" : "apigeemock.target.net", "isEnabled" : true, "port" : 443 }, { "name" : "targqqq11", "host" : "apigeemock.target.net", "isEnabled" : true, "port" : 443 } ]

Does Management API call support creation of multiple target servers?

0 3 844
3 REPLIES 3

Have you looked at the Apigee Plugins (Maven, Node) which do exactly the same using the Management API Calls?

https://github.com/apigee/apigee-config-maven-plugin

Here is the management API which can create a target server

https://apidocs.apigee.com/management/apis/post/organizations/%7Borg_name%7D/environments/%7Benv_nam...

You will have to make changes to the URL if you are using Private Cloud. In this case, you can store every target server configuration as a JSON file and submit it over curl

Thanks @rmishra,

I am trying to create target servers using cURL command like below:

curl -X POST --header "Content-Type: application/json" --header "Authorization: Basic <<value>>" -d "{
\"name\" : \"target2\",
\"host\" : \"mocktarget.apigee.net\",
\"isEnabled\" : true,
\"port\" : 443
}" "https://api.enterprise.apigee.com/v1/organizations/<<value>>/environments/test/targetservers"

For single target server this is working fine.

I have a jenkins job which will read config file(which has multiple target servers),If I give multiple entry's in JSON body only the first entry target server is created and the next set of target servers are skipped. Is there an example/sample where in I can pass an Array of target server entry's to management API?

I am guessing your Jenkins job pulls out the config file out of the source code repository somewhere. If it doesn't , please store your config files in a source code repository.

Once you do, create one JSON file per target server.

Enhance Jenkins to execute a shell script (stored with the json files) which iterates over all the json files and makes one curl call per json file.

If you choose to keep a single file, feed your file to jq(https://stedolan.github.io/jq/) , iterate over the list of target servers and then make a curl call per target server.

Please google on the plugins i pointed to, you will find enough examples. As of now, it seems you writing another client for the Management API when a few already exist