I'm trying to work out how to replace the users in a Custom Audience. I'm able to delete and create a new audience, but ideally I just want to update the existing audience as it's shared with other accounts.
I think I may be able to do this using create_users_replace
but Im getting the error message:
facebook_business.exceptions.FacebookRequestError:
Message: Call was not successful
Method: POST
Path: https://graph.facebook.com/v13.0/23850060704540982/usersreplace
Params: {}
Status: 400
Response:
{
"error": {
"message": "(#100) The parameter session is required",
"type": "OAuthException",
"code": 100,
"fbtrace_id": "AOJ9p0Hd1Kla4NRlkhOnHIQ"
}
}
Here's the code I'm trying to use:
from collections import UserList
from facebook_business.adobjects.adaccount import AdAccount
from facebook_business.adobjects.customaudience import CustomAudience
from facebook_business.api import FacebookAdsApi
test_id = '2385040704549815'
api = FacebookAdsApi.init(access_token=access_token)
session_id = '123456789'
session = {
'session_id':session_id,
'batch_seq': 1,
'last_batch_flag':False,
}
# List of hashed email addresses (SHA256)
test_audience_list = ["8b84db83027ecd2764ac56dd6ed62aa761ea315e0268c64e34104a6536f"]
# I can add a list of users to a custom audience using this
CustomAudience(test_id).add_users(schema="EMAIL_SHA256", users=test_audience_list)
# I'm unable to replace all users with a new list
CustomAudience(test_id).create_users_replace(fields=None, params=None, batch=None)
I've also tried including the session parameter:
CustomAudience(test_id).create_users_replace(fields=None, params=None, batch=None, success=None, failure=None, session=session)
but then I get an error about an unexpected keyword argument 'session'.
Is it possible to replace all users in a Custom Audience using a new list? What would be the best way to do this?