How to Update config/settings_data.json in Shopify?

Topic summary

A developer is building a Shopify app and encountering issues updating the config/settings_data.json file to modify theme block settings.

Current Approach:

  • Fetching the active theme via API
  • Retrieving the settings_data.json asset
  • Modifying block settings (specifically the disabled status)
  • Attempting to save changes back to Shopify

Problem: Changes don’t reflect in the Shopify admin after the update attempt.

Code Provided: The developer shared a code snippet showing their implementation using Shopify’s REST API resources (Theme and Asset), but the code appears corrupted or improperly formatted in the post, making it difficult to diagnose specific issues.

Status: The question remains unanswered with no solutions or responses from the community yet. The developer is seeking guidance on the correct method to programmatically update theme settings through their app.

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

Hello Shopify Community,

I am currently working on a Shopify app and trying to update the config/settings_data.json file, specifically to change the settings of a block in the theme. I have been able to retrieve the current settings data, but I’m facing issues when trying to update it.

Here’s a brief overview of what I’m doing:

  1. Fetch the Current Theme: I’m using the API to fetch the current theme and its associated settings_data.json file.

  2. Update the Settings: I modify the settings for a specific block (e.g., changing the disabled status and updating other settings) in the fetched data.

  3. Save the Updated Data: I attempt to save the updated settings_data.json, but it does not reflect the changes in the Shopify admin.

    Here’s the code snippet I’m using:

     
    

    export async function AppEnableDisable(admin, session, data) {
    const EnableDisable = data.EmbedApp === ‘true’ ? true : false;
    let DataTheme = null;
    try {
    const themes = await admin.rest.resources.Theme.all({
    session: session,
    });
    const currentTheme = themes.data.find(theme => theme.role === ‘main’);
    if (!currentTheme) {
    throw new Error(“No main theme found”);
    }

    DataTheme = await admin.rest.resources.Asset.all({
    session: session,
    theme_id: currentTheme.id,
    asset: { “key”: “config/settings_data.json” },
    });
    if (!DataTheme) {
    throw new Error(“Failed to fetch settings_data.json”);
    }
    DataTheme = JSON.parse(DataTheme.data[0].value);

    let blockFound = false;

    for (const blockKey in DataTheme.current.blocks) {
    const block = DataTheme.current.blocks[blockKey];

    if (block.type.includes(‘xxx/blocks/extensionid’)) {
    block.disabled = EnableDisable;
    block.settings = {
    …block.settings
    };
    blockFound = true;

    break; // Exit the loop once the block is found and updated
    }
    }

    if (!blockFound) {
    throw new Error(“No block found with type 'my extension '”);
    }
    const updatedSettingsData = DataTheme;
    const asset = new admin.rest.resources.Asset({ session: session });
    asset.theme_id = currentTheme.id
    asset.key = ‘config/settings_data.json’;
    asset.value = JSON.stringify(updatedSettingsData);
    const response = await asset.save({
    update: false,

    });

    if (response.errors) {
    throw new Error(Failed to update settings_data.json: ${JSON.stringify(response.errors)});
    }

    return { success: true, message: “Settings updated successfully.”, response };

    // return response;
    } catch (error) {
    console.error(“Error fetching asset:”, error);
    return { error: “Error during app enable/disable”, details: error.message };
    }
    }