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:
- Check Your Metafield Definition in Shopify
. In Shopify, ensure that your metafield is correctly defined as list.single_line_text_field.
- 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}/metafields.json’;
// 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 