Magento version 2.2.5
Endpoint in question /V1/products/{sku}/media METHOD: POST
I am trying to add a video under a product sku using Magento's provided API endpoint.
{
"entry": {
"media_type": "external-video",
"label": "Video 2",
"position": 2,
"disabled": false,
"types": ["thumbnail"],
"content" : {
"base64_encoded_data": "encoded image data ",
"type": "image/jpeg",
"name": "0.jpg"
},
"extension_attributes": {
"video_content": {
"media_type": "external-video",
"video_provider": "youtube",
"video_url": "some youtube video url",
"video_title": "some title",
"video_description": "",
"video_metadata": ""
}
}
}
The response I get from this call is "invalid option value", I had debugged this in a local environment which leads me to failure during ProductRepository->save() within Magento\Catalog\Model\Product\GalleryGalleryManagement.php on line 70.
Is this an issue with my payload or actual magento bug?
Resolved this issue by adding videos directly using POST /V1/products or PUT /V1/products/{sku} endpoints.
post method example:
{
"product": {
"sku": "some-sku",
..... other product data,
"media_gallery_entries": {
"media_type": "external-video",
"label": "Video 2",
"position": 2,
"disabled": false,
"types": [],
"content" : {
"base64_encoded_data": "encoded image data ",
"type": "image/jpeg",
"name": "0.jpg"
},
"extension_attributes": {
"video_content": {
"media_type": "external-video",
"video_provider": "youtube",
"video_url": "some youtube video url",
"video_title": "some title",
"video_description": "",
"video_metadata": ""
}
}
}
}
I had no luck with Magento's MediaGallery POST endpoint (/V1/products/{sku}/media.
If you want to add a video to the product page then why you did not try using YouTube API?
You just need to follow these steps:
Generate a YouTube API Key by going goodle developer console
Then add Youtube API key to your Magento 2 by going to STORES --> Configuration
Then Add Video URL
Related
I built a winebot that can suggest food pairings or make recommendations.
The integration with FB Messenger works fine, and it's supposed to call a carousel after a search to show you the various options. I found that when I call on it multiple times it will only display the carousel the first time and not a new one each time.
This is the function that calls the carousel
// CREATE RICH MESSAGES FOR FACEBOOK
function create_carousel(agent, carousel_params) {
agent.context.set({
name: 'carousel_output',
lifespan: 2,
parameters: carousel_params,
});
agent.setFollowupEvent('createCarousel');
agent.add(''); //add a dummy payload
return;
}
IntentMap is set up like this:
// Run the proper function handler based on the matched Dialogflow intent name
let intentMap = new Map();
intentMap.set('createCarousel', create_carousel);
agent.handleRequest(intentMap);
The createCarousel intent is set up with an event createCarousel and an output context called carousel_output
Under the messenger tab it has a text message followed by a payload. The text message and payload both use the content of carousel_output to make a recommendation.
{
"facebook": {
"attachment": {
"type": "template",
"payload": {
"elements": [
{
"image_url": "#carousel_output.product1.image",
"default_action": {
"url": "https://google.com",
"webview_height_ratio": "tall",
"type": "web_url"
},
"subtitle": "#carousel_output.product1.subtitle",
"title": "#carousel_output.product1.title",
"buttons": [
{
"url": "https://www.winemag.com/buying-guide/brovia-2013-garblet-sue-barolo/",
"title": "#carousel_output.product1.price",
"type": "web_url"
},
{
"title": "Some Text",
"payload": "Some Text",
"type": "postback"
}
]
},
{
"image_url": "#carousel_output.product2.image",
"subtitle": "#carousel_output.product2.subtitle",
"default_action": {
"type": "web_url",
"webview_height_ratio": "tall",
"url": "https://google.com"
},
"title": "#carousel_output.product2.title",
"buttons": [
{
"type": "web_url",
"url": "https://www.wine-searcher.com/find/limerick+lane+cellars+rocky+knoll+zinfandel+russian+river+valley+sonoma+county+north+coast/2013",
"title": "#carousel_output.product2.price"
},
{
"title": "Some Text",
"payload": "Some Text",
"type": "postback"
}
]
},
{
"default_action": {
"webview_height_ratio": "tall",
"type": "web_url",
"url": "https://google.com"
},
"image_url": "#carousel_output.product3.image",
"buttons": [
{
"title": "#carousel_output.product3.price",
"type": "web_url",
"url": "https://www.wine-searcher.com/find/charles+smith+k+vintner+the+hidden+sra+wahluke+slope+washington+usa/2009"
},
{
"title": "Some Text",
"type": "postback",
"payload": "Some Text"
}
],
"title": "#carousel_output.product3.title",
"subtitle": "#carousel_output.product3.subtitle"
}
],
"template_type": "generic"
}
}
}
}
What I noticed is that when I call the intent a second or third time , the message appears but the payload does not.
I 've already tried clearing output_context and deleting it but this does not seem to affect anything. I looked through the documentation of how payloads work but nothing specifically referencing the issue.
I was wondering if this may be a limitation on facebook messenger but don't see anything in the logs that is a flag. The function runs and the context is updated each time with the right content but just doesn't display in the bot.
The logs didn't show any errors, but the problem appeared in the data provided to the payload.
The code that creates the payload pulls images 3 at a time from a list of urls. There were only 5 urls provided in the list so on the second run it killed the carousel and did not show an undefined error message or a missing data error. Works fine after adding more urls to the list.
Currently, When an intent is invoked, I am calling a webhook and getting a response from the web service as json structure show below.
{
"speech": "this text is spoken out loud if the platform supports voice interactions",
"displayText": "this text is displayed visually"
}
This is mere text. Alternatively, What response do I have to get to display a list for example.
I tried the rich message section of dialogflow documentation. Those structures didn't work.
Every time DialogFlow matches an intent, you have the possibility to ask DialogFlow to send a request to a specific endpoint. An endpoint which you’ll obviously have to code.
That will allow you to retrieve the matched intent, as well as the matched parameters and contexts, and do some useful work with those.
How to use Message Object in Dialogflow
Kommunicate - Custom webhook Dialogflow integration example
Example of rich message with webhook
{
"fulfillmentMessages": [{
"payload": {
"message": "Object1",
"platform": "", // Example - Facebook, Slack...etc
{
"name": "Save Promo",
"action": {
"type": "quickReply",
"payload": {
"message": "text will be sent as message",
"replyMetadata": {
"key1": "value1"
}
}
}
},
{
"name": "Save Coupon",
"action": {
"type": "quickReply",
"payload": {
"message": "text will be sent as message",
"replyMetadata": {
"key1": "value1"
}
}
}
}
}, {
"payload": {
"message": "Object2",
"platform": "" // Example - Facebook, Slack...etc
}
}]
}
To add an Actions on Google List as part of the reply, you'll need to use the data field in your response to include a richResponse with what should be said, along with a systemIntent that contains the list information.
You can see more examples at their github example repository, but here is the one for showing a list:
{
"data": {
"google": {
"expectUserResponse": true,
"richResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "Choose an item"
}
}
]
},
"systemIntent": {
"intent": "actions.intent.OPTION",
"data": {
"#type": "type.googleapis.com/google.actions.v2.OptionValueSpec",
"listSelect": {
"title": "Hello",
"items": [
{
"optionInfo": {
"key": "first title"
},
"description": "first description",
"image": {
"url": "https://developers.google.com/actions/images/badges/XPM_BADGING_GoogleAssistant_VER.png",
"accessibilityText": "first alt"
},
"title": "first title"
},
{
"optionInfo": {
"key": "second"
},
"description": "second description",
"image": {
"url": "https://lh3.googleusercontent.com/Nu3a6F80WfixUqf_ec_vgXy_c0-0r4VLJRXjVFF_X_CIilEu8B9fT35qyTEj_PEsKw",
"accessibilityText": "second alt"
},
"title": "second title"
}
]
}
}
}
}
}
}
I have a webhook server that responds to Dialogflow with rich message objects, which work on the Google Assistant.
However, in the case the user chatting with my bot from a different platform other than Google Assitant, such as the web or Amazon Alexa, I would like to send a basic text response.
After looking through the docs, I am not sure how I can send a response message object that will display a rich message object when the user uses Google Assistant, and a plain text response on other platforms as a fallback.
This is the format of my current rich message response object, taken from the docs: https://dialogflow.com/docs/reference/agent/message-objects#basic_card_response
{
"messages": [
{
"buttons": [
{
"openUrlAction": {
"url": "https://linkUrl.com"
},
"title": "AoG Card Link title"
}
],
"formattedText": "AoG Card Description",
"image": {
"url": "http://imageUrl.com"
},
"platform": "google",
"subtitle": "AoG Card Subtitle",
"title": "AoG Card Title",
"type": "basic_card"
}
]
}
To do this, you'll just include a regular text/speech response in the messages object.
In the /query doc, check out the POST response sample.
Your JSON should look something like this:
{
"messages": [
{
"buttons": [
{
"openUrlAction": {
"url": "https://linkUrl.com"
},
"title": "AoG Card Link title"
}
],
"formattedText": "AoG Card Description",
"image": {
"url": "http://imageUrl.com"
},
"platform": "google",
"subtitle": "AoG Card Subtitle",
"title": "AoG Card Title",
"type": "basic_card"
},
{
"speech": "text response",
"type": 0
}
]
}
I am trying using rest API to add a product to cart with custom options type file jpg, but when I sent the request I got an error "message": "Please specify product's required option(s).",a part of code my request
"customOptions": [
{
"optionId": "2",
"optionValue": "data:image/jpeg;base64,/9j/4AAQSkZJRg...",
"extensionAttributes": {
"fileInfo": {
"base64EncodedData": "iVBORw0KGgoAAAANSUhEUgAAACgAAAAo....",
"type": "image/jpeg",
"name": "image.jpeg"
}
}
}
]
and I also tried with
"customOptions": [
{
"optionId": "2",
"optionValue": "image.jpeg",
"extensionAttributes": {
"fileInfo": {
"base64EncodedData": "iVBORw0KGgoAAAANSUhEUgAA....",
"type": "image/jpeg",
"name": "image.jpeg"
}
}
}
]
Try to use your second option and remove ".jpeg" from optionValue.
Based on this answer this could be your problem: https://magento.stackexchange.com/questions/217547/magento-2-rest-api-add-product-to-cart-with-custom-option-type-file
When I edit an ad on business.facebook.com, I can see a "Tracking" section where there is a field called "URL Parameters".
I am trying to get the value of that field using the (Graph or Marketing) API, but after reading a lot I can't find a way of achieve that.
Does somebody know if that is even possible?
See the "Ad Creative" object, "URL Tags" field.
More info here: https://developers.facebook.com/docs/marketing-api/reference/ad-creative
Whoops, that seems to be for writing only. It seems like that field is always empty when reading objects. :(
You can find this information under "url_tags" on the Ad Creative level through Graph API.
Official Documentation: https://developers.facebook.com/docs/marketing-api/reference/ad-creative/#fields
Disclaimer: I'm still pretty new to intermediate graph API usage, but this is what I figured out so far.
The python page seems to give all the fields in a nice long list, so I copy and pasted those into the API URL:
actor_id, actor_image_hash, actor_name, adlabels, applink_treatment,
body, call_to_action_type, dynamic_ad_voice, filename,
follow_redirect, id, image_crops, image_file, image_hash, image_url,
instagram_actor_id, instagram_permalink_url, link_deep_link_url,
link_url, name, object_id, object_store_url, object_story_id,
object_story_spec, object_type, object_url, place_page_set_id,
preview_url, product_set_id, template_url, thumbnail_url, title,
url_tag
So something like this (spaces are ok):
/v2.12/act_XXXXXXX/adcreatives/?fields=actor_id, actor_image_hash,
actor_name, adlabels, applink_treatment, body, call_to_action_type,
dynamic_ad_voice, filename, follow_redirect, id, image_crops,
image_file, image_hash, image_url, instagram_actor_id,
instagram_permalink_url, link_deep_link_url, link_url, name,
object_id, object_store_url, object_story_id, object_story_spec,
object_type, object_url, place_page_set_id, preview_url,
product_set_id, template_url, thumbnail_url, title,
url_tag&limit=100&effective_status=["ACTIVE"]
This gives me the full tree:
{
"data": [
{
"body": "XXXXXXX",
"call_to_action_type": "LEARN_MORE",
"id": "XXXXXXX",
"image_hash": "XXXXXXX",
"image_url": "XXXXXXX",
"instagram_actor_id": "XXXXXXX",
"instagram_permalink_url": "XXXXXXX",
"name": "#XXXXXXX",
"object_story_spec": {
"page_id": "XXXXXXX",
"instagram_actor_id": "XXXXXXX",
"video_data": {
"video_id": "XXXXXXX",
"title": "XXXXXXX",
"message": "XXXXXXX",
"link_description": "XXXXXXX",
"call_to_action": {
"type": "LEARN_MORE",
"value": {
"link_caption": "EXAMPLE.COM",
"link": "https://example.com/your-page",
"link_format": "VIDEO_LPP"
}
},
"image_hash": "XXXXXXX"
}
},
"object_type": "VIDEO",
"thumbnail_url": "XXXXXXX",
"title": "XXXXXXX"
},
So now I know it CAN be returned and most definitely is not write-only.
After playing some more I found that it's the SINGLE field object_story_spec that returns ALL this:
"data": [
{
"object_story_spec": {
"page_id": "XXXXXXX",
"instagram_actor_id": "XXXXXXX",
"video_data": {
"video_id": "XXXXXXX",
"title": "XXXXXXX!",
"message": "XXXXXXX",
"link_description": "XXXXXXX",
"call_to_action": {
"type": "LEARN_MORE",
"value": {
"link_caption": "EXAMPLE.COM",
"link": "https://EXAMPLE.COM/YOUR-WEBSITE-LINK",
"link_format": "VIDEO_LPP"
}
},
"image_hash": "XXXXXXX"
}
},
"id": "XXXXXXX"
},
So perhaps fields like link and object_id aren't for the type of ad I am using (mostly video with link to website) - or perhaps they are just for creating an ad - but I don't really care because now I have the data I need.
I'm using https://developers.facebook.com/tools/explorer for this