Dev Zone

Deleting apps from your ODC instance programmatically

otavio-souza
hero-bp-odc-productivity-delete-apps

Does this sound familiar to you? You start building one app, then two. Naturally, you're excited, and before you know it, you have dozens of them on your OutSystems Developer Cloud (ODC) infrastructure.

Well, that happens to me all the time. It’s just so easy and handy to create them with one specific need or another, or many times to just try new features like Agent Workbench, for instance.

What’s the problem? Well, you know, whether you’re in the ODC free tier or you’re an OutSystems customer, you could use a clean-up from time to time.

ODC is designed as an enterprise platform, so it naturally comes with robust guardrails to prevent accidental data loss. That is why deleting an app requires you to manually type its name. This safety step is crucial for critical applications.However, when you are working in a developer sandbox or a personal playground, you often create dozens of throwaway prototypes. But in these cases, the manual safety step can slow down your clean-up process.

In this article, we show you how to use ODC's APIs to build a developer productivity tool that allows for bulk deletion. In case you’re wondering, we’re not bypassing security. What we’re demonstrating is that the platform's extensibility helps you manage your sandbox efficiently.

Meet my collaborators

It takes a village to develop a blog on the topic of building a tool that deletes apps from ODC instances. So, I’d also like to thank the teams that made this project happen:

Important reminder before we start

Just remember: with the power to bulk-delete comes the responsibility to ensure you never run this against production environments.

This technique lets you wipe every app from your environment in one go, but remember: there is no rollback. Please be mindful of the risks. Deleting an app permanently means potentially losing months of hard work, so double-check everything before you hit enter.

Yeah yeah yeah, enough of the dad talk, let’s get to the good part.

Managing API clients

In the ODC Portal of your tenant, you’re gonna click on API Clients and create a new one.

api clients

Give it a name. Most importantly, under Asset Management, give it Delete permissions.

create api client

That’s it, so hit the Create API button.

Make sure you copy client_id and client_secret

Wanna know more about API clients? Get in touch.

ODC Studio

Now, in ODC Studio, create a new web application, go straight to the APIs section, and under the Logic tab, call four APIs:

Openid config: https://<<ODC_INFRA>>/identity/.well-known/openid-configuration
Token: <<method URL will come from the first API>>
Get Assets: https://<<ODC_INFRA>>/api/asset-repository/v1/assets
Delete Asset: https://<<ODC_INFRA>>/api/asset-repository/v1/assets/{assetKey}

Let’s create a new Screen and call that Config and make it the default screen, there we’ll call the config and token APIs:

new screen creation

P.S. Check out this really good “Get access token” documentation by OutSystems.

P.S². Pay attention to the fact that the token call needs to be in the URL encoded format.

Next, let’s create a screen to list the assets, passing the token as a parameter.

assets list

When we click on Next, it shows the apps to be deleted.

delete app warning

See the deleted apps in the console.

apps in console

Conclusion

The most important thing here is to be careful to delete only undesired apps. This tool keeps your environment sharp, but at the same time, you can self-inflict some real damage here by deleting an app you don’t want to.

To make it easier to understand more about Client APIs, for studying purposes, or to clean up your environment, I have made this component available on the Forge.

References

Configure API access using an API client
Generate client secret
Get Access Token
Using OAuth 2.0 to access the APIs