Magento 2 Rest API youtube video missing values - python

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.

Related

Jira API : when using PUT call getting "no single-String constructor/factory method"

I was trying to update a custom field on a Jira ticket using Jira API, following this Jira Documentation. however, I am getting the below error.
{'errorMessages': ['Can not instantiate value of type [simple type, class com.atlassian.jira.rest.v2.issue.IssueUpdateBean] from JSON String; no single-String constructor/factory method']}
this is my code:
data = {'update': {'customfield_25305': [{'set': [{'value': '1c1a07d49af1b1cde8a1a7bd93cbbeef8efd50c9'}, {'value': 'c6f1e31ce0138cba658f769accaac729bebc42d6'}]}]}}
data = json.dumps(json.dumps(data)) #because the API accepts only strings enclosed in double quotes
upload = requests.put(url, headers=headers, data=data)
print(upload.json())
as per the documentation, I tried "/editmeta" the custom field I am trying to update is editable and has the following attributes.
{'required': False, 'schema': {'type': 'string', 'custom': 'com.atlassian.jira.plugin.system.customfieldtypes:textfield', 'customId': 25305}, 'name': 'Commit ID(s)', 'fieldId': 'customfield_25305', 'operations': ['set']}
Not sure what I am doing wrong here, any help would be appreciated!
Tried jira documentation
and searched through the Jira community none of the answers helped, everything points to malformed data but the data that I am passing is as per documentation.
the end result would be a 204 status code.
I think is a matter of single quotes.
As far as I remember, for valid JSON it should be double quotes.
{
"update": {
"customfield_25305": [{
"set": [{
"value": "1c1a07d49af1b1cde8a1a7bd93cbbeef8efd50c9"
}, {
"value": "c6f1e31ce0138cba658f769accaac729bebc42d6"
}]
}]
}
}
I use to do a online validator tool to my JSON strings when I got stuck.
E.g. https://jsonlint.com/ (first result on google)
I was able to resolve the issue, the proper formatting for data is as below:
{"fields": {"customfield_25305": "\"1c1a07d49af1b1cde8a1a7bd93cbbeef8efd50c9\", \"c6f1e31ce0138cba658f769accaac729bebc42d6\", \"1c1a07d49af1b1cde8a1a7bd93cbbeef8efd50c9\""}}

How to create a video ad in Facebook with Python SDK using an already existing video?

I am trying to create a video ad using a video that already exists in the ad account's asset library. When I first tried it, I did not specify a thumbnail and got an error message saying it needs a video thumbnail, which can be specified using either 'image_hash' or 'image_url' in the video_data field of object_story_spec. Below is the code I tried after adding in 'image_url' as a parameter:
params = {
'name': new_ad_name,
'body': body_copy,
'title': headline,
'url_tags': url_tags,
'object_story_spec': {
'page_id': page_id,
'video_data': {
'video_id': video_id,
'link_description': link_description,
'image_url': image_url,
'call_to_action': {
'type': cta,
'value': {
'link': link
}
}
}
}
}
response = my_adaccount.create_ad_creative(params=params)
print(response)
creative_id = response['id']
params = {
'name': new_ad_name,
'status': 'PAUSED',
'adset_id': adset_id,
'creative': AdCreative(fbid=creative_id)
}
response = my_adaccount.create_ad(params=params)
print(response)
How do I get the image_hash or image_url of the video? When I use the AdVideo.api_get() method, the only possible fields that would seem to make sense is 'thumbnail_url' or 'picture', which both return URLs that start with 'https://scontent.xx.fbcdn.net', and when I use it as the parameter for 'image_url', I get the below error message:
"message": "Invalid parameter",
"type": "OAuthException",
"code": 100,
"error_data": "null",
"error_subcode": 1487833,
"is_transient": true,
"error_user_title": "Image Wasn't Downloaded",
"error_user_msg": "Your image, https://scontent.xx.fbcdn.net/v/t15.13418-10/103708673_260590461836791_481914169400490137_n.jpg?_nc_cat=103&_nc_sid=f2c4d5&_nc_ohc=Uny5BTsfOP8AX_WC43Y&_nc_ad=z-m&_nc_cid=0&_nc_ht=scontent.xx&oh=6f27c0187e9477295663d325a3531c79&oe=5F11F4D7, couldn't be downloaded. Please wait a few minutes and try again."
Is there a way to create a video ad with the Python SDK without specifying the thumbnail initially? In Ads Manager, this is definitely not a requirement as Facebook generates it automatically so it seems odd that it is requiring it here.
Thank you!
For an uploaded video in media library, you can simply call a get request to the endpoint below:
https://graph.facebook.com/v11.0/video_id?fields=thumbnails
like
https://graph.facebook.com/v11.0/1086354212654329?fields=thumbnails
This will give you a list of thumbnails generated from your video. Before you create an ad, you can get the first thumbnail object's "uri" and use it as image_url.
With this way i can create ads without uploading a seperate thumbnail image to media library.

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.

Facebook APIs to retrieve deleted campaign insights

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']}]
}

getChanges Sharepoint rest API

I am using Sharepoint 2013 REST api to find out the incremental changes that have happened in the root site. My request is like below:
headers = {"Authorization": 'Bearer ' + access_token, "accept": "application/json", "odata": "verbose"}
headers["content-type"] = "application/json;odata=verbose"
body = { 'query': { '__metadata': { 'type': 'SP.ChangeQuery' },'Web': True, 'Update': True, 'Add': True,
'ChangeTokenStart':{'__metadata':{'type':'SP.ChangeToken'},
'StringValue': '1;1;5b9752ee-f410-4cc6-9ab6-eb18c2ad802f;636252579049500000;89866182'}
}
}
In response I am getting lot of changerequest objects. One of them is as below:
{
'odata.type': 'SP.ChangeWeb',
'ChangeToken': {
'StringValue': '1;1;5b9752ee-f410-4cc6-9ab6-eb18c2ad802f;636252779425600000;89976872'
},
'WebId': '6e21eadd-4155-494d-9a8e-1046865bdd4b',
'ChangeType': 2,
'odata.id': 'https://<site url>/_api/SP.ChangeWeb87f1a9c6-937b-4507-973d-fc2d1b949aed',
'SiteId': '5b9752ee-f410-4cc6-9ab6-eb18c2ad802f',
'odata.editLink': 'SP.ChangeWeb87f1a9c6-937b-4507-973d-fc2d1b949aed',
'Time': '2017-03-16T16:19:02.56Z'
Can somebody help me understand the response? I am facing difficulty to find out the path where the change happened. Also, would this getchanges API capture changes that has happened in subsites within the site?
Yes Lists and Libraries at the end of the day are the same thing. You can get the list title from odata.editLink by stripping off the last segment (Items(1)) in the above case. If you call that path it'll give you the details of the list versus the item/file that was modified. If you want the user's details call /_api/Web/lists/getbytitle('User Information List')/Items(EditorId). If you want the path to the item/file call odata.editlink and the serverrelativeurl parameter returned will have the path to it and title will have the title of the item/file.
Sure, the ChangeType is the main piece of information you need which is an enumerable. You can look up the friendly names for the numbers here: ChangeType Enumeration
So in that case, that looks like an update to the settings of the SPWeb with a guid of '6e21eadd-4155-494d-9a8e-1046865bdd4b'
You may also want to look at using the $expand operator in your REST query to get additional fields back.

Categories

Resources