Facebook APIs to retrieve deleted campaign insights - python

I'm using the python Facebook API's SDK.
I am currently able to request and obtain campaign insights from the account level, with a snippet as such:
from facebook_business.adobjects.adaccount import AdAccount
from facebook_business.adobjects.adsinsights import AdsInsights as Insights
account = AdAccount(u"act_{}".format(account_id))
report_params = {
'time_increment': time_increment,
'time_range': {
'since': start_date.strftime("%Y-%m-%d"),
'until': end_date.strftime("%Y-%m-%d"),
},
'level': 'campaign'
}
insights = account.get_insights(fields=['campaign_name', 'spend'],
params=report_params, pending=True).execute()
The problem is that I can't seem to get information about a deleted campaign, that was active for a time, meaning that it has a spend value.
Here I read that adding a filtering might give me also DELETED or ARCHIVED campaigns, but in the get_insights documentation page I can't seem to find a field to filter on, and every try has been unsuccessful

I found the right filter, even though the effective_status is not obtainable through insight fields, you can use it in filters, in my case I included every possible campaign.effective_status. Using the following report_params
report_params = {
'time_increment': time_increment,
'time_range': {
'since': start_date.strftime("%Y-%m-%d"),
'until': end_date.strftime("%Y-%m-%d"),
},
'level': 'campaign',
'filtering': [{'field': 'campaign.effective_status',
'operator': 'IN',
'value': ['ACTIVE', 'PAUSED', 'DELETED', 'PENDING_REVIEW', 'DISAPPROVED',
'PREAPPROVED', 'PENDING_BILLING_INFO', 'CAMPAIGN_PAUSED', 'ARCHIVED',
'ADSET_PAUSED']}]
}

Related

Facebook Business Manager Results metric via API (python)

With python I’m using Insights API in order to get data (at the campaign level) of the facebook business manager report (impressions, clicks etc etc).
I’m using the following code:
from facebook_business.api import FacebookAdsApi
from facebook_business.adobjects.adaccount import AdAccount
access_token = "****"
app_secret = "****"
app_id = "*****"
ad_accounts = [{"name": "***", "id": "act_****"}, {"name": "***", "id": "act_****"}]
fields = [
'reach',
'impressions',
'spend',
'clicks',
'account_id',
'account_name',
'campaign_name',
'campaign_id',
'date_start',
'date_stop',
'objective',
'inline_link_clicks',
'inline_post_engagement',
'inline_link_click_ctr',
'actions',
'estimated_ad_recallers'
]
params = {
# since not less than 37 months ago
'time_range': {'since':'2018-07-05', 'until':'2021-08-02'},
'filtering': [],
'level': 'campaign',
'breakdowns': [],
'limit': 100000,
'use_unified_attribution_setting': True
}
for ad_account in ad_accounts:
report_campaigns = list(AdAccount(ad_account['id']).get_insights(
fields=fields,
params=params,
)
)
My problem is that i need the “Results” field too. Although it is available in the fb business manager UI (see image below), “Results” is not available among all the possible fields of the insight API.
I wonder if there is a way to have the Results metric via API.
I know I could compute this field knowing the objective of the campaign, however I have many custom objectives so this approach would be very long and I would like to avoid it if possible.
Looks to me like what you're looking for is provided under the "conversion_values" field which in turn has action_type as one of its parameters: https://developers.facebook.com/docs/marketing-api/reference/ads-action-stats/
It helps to remember that the names you see in the UI don't have to match the names coming from the API. Reading documentations may not be sexy, but given the proper attention they deserve, they almost never disappoint you.

How can I add attributes to my product using woocommerce api in python

I find difficulty on how to pass attributes to a product using the woocommerce rest api.
I successfully took the attribute id.
my function:
def assign_attribute_to_products(wcapi_yachtcharterapp,post_id,attribute_id):
#the post_id argument is the product id
data = {
"attributes": [
{
"id": attribute_id,
},
],
}
wcapi_yachtcharterapp.put("products/"+str(post_id), data).json()
The product is updated without passing the information of attribute_id.
Any idea how to fix this?
You are missing some data, take a look here
This works for me:
data = {'attributes': [{'id': 7,
'options': ['term01', 'term02'],
'variation': 'true',
'visible': 'true'}]}
even though the data type for visible and variation is a boolean in the docs, you have to set 'true' or 'false' with a string.
You have to include the options for variations.
Hope this helps.

Magento 2 Rest API youtube video missing values

I have simple question regarding the Magento V1 media API. I'm trying to add a video to a product but it keeps telling me that is missing values.
I'm trying to add the data from Odoo (python) like this:
videoFile = {
"entry": {
'position': position,
'media_type': 'external-video',
'disabled': False,
'label': 'Holassss',
'types': ['image', 'small-image', 'thumbnail'],
'content': {
'base64_encoded_data': base64.b64encode(urllib.request.urlopen("https://img.youtube.com/vi/axwE9q7llEQ/0.jpg").read()).decode('ascii'),
'type': 'image/jpeg',
'name': '0.jpg'
},
'extension_attributes': {
'video_content': {
'media_type': 'external-video',
'video_provider': 'youtube',
'video_url': 'https://www.youtube.com/watch?v=axwE9q7llEQ',
'video_title': 'Titulo',
'video_description': 'Description',
'video_metadata': None,
}
}
}
}
cc = json.dumps(videoFile)
productUrl = url + "/index.php/rest/V1/products/" + productSku + "/media"
Eventually I'll add the content using the https://www.youtube.com/oembed?url=youtubeurl&format=json response.
I'm following the API documentation (http://devdocs.magento.com/swagger/index_20.html) for
catalogProductAttributeMediaGalleryManagementV1 (/V1/products/{sku}/media)
Error:
"message": "Option values that are not specified."
Please advice me on which values I'm missing and which I can leave NULL. Also let me know if there is a way to let Magento automatically get the description and other data (as on the admin panel) instead of providing it myself. last but not least, I think this documentation is missing some data. This already happened to me before with a different call and a couple of "optional" values were actually required. Is there another documentation web page?
Thank you very much.

How to assign id to a created issue with jira python?

I am using jira python to create issues through their REST api, but in the "fields" dictionary for the "project" key's dictionary, I am running into an issue when I try using "id" or "name" as keys, but it works with the "key" key.
So, this works:
'project': {'key': 'ORION'}
But, when I try using the other keys provided in the jira-python documentation such as:
'project': {'name': 'ORION-777'}
or
'project': {'id': 777}
or
'project': {'id': '777'}
It does not work. I am getting an error that says:
response text =
{
"errorMessages": [],
"errors": {
"project": "project is required"
}
}
I want to specify the id so that I don't keep creating issues for the same bug over and over. Any guidance is welcome. Thanks!
Following the documentation link that you provided, you can create an issue in the following ways:
new_issue = jira.create_issue(project='PROJ_key_or_id', summary='New issue from jira-python',
description='Look into this one', issuetype={'name': 'Bug'})
or
issue_dict = {
'project': {'id': 123},
'summary': 'New issue from jira-python',
'description': 'Look into this one',
'issuetype': {'name': 'Bug'},
}
new_issue = jira.create_issue(fields=issue_dict)
You can you a project key, name or ID.
To get the name or key, go the "Project settings" of your project then click on "Details" (you need to have the permission to see these settings).
To see the ID without making any rest query, go again in the "Project settings" page then mouse-over on details and you can view the project id in the navigation bar at the bottom of browser (i.e. pid=12345)
With this information you should able to create the issue using name, key or ID of your project.

Python will not patch json in ConnectWise.

I am a little confused why the following will not work.
I am connecting to our ConnectWise API via requests. I get the response and then I parse through to find the tickets I am looking for. I am then trying to PATCH the ticket to change certain information.
Sample json that is returned via API.
{
"id": 12345,
"summary": "[CompanyName][ComputerName] Disk Space Check - drive G:",
"recordType": "ServiceTicket",
"board": {
"id": 1,
"name": "Board1",
},
"status": {
"id": 5,
"name": "NewTicket",
},
"owner": {
"id": 1,
"identifier": "",
Once I have identified the ticket I need to work with. I try to patch it.
def assign_ticket(self, ticket):
add_resource = [
{'op': 'replace', 'path': '/board/name', 'value': 'Board2'},
{'op': 'replace', 'path': '/status/name', 'value': 'NewTicket2'},
{'op': 'replace', 'path': '/owner/identifier', 'value': 'MyBrainHurts'}
]
r = requests.patch(self.url + self.url_ticket + str(ticket), json=add_resource, headers=self.header)
print(r.status_code)
It returns a 200 status code to indicate everything completely correctly, but only the /owner/identifier field is updated. The other two are not. I have Google'd for several days and tried multiple variations of the code but I do not see why it will not change the board or status. Any ideas?
I've just checked some of my other code and I'm patching successfully using an array, but I'm using the ID of the resource rather than the name. Try that; instead of /status/name use /status/id and a numerical value.
What is the result of r.text? That should either return the configuration in its new, patched, form or it will tell you why the patch didn't work.

Categories

Resources