Hi,
I am trying to get a metafield on the company of a user. The metafield is company.sold_to_address.
Here’s my code:
import {
reactExtension,
BlockLayout,
Text,
BlockSpacer,
} from '@shopify/ui-extensions-react/customer-account';
export default reactExtension(
"customer-account.profile.company-details.render-after",
async (api) => {
const companyId = api.authenticatedAccount.purchasingCompany.current.company.id;
const metafieldNamespace = "company";
const metafieldKey = "sold_to_address";
try {
const customerQuery = {
query: `query {
company(id: "gid://shopify/Company/${companyId}") {
name
metafield(namespace: "${metafieldNamespace}", key: "${metafieldKey}") {
id
key
value
}
}
}`,
};
const result = await fetch(
"shopify://customer-account/api/latest/graphql.json",
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(customerQuery),
}
);
const { data } = await result.json();
console.log("Data:");
console.log(data);
} catch (error) {
console.log(error);
}
return (
);
}
);
My console.log statement prints the following:
company {
metafield: null
name: “A-Bad AS”
}
I cannot figure out how to access the metafield. It is there, I can get it through the graphql admin API.