Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can add the "featured-image-by-url" in a post using the rest API? #49

Open
BaggioMarco opened this issue Jan 15, 2022 · 5 comments
Open
Labels
enhancement New feature or request

Comments

@BaggioMarco
Copy link

Hi,

I tried to create a new post using the REST API, but the "featured-image-by-url" doesn't not display.

I tried different endpoint like _knawatfibu_url, featured_image_urls, jetpack_featured_media_url but I had not luck.
I installed also the plugin "Rest API Custom Fields" that used to enable the custom field '_knawatfibu_url' under the 'post' section, but the image did not show up.

Below an example of code I was using.

imageURL = 'https://upload.wikimedia.org/wikipedia/it/f/fc/Pippo_Disney.png'

content= {
    "title": 'Hi',
    "content": 'My Content',
    "date": '2020-08-17T10:16:34',
    "featured_image": , # IMPORTANT
    '_knawatfibu_url': imageURL ,
    'featured_image_urls': imageURL ,
    'jetpack_featured_media_url': imageURL ,

}

thanks in advance

@BaggioMarco BaggioMarco added the enhancement New feature or request label Jan 15, 2022
@fernandogiacomino
Copy link

fernandogiacomino commented Jan 15, 2022

Marco, you must put urls in metadata, like here:

{"name": " your_productname ",
"type": "simple",
"sku": " your_productsku ",
"regular_price": " your_price ",
"manage_stock": true,
"on_sale": true,
"stock_quantity": your_stock,
"images": ""',
"short_description": " your_shortdescription ",
"description": "your_description ",
"slug": " your_productslug ",
"meta_data": [
{"key": "_knawatfibu_url", "value": " your_featuredimage_url " },
{"key": "_knawatfibu_wcgallary", "value": " your_galleryimage_url1, your_galleryimage_url2, your_galleryimage_url3 " },
]};

All names started with "your" are wildcards for your data. Pay special attention to quotation marks.

@BaggioMarco
Copy link
Author

Thanks @fernandogiacomino

I used your wocommerce example for a normal post, but the image is not showing up.
Here the code I used:

post = {
'title': 'Hi2',
'content': 'Content',
# "meta_data": [{"key": "_knawatfibu_url", "value":"https://upload.wikimedia.org/wikipedia/it/f/fc/Pippo_Disney.png"}],
"meta_data": {"key": "_knawatfibu_url", "value":"https://upload.wikimedia.org/wikipedia/it/f/fc/Pippo_Disney.png"},
'status': "publish",
}

I've tried also the commented line, but no luck.
I tried both with the "Rest API Custom Fields" enabled (with the field "_knawatfibu_url" checked) and disabled, but no luck.

What's wrong with my code? Thanks in advance

@BaggioMarco
Copy link
Author

@fernandogiacomino
Copy link

Yes, I didn't realize that your query was related to a Wordpress post and not a Woocommerce product. Greetings!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants
@fernandogiacomino @BaggioMarco and others