The error "Facebook API offline conversion event parameter data must be in array format" has occurred

When attempting to upload events to Facebook's offline conversion dataset with custom fields, I encountered the following error:

Status:  400
  Response:
    {
      "error": {
        "message": "(#100) param data must be an array.",
        "type": "OAuthException",
        "code": 100,
        "fbtrace_id": "A5qsezd_MfvKEYYTVfPcu29"
      }
    }

You can find detailed information on how to upload offline events on this page.

https://developers.facebook.com/docs/marketing-api/offline-conversions/

CSV file structure

email,event_name,event_time,value,dept,brand,tx_type,cust_type,cust_trend
79FBB38FC843911533020FD8DE5B29CBA9958F,Purchase,2020-06-15T07:42:47Z,100.25, RENTAL,NAN,PA,Active,Growth (+15% to LY)
8EF89542E99BF7D8C0D4AA9F218,Purchase,2020-06-15T17:46:13Z,50,DEPOSITS, NAN,Other,Active,Declined (-15% to LY)
4C83B542E9C9566AA8D6A5279839115E7C0C454A1,Purchase,2020-06-15T09:55:01Z,150,DEPOSITS, NAN,PA,Active,Declined (-15% to LY)
361604C2B8FC67,Purchase,2020-06-15T15:41:18Z,50,DEPOSITS, NAN,OtherNew (Less than 3 Months),Did Not Shop LY
09133B0CDFA527BA9013CA8F1A0382D76F9,Purchase,2020-06-15T08:44:47Z,1,DEPOSITS, NAN,PX,Active,Growth (+15% to LY)
50cff131E2B3042C6E533ss225146C37994E2C2,Purchase,2020-06-15T07:35:50Z,300,DEPOSITS, NAN,Other,ActiveGrowth (+10% to LY)
ECD35DBB79FF37B0FC95E131,Purchase,2020-06-15T16:13:28Z,50,DEPOSITS, NAN,PX,Active,Decline (-12% to LY)   

Python code snippet for uploading offline conversions:

Here goes the Python code snippet...

Expected output format of uploaded data:

Expected data format...

Sample output produced by the code:

Sample output...

Answer №1

It is necessary to specify the LDU starting on July 1st, 2020.

    Code:
    def upload_offline_conversion(**args):
        from facebook_business.adobjects.offlineconversiondataset import OfflineConversionDataSet
        from facebook_business.api import FacebookAdsApi
        import pandas as pd
        #import gcsfs
        import json
        access_token = access_token
        FacebookAdsApi.init(app_id=app_id,access_token=access_token)
        offline_dataset = OfflineConversionDataSet(dataset_id)
        df = pd.read_csv('UPLOADS.csv',sep =',')
        df['event_time'] = (pd.to_datetime(df['event_time']).astype(int) / 10 ** 9).astype(int).astype(str)
        df['match_keys'] = df.apply(lambda row: json.dumps({k: [row[k]] if k in ['email'] else row[k] for k in ['email'] if pd.notnull(row[k])}), axis=1)
        del df['email']  # deleting match_keys single columns since they are now useless
        df["currency"]='CAD'
        data = (df.groupby(['event_name','event_time','match_keys','value','currency'], as_index=False)
             .apply(lambda x: x[['dept','brand','tx_type','cust_type','cust_trend']].to_dict('r'))
             .reset_index()
             .rename(columns={0:'custom_data'}).to_dict(orient='records'))
        df = pd.DataFrame(data)
        df["data_processing_options"]=  [[]] * df.shape[0]  #(Value either [] or ["LDU"]  ) 
        data  = df.to_dict(orient="records")  
        batch_limit = 2000 # Maximum number of events permitted in a single call
        for i in range(0, len(data), batch_limit):
            params = {
                    'upload_tag': 'upload_test',
                    'data': data[i:i+batch_limit],
                    }
           # print(params)
           #offline_dataset.create_event(

params=params)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What happens if I attempt to access an undefined value from a JSON array?

I've been attempting to nest a JSON array within another JSON array. I believe I have structured it correctly, but when I try to access the second array, it returns undefined. JSON example : var data = [ {"Items" : [ {"item1" : "item1 ...

Allowing Netonsoft for JSON parsing

I'm attempting to retrieve a lenient dictionary using Newtonsoft.Json. Essentially, what I'm trying to achieve is when the tool receives an input like string jsonText = @"{ "key1" : "val1", "key2" : "val2", "inconsistency", "ke ...

Tips for handling Vue/Axios JSON payload sent data in Yii2

After spending some time trying to figure it out, I finally realized the solution, which was a bit obvious. I am sharing my answer here so that others can benefit from it and also to see if there is a more efficient way to handle this issue. The problem I ...

Utilizing Python SDK to access Watson Discovery API via an HTTP Proxy server

Utilizing the Watson Python SDK from https://github.com/watson-developer-cloud/python-sdk, I am attempting to send a search request to the Watson Discovery service. However, due to being behind an HTTP proxy, I am unable to reach the Watson Discovery servi ...

Update Android: Sending data to server using PUT request

Feeling a bit frustrated here. Encountering an issue with sending all user inputs via a PUT REST request to the server. Here's how the request JSON object appears on the server: { id: "123", text: "My Name is Peter...", age": 15, name ...

Is it possible to deserialize abstract classes in JSON.Net in a unique or unconventional way?

Issue: I am facing a challenge in my data models where I need to define a class with a property that is an abstract base class. public class DataEntityModel { [JsonProperty("myData")] public Data MyData { get; set; } [JsonProperty("uniqueId") ...

Parsing and Displaying JSON Data from a Python DataFrame in D3

Trying to create a stock chart, I encountered an issue with parsing the json file output by my python dataframe. The example code from http://bl.ocks.org/mbostock/3884955 does not seem to fit the format of my data: The json looks like this: var dataset = ...

What is the level of support JACKSON offers for Java Generics?

Currently, I am engaged in a project that utilizes the restFul approach and is schema based. In this project, we are utilizing JAXB for XSD to JAVA conversion. Below is the structure of a class used in this project: @XmlAccessorType(XmlAccessType.FIEL ...

The Kendo Grid is appearing correctly, however, it is not showing the JSON data as

Lately, I've been struggling with grids, particularly when trying to display properly formatted JSON data fetched from a webservice (which has already been validated in VS2013 and JSONLint). If someone could take a look at my solution and point out wh ...

Encountering a problem when looping through a JSON response

After making an Ajax call, I received the JSON response below. studentList: { "currentStudent":0, "totalStudent":11, "studentDetails": [{ "adId":1, "adName":"BMB X5", "sfImage":{ "imageName":"Desert", "image ...

Converting Matlab Code to Python: A Comprehensive Guide

I'm in the process of converting a MATLAB .m source code file to a Python script. The initial lines of the .m file are as follows: clear all close all clc Here is my Python equivalent code for: clear all: def clearall(): """Clear all global va ...

Simplify your browsing experience by automating Google Chrome keyboard shortcuts with Selenium

For the automation task at hand, I am utilizing Chrome Keyboard shortcuts such as Ctrl+t and Ctrl+Tab with Selenium driver in Python. Various methods have been attempted to incorporate keyboard shortcuts: driver.find_element_by_tag_name('html') ...

Tips on excluding null or empty values when writing to JSON with NodeJS

When saving the following content to a JSON file, I want to exclude any fields with a value of null or blank. Specifically, I do not want to include productPrice and productRating fields in the JSON file. Since I am not very familiar with NodeJS, can someo ...

Creating an object with an array of objects as a field in MongoDB: A step-by-step guide

I have a unique schema here: const UniqueExerciseSchema = new Schema({ exerciseTitle: { type: String }, logSet: [{ weight: { type: Number }, sets: { type: Number }, reps: { type: Number }, }], }); After obtaining the da ...

How can one HTML form be used to request a unique identifier from the user, retrieve a record from the database, parse it into JSON format, and then populate an HTML page form using the

As someone who isn't an expert in any specific coding language, I have a knack for piecing things together to make them work. However, my current challenge is stretching my technical abilities a bit too far. Here's what I'm trying to achieve ...

Differentiating python timezone names

pytz offers a range of timezones such as America/Chicago, America/Los_Angeles, Asia/Kolkata or the tz abbreviation in various formats. I am interested in obtaining the complete names of timezones. Central Standard Time Pacific Standard Time Indian Stand ...

Securing a worksheet in Excel with Openyxl and tkinter

In my Python project, I am attempting to secure an Excel sheet using Openyxl. After experimenting with various methods, I have not been successful. The objective is to enable data entry for users to input information and then view it in Excel without the a ...

Extract specific fields from JSON in a single operation

My JSON file is large, but I only need to extract specific fields. I have the paths to these fields and have been using JPath successfully, but I want to streamline the process to parse all desired fields at once. For example, consider the following JSON s ...

Having a hiccup in my code. The webpage is opening fine, but I'm encountering an error when trying to input text into the search box. I'm still a beginner in Python,

from selenium import webdriver from selenium.webdriver.common.keys import Keys driver = webdriver.Chrome("C:\\Users\\rahuls1\\chromedriver.exe") driver.get('https://www.pastemagazine.com/') elem = driver.find_eleme ...

Challenges with handling JSON data in JavaScript

I am currently attempting to retrieve and parse JSON data in order to display it on a blank HTML file. Unfortunately, I keep encountering an issue where if I retrieve and parse the data, I receive an error stating Uncaught TypeError: Cannot read property & ...