Why isn't my asset file updating through API?

Topic summary

A developer is experiencing issues updating a Shopify theme asset file via the REST API.

The Problem:

  • The code successfully retrieves an asset file (assets/animations.js) using a GET request
  • However, the subsequent PUT request to update the asset’s value appears to fail or not persist changes
  • The developer is attempting to change the asset value to a simple HTML string (<p>Hello world</p>)

Code Structure:

  • Uses Shopify’s REST client with session authentication
  • Fetches the asset first, then attempts to update it with client.put
  • Includes error handling that returns a 500 status with an error message

Current Status:
The discussion shows only the initial code snippet with no responses yet. The issue remains unresolved, with no community feedback on potential causes such as incorrect API parameters, theme permissions, or asset key formatting problems.

Summarized with AI on November 13. AI used: claude-sonnet-4-5-20250929.

app.get(“/api/single_a”, verifyRequest, async (req, res) => {
try {
const sessionId = await shopify.session.getCurrentId({
rawRequest: req,
rawResponse: res,
});
const session = await sessionHandler.loadSession(sessionId);

const client = new shopify.clients.Rest({session});
const response = await client.get({
path: ‘themes/id/assets’,
query:{
asset:{
key: “assets/animations.js”
}
}
});

console.log(“value”, response.body.asset.value )
response.body.asset.value = “

Heloo world


console.log(“value changed”, response.body.asset.value )

await client.put({
path: themes/id/assets,
data: response.body.asset

});

console.log(“Layout of theme liquid”, response);

res.status(200).json({ response }); // Assuming you want to send themes as JSON
} catch (error) {
console.error(“Error while fetching all Single Asset”, error);
res.status(500).json({ error: “An error occurred while fetching Single Asset” });
}
});

1 Like