Octopus REST API: How do I get the latest successful deployment?

I am trying to get the latest deployment successful environment through the REST API.

I can get the last deployment through ~/api/dashboard/dynamic?environments=Environments-1&projects=Projects-10 but this returns the last deployment whether it was successful or not.

I saw in other posts similar to mine that you used to be able to get the last successful deployment by tacking on &includePrevious=true. This is not working for me, is this still supported? If not how can I get the result I want? The response that I get back from the dashboard query has all the information I need without making multiple API calls.

Also, I did notice that when I do tack on the &includePrevious that the “PreviousItems” JSON objec is not null.
Ex:
~/api/dashboard/dynamic?environments=Environments-1&projects=Projects-10 returns:
{

],
“Tenants”: [],
“Items”: [
{ … }
],
“PreviousItems”: null,

}

and
~/api/dashboard/dynamic?environments=Environments-1&projects=Projects-10&includePrevious=true returns:
{

],
“Tenants”: [],
“Items”: [
{ … }
],
“PreviousItems”: [], //Although not null it is empty…

}

Hello Carlos,

Thanks for getting in touch. Could you try using this API route:

~/api/deployments?environments=Environments-1&projects=Projects-10&taskState=Success

The valid values for TaskState are:

Queued
Executing
Failed
Canceled
TimedOut
Success
Cancelling

If you then need exact task details follow the api/tasks/ServerTasks-XXX link supplied in the Links it will have ‘State’ again and, StartTime, CompletedTime, IsCompleted, etc.

If that doesn’t help, please let us know in more detail what you’re trying to achieve with the API calls and we’ll have another look at which set of API calls will be better. It may not be possible to get all the data you need in just 1 API call.

Regards,
Nick

The route I mentioned in my initial post has all the information I need in one call. Is the “includePrevious” parameter not working supported anymore?

I think I could get it working with the route you provided but like you said I might need more than one call. What I need from the API is the last successful release number and deployment time for a specific environment. I am iterating through all the environments in our octopus instance so I don’t want to make too many calls for each one.