Upload offline Events using Facebook Business Python API

678 Views Asked by At

I am looking for some good resource to automate the complete analytics flow of Facebook Ads, such as creating audience list, creating campaign and creating custom event sets as our have business have complete offline sale cycle. I tried the curl method to get the data in reporting dashboard of Facebook but I am looking for good resource where I can automate the code on per day basis.

curl \
  -F 'access_token=SYSTEM_USER_ACCESS_TOKEN' \
  -F 'upload_tag=store_data' \
  -F 'data=[ \
    { 
      match_keys: {"phone": ["HASH1","HASH2"], "email": ["HASH3","HASH4"]}, 
      currency: "USD", 
      value: 16,
      event_name: "Purchase",
      event_time: 1456870902,
      contents: [
        {id: "A", quantity: 1},
        {id: "B", quantity: 2},
        {id: "C", quantity: 1}
      ]
      custom_data: {
        event_source: "in_store"
      },
    }, 
    { 
      match_keys: {"lead_id": "12345"}, 
      event_name: "Lead",
      event_time: 1446336000,
      contents: [
        {id: "A", quantity: 1},
        {id: "B", quantity: 2},
        {id: "C", quantity: 1}
      ]
      custom_data: {
        event_source: "email",
        action_type: "sent_open_click",
        email_type: "email_type_code", 
        email_provider: "gmail_yahoo_hotmail",
      }
    }, 
  ]'
  https://graph.facebook.com/VERSION/OFFLINE_EVENT_SET_ID/events

I followed this from this link https://developers.facebook.com/docs/marketing-api/offline-conversions/

Need to do this using facbook_business or facebook-sdk of Python.

1

There are 1 best solutions below

1
On

Finally using graph API console of Facebook I achieved it. One is supposed to use requests library of python along with the curl request reference to replicate it in pythonic code. If any one have better solution for this please add it to. Thank you. Happy coding