Delete asset on cesium ion with nodejs

Hi,
I’m trying to delete assets with nodejs.
I tried :

const response = await request({
        url: 'https://api.cesium.com/v1/assets',
        method: 'DELETE',
        headers: { Authorization: `Bearer ${accessToken}` },
        json: true,
        body: {
            assetId: '936731',
        }
    });

But it’s not working. Can you point to an exemple please ?
Thanks

Hi @romza,

Are you able to successfully delete this asset from your Cesium ion account?

-Sam

Hi Sam,
From the Cesium ion page yes.
But I can’t make it work with javascript.

Hi @romza,

Understood :+1: We will investigate this and get back to you shortly.

In the meantime, I recommend that you check out our documentation and guide for deleting assets:

Are you getting a response when you attempt to delete an asset?

All the best,
Sam

Hi Sam,
Thanks. I did check out the documentation and tried to write the code I shared based on it, but I’m not sure it’s the right way.
I found exemple of how to list the assets, and to upload one, but I couldn’t find code exemple for deleting an asset.
I get a 500 (Internal Server Error) when I tried this code.
Best,

Hi @romza,

This is the section that I am referring to:

I haven’t been able to find a code example that showcases the best practices for using this functionality, but I will continue to investigate.

-Sam

Hi @sam.rothstein

I get a 405 - {"code":"MethodNotAllowed","message":"DELETE is not allowed"}

When trying this code :

async function main() {

    const response = await request({
        url: 'https://api.cesium.com/v1/assets',
        method: 'DELETE',
        headers: { Authorization: `Bearer ${accessToken}` },
        json: true,
        body: {
            assetId: 932791,
        }
    });
}

main().catch(e => {
    console.log(e.message);
});

I tried DEL instead of DELETE, and got this :

The request could not be satisfied.</H2>\n<HR noshade size=\"1px\">\nThis distribution is not configured to allow the HTTP request method that was used for this request. The distribution supports only cachable requests.\nWe can't connect to the server for this app or website at this time. There might be too much traffic or a configuration error. Try again later, or contact the app or website owner.\n<BR clear=\"all\">\nIf you provide content to customers through CloudFront, you can find steps to troubleshoot and help prevent this error by reviewing the CloudFront documentation.

Hi @romza,

Thank you for the update. We will take this additional information into account and continue investigating.

All the best,
Sam

Hi @sam.rothstein,

Any news about this ?
Is it possible to delete asset with the rest API ?

My token provides access to the following scopes:

  • assets:list
  • assets:read
  • assets:write
  • geocode
  • profile:read
  • tokens:read
  • tokens:write

I don’t see any assets:delete. Could this be why ?
Thanks,

Romain

Hi @romza,

assetId has to be passed in the URL parameters. It seems like you are passing it in the body. Please check out the following documentation for more information.

Ion REST API documentation – Cesium

-Sam

Hi Sam, Thanks ! It’s working now ! I was able to delete assets with the id in the URL parameters.

Best,

Romain

Hi Romain,

Great, happy to hear that we got this working.

-Sam