401 error when creating asset with react

Hi,

I manage to get my assets list with axios and react like this.

try {
            const resp = await axios.get('https://api.cesium.com/v1/assets', {
                headers: {
                    'authorization': `Bearer ${accessToken}`
                },
                json: true
            });
            console.log(resp.data);
        } catch (err) {
            // Handle Error Here
            console.error(err);
        }

My problem is when I want to create my assets, I get a 401.

try {
            const resp = await axios.post('https://api.cesium.com/v1/assets', {
                headers: {
                    'authorization': `Bearer ${accessToken}`
                },
                json: true,
                body: postBody
            });
            console.log(resp.data);
        } catch (err) {
            // Handle Error Here
            console.error(err);
        }

the access Token I’m using is set to : assets:list, assets:read, assets:write, geocode, profile:read, tokens:read, tokens:write
So I should be able to creat the asset.
What am I doing wrong ?
Thanks

Hi @romza,

Thank you for bringing us your question. If possible, could you please clarify:

  • What is currently working for you, and where is your error? Are you able to access your asset list? If so, it would be great to know how the data is formatted.
  • What do you mean by create my assets? Are you trying to locally download your assets or display them? If you are trying to display them, are you using CesiumJS or Resium?

Looking forward to learning more!

-Sam

HI Sam,
Thanks for the help.
Yes I do get my assets list without problem. My problem was that I was trying to upload a file to cesium like it’s done here : cesium-ion-rest-api-examples/index.js at main · CesiumGS/cesium-ion-rest-api-examples · GitHub but with axios.

I manage to do what I wanted though, using the code above, on the server side, so it’s not really a problem for me anymore. I’m not sure what I was trying to do is even possible :slight_smile:

1 Like

Hi @romza,

Great! I am happy to hear that there was a resolution.

-Sam