How to create list of single-line text metafield from Business Central

How to create list of single-line text metafield from Business Central

Ekin
Shopify Partner
1 0 1

Hello,

 

I am trying to send a metafield for shopify variant from Business central to Shopify, my issue is that the metafield is created as type: Single-line Text but defined as List of values. In Business central, in shopify metafield, there is no definition for single-line test as list, so when I try to send data to shopify the response I've got is the following:
"Type 'single_line_text_field' must be consistent with the definition's type: 'list.single_line_text_field" But I have no idea about how to send a list of single-line texts from BC, there is not much indication about how-to's in microsoft learn either, help will be much appreciated.

 

Ekin

Reply 1 (1)

goldi07
Trailblazer
147 10 16

Hello @Ekin 

You're running into an issue because Business Central (BC) does not natively support defining a list of single-line text metafields for Shopify. However, Shopify expects the data type to be list.single_line_text_field instead of just single_line_text_field.

Solution:
You need to format your data as a list of strings (JSON array) before sending it to Shopify.

Steps to Fix the Issue:
1. Check Your Metafield Definition in Shopify

. In Shopify, ensure that your metafield is correctly defined as list.single_line_text_field.

2. Modify the Business Central Code to Send a List of Strings

. In Business Central, you need to construct a JSON array (["value1", "value2", "value3"]) instead of sending a single string.

Example Code to Send List of Single-Line Texts from Business Central
Modify your AL code to correctly structure the payload:

 

al

 

var
Client: HttpClient;
Request: HttpRequestMessage;
Response: HttpResponseMessage;
Content: HttpContent;
JsonObject: JsonObject;
JsonArray: JsonArray;
JsonValue: JsonValue;
ShopifyAPIUrl: Text;
ShopifyAccessToken: Text;
ShopifyMetafield: JsonObject;
begin
// Shopify API Endpoint for Updating Metafields
ShopifyAPIUrl := 'https://yourstore.myshopify.com/admin/api/2024-01/products/{product_id}/variants/{variant_id}/metafi...';

// Add values to the JSON array
JsonArray.Add(JsonValue.FromText('Value 1'));
JsonArray.Add(JsonValue.FromText('Value 2'));
JsonArray.Add(JsonValue.FromText('Value 3'));

// Constructing the metafield JSON object
ShopifyMetafield.Add('namespace', 'custom');
ShopifyMetafield.Add('key', 'your_metafield_key');
ShopifyMetafield.Add('type', 'list.single_line_text_field');
ShopifyMetafield.Add('value', JsonArray); // Attach array here

// Convert JSON object to content
Content.WriteFrom(ShopifyMetafield);
Content.GetHeaders().Add('Content-Type', 'application/json');

// Setup HTTP request
Request.Method := 'POST';
Request.SetRequestUri(ShopifyAPIUrl);
Request.GetHeaders().Add('X-Shopify-Access-Token', ShopifyAccessToken);
Request.Content := Content;

// Send the request
if Client.Send(Request, Response) then begin
Message('Metafield sent successfully!');
end else begin
Error('Failed to send metafield.');
end;
end;

 

 

Key Fixes in the Code:
. Use list.single_line_text_field as the metafield type.
. Format the value as an array (i.e., ["value1", "value2"]) instead of a single string.
. Use JsonArray to create the list and add it to the payload.

This will ensure that Shopify correctly recognizes the metafield as a list of single-line text values instead of a single text field.

 

Thank you 😊

 

Was I helpful?

Buy me a coffee



Want to modify or custom changes or bug fix on store . Or Need help with your store? Or -Want Complete Storefront
Email me -Goldi184507@gmail.com - Skype: live:.cid.819bad8ddb52736c -Whatsapp: +919317950519
Checkout Some Free Sections Here