Get metafiels value in Post Purchase extension

Hi,
I am developing post purchase extension. I can’t get metafields value in shop field of InputData.
I set access.storefront = PUBLIC_READ, owerType = SHOP for metafield setting.
Thank you for your assistance and any solution you can provide.

Hi @nadiport

Are the metafields added to the .toml file? They should be added like this:

type = "post_purchase"
name = "checkout_post_purchase"

# [[metafields]]
# namespace: my-namespace
# key: my-key

# [[metafields]]
# namespace: my-namespace
# key: my-key-2

See example implementation here: Post-purchase extensions configuration

Hi @Liam-Shopify,
I added the metafields to the .toml file. But I build project, it show error

Can you post your .toml file with any sensitive data removed?

Hi, @Liam-Shopify
Here is my toml file configuration. I used shopify/cli to create post purchase extension.

@Liam-Shopify Do you have any solution for this problem? Thank you.

Hi again,

You don’t need to include the "" around namespaces and keys, see example:

I am also looking into this and I wonder how this works as the metafields in the api documentation (which you’ve screenshot) shouldn’t be read as they are commented out. Even if they are read, where would they show up? In the post purchase api documentation for shouldRender and the render extension points it shows 3 places where there are metafields added, the shop, product, and variant. Which one gets populated with these metafields? Does the logic run for each entity where there can be metafields and apply each of the described metafield namespace(s) and key(s) that are found in the toml file? Or are they searching on another owner type?
Please advise.

1 Like

@Liam-Shopify Any advice on the question above?

I’m also seeing the same issue. Nothing I try seems to work to fetch the metafields that are defined in the .toml file.

w │ ❌ Error
14:53:16 │               app-preview │ └  Error reloading app: Fix the following error in                              
extensions/post-purchase-offer/shopify.extension.toml:                                                                 
14:53:16 │               app-preview │ Invalid character, expected "=" at row 6, col 10, pos 145:                      
14:53:16 │               app-preview │ 5: [[metafields]]                                                               
14:53:16 │               app-preview │ 6> namespace: custom                                                            
14:53:16 │               app-preview │             ^                                                                   
14:53:16 │               app-preview │ 7: key: test                                                                    
14:53:16 │               app-preview │                  

This format doesn’t work. The CLI demo generates it like namespace = "custom". I’ve added a shop metafield definition with Storefront API read permission, but inputData.shop.metafields is empty.

I really need to use $app namespace and without storefront API permission, since there’s no definition, but I’m just trying things now and I can’t even get a simple custom.test metafield working.