Resolving Facebook CAPI Content Errors
If you're encountering issues with Facebook Conversions API (CAPI) where certain parameters like contents
or content_ids
cause errors, follow the steps below to resolve the issue.
Problem
When sending events to Facebook via CAPI, you might see the following error:
{"error":{"message":"Invalid parameter","type":"OAuthException","code":100,"error_subcode":2804008,"is_transient":false,"error_user_title":"Invalid Contents Parameter","error_user_msg":"The contents parameter you entered doesn't contain a list of JSON objects. Enter a list of JSON objects that contain the product IDs associated with the event plus information about the products. For example: [{ 'id' : 'ABC123', 'quantity' : '2', 'item_price' : 5.99}, { 'id' : 'XYZ789' , 'quantity' : 2, 'item_price' : 9.99}]","fbtrace_id":"..."}}
This typically indicates that the contents
parameter is either malformed or not formatted as a list of JSON objects.
Solution
Step 1: Remove contents
and content_ids
From Existing Server-Side Facebook CAPI Tags
1. Go to your server container in your tag manager.
2. Locate the Facebook CAPI tag that is currently configured.
3. Remove the contents
and content_ids
parameters from the tag.
Step 2: Modify the contents
Parameter for Purchase Events
1. Create a JavaScript Variable in your client container:
- Open your web container.
- Add a new variable of type Custom JavaScript.
- Use the following code to construct the contents
parameter (Make sure {{DLV - ecommerce.items}} is your correct items variable):
function() {
// Access the items array from the dataLayer
var items = {{DLV - ecommerce.items}};
// Validate that items is an array with at least one item
if (!items || !Array.isArray(items) || items.length === 0) {
return null;
}
// Map over each item to create a new array with the modified properties
var modifiedItems = items.map(function(item) {
return {
id: item.item_id,
name: item.item_name || "",
price: item.price || 0,
quantity: item.quantity || 1
};
});
// Return only the first item in the modified array as required
return [modifiedItems[0]];
}
2. Add the Variable to the GA4 Purchase Event Tag:
- Assign the newly created variable as the value for the contents
parameter.
Step 3: Separate the Facebook CAPI Tag for Purchase Events
1. In the server container:
- Create a dedicated Facebook CAPI tag for purchase events.
- Exclude purchase events from the original Facebook CAPI tag.
2. Add the contents
parameter to the new purchase-specific CAPI tag:
- Use an Event Data Variable to pull the contents
value from the variable you created earlier in the web container.
3. Test the changes:
- Ensure events are firing correctly with the modified contents
parameter.
Step 4: Publish and Verify
1. Publish the changes in both the web container and server container.
2. Test all events (e.g., Add to Cart, Purchase) to confirm that they are functioning as expected.
3. Check Facebook Event Manager to ensure no errors appear.
Outcome
This updated solution resolves the Invalid Contents Parameter
error and ensures smooth data transfer between your system and Facebook CAPI for all events, including purchases.
Additionally, by removing the contents
and content_ids
parameters from the original server-side CAPI tag, you eliminate potential conflicts with other configurations.
If the issue persists, double-check the formatting of the contents
parameter and test the setup again. For additional assistance, please contact our support team.