Using the Native API
  • 27 Mar 2024
  • 2 Minutes to read
  • Dark
    Light
  • PDF

Using the Native API

  • Dark
    Light
  • PDF

Article Summary

The other endpoints should be used instead of the Native API Methods when possible, as they are much easier to use and will likely not change from version-to-version.

API Usage

All of these methods require that an API Key with Native API Access is passed into each request; see Using API Keys for more information.

Method Listing

The Native API Methods are automatically documented by a special page in the software. To see the API Methods for your specific version, go to Administration > Reference > API Methods, or directly visit http://your-proget-installation/reference/api in your installation.

Using the Native API

There are two interfaces for the native API: JSON and SQL. The native API interfaces take the same parameters and return the same data, so you should use the most convenient one for your programming environment.

JSON-based Access

The JSON interface for the native API can be used by any program that can perform HTTP requests and decode JSON. For example, here is a way to create a feed:

URL:
http://feeds.fd.local:2000/api/json/Feeds_CreateFeed

Header:
Content-Type: application/json

Body:
{
"Feed_Name" : "MyNewNuGetFeed",
"FeedType_Name" : "nuget",
"API_Key" : "«api-key»"
}

You can also use querystrings with the JSON-based API. To delete a package license and all associated rules, we need to perform two requests:

GET or POST /api/json/Licenses_GetLicenses?key=«api-key»

The first request gives us a JSON array containing JSON objects with properties of licenses in ProGet. Each license is uniquely identified with a License_Id, which we will feed into the next request:

POST /api/json/Licenses_DeleteLicense?key=«api-key»&License_Id=«application-id»

The response contains no data, as it's just a delete, and the built-in reference documentation indicates no return.

SQL-based Access

The SQL interface for the native API is useful for one-off applications because the code can run directly in the database, saving you the trouble of writing a full program.

The SQL interface also has access to some procedures not available in the JSON or SOAP interfaces. These internal procedures are not supported, but you may find them useful when writing a script. Additionally, because it operates directly on the database, the SQL interface is not restricted to procedures. In some cases, it may be easier to write one large query instead of many smaller ones.

Despite the increased power (and therefore danger) of the SQL interface, it can be used in the same way as the JSON or SOAP interfaces:

DECLARE @Application_Id INT

SELECT @License_Id = [License_Id] FROM [Licenses] WHERE [External_Id] = '«MIT, etc.»'

EXEC [Licenses_DeleteLicense] @License_Id = @License_Id

Was this article helpful?