Welcome to the Inedo Forums! Check out the Forums Guide for help getting started.
If you are experiencing any issues with the forum software, please visit the Contact Form on our website and let us know!
Using API on PowerShell
-
Hello,
I am having some issues with ProGet API. I am trying to use Powershell in order to create, update feeds, and then add some retention rules. My script is based on this doc: https://docs.inedo.com/docs/proget/reference/api/feed-management.
Here is the script:
$progetApiUrl = "https://{server}/" $apiKey = "secret-api-key" #Force TLS 1.2 [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 $Header = @{"X-ApiKey" = $apiKey} $uri = "$progetApiUrl/api/management/feeds/create/" $Body = @{name="example";feedType="universal";active=$true} $response = Invoke-RestMethod -Method POST -Uri $uri -ContentType "application/json" -Headers $Header -Body ( $Body | ConvertTo-Json)
A sample response is:
- The api documentation: https://github.com/Inedo/inedo-docs/blob/master/ProGet/reference/api/native.htm
Using that documentation, i have tried to create my feeds like this:
$progetApiUrl = "https://{server}/" $apiKey = "secret-api-key" #Force TLS 1.2 [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 $Header = @{"X-ApiKey" = $apiKey} $uri = "$progetApiUrl/Feeds_CreateFeed" $body = @{ Feed_Name = "example"; FeedType_Name = "universal"; FeedConfiguration_Xml = '<Inedo.ProGet.Feeds.NuGet.NuGetFeedConfig Assembly="ProGetCoreEx"> <Properties SymbolServerEnabled="True" StripSymbolFiles="True" UseLegacyVersioning="False" /> </Inedo.ProGet.Feeds.NuGet.NuGetFeedConfig>' } $response = Invoke-RestMethod -Method POST -Uri $uri -ContentType "application/json" -Headers $Header -Body ( $body | ConvertTo-Json)
The response is a Feed_Id. But the feed has some issues when i am trying to access it. I have this error:
Server Error in '/' Application.
Specified argument was out of the range of valid values.
Parameter name: code[ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: code] Inedo.Data.DataDomain`1.GetName(String code) +551 Inedo.ProGet.WebApplication.Pages.Feeds.BrowseFeedPage.CreateChildControls() +436 Inedo.ProGet.WebApplication.Pages.<InitializeAsync>d__2.MoveNext() +197 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +60 Inedo.Web.PageFree.<ProcessRequestAsync>d__46.MoveNext() +279 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +60 System.Web.TaskAsyncHelper.EndTask(IAsyncResult ar) +64 Inedo.Web.Handlers.AsyncHandlerWrapper.EndProcessRequest(IAsyncResult result) +33 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +602 System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +195 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +128
The only way to manage the feed is by using the administration url in a browser:
- https://{server}/administration/feeds/manage-feed?feedId=xxxx
So, it is possible to modify the feed and even to delete it.
Can you please give me a sample way to do that using the API?
-
The first example you mentioned (i.e. the one to
/api/management/feeds/create
) is using the Feeds Management API; it looks ok to me on first glance... can you share the error message you got when invoking it? You should be able to see logged request/responses in the Admin > API Keys as well.The second example you mentioned (
Feeds_CreateFeed
) is using the Native API, which we don't really recommend if there's an alternative available. It is basically a wrapper around stored procedures and the database. But in this case, it looks mostly correct, but theFeedType_Name
is wrong; if you look at theFeeds
table in the database, you'll see a universal feed is actually calledProGet
in the database.Anyways, please use
/api/management/feeds
because it's easier to use and won't change if we update the database or stored procs.