Hi!
I’m trying to add a coupon with API at the moment of create a post but the meta field is empty. I can create a post correctly using REST API but, I can only fill normal fields, not the one created by your theme.
I have installed a plugin called "REST API Custom Fields" which allows me to show meta fields in API REST calls, but, I can only read but not fill in the moment I create the post.
My Python code:
##############
import requests
import json
import base64
url = "https://xxxxxxxx.com/wp-json/wp/v2"
user = "user"
password = "applicationpass"
credentials = user + ':' + password
token = base64.b64encode(credentials.encode())
header = {'Authorization': 'Basic ' + token.decode('utf-8')}
# Just an image upload
media = {
'file': open('imagen.jpg', 'rb'),
'caption': 'First API Image',
'description': 'First API Image'
}
image = requests.post(url + '/media', headers=header, files=media)
imageURL = str(json.loads(image.content)['source_url'])
imageID = str(json.loads(image.content)['id'])
meta = {
"rehub_offer_product_coupon": "CUPONAPI",
"other_meta_fields": "value"
}
post = {
"date": "2021-10-22T08:32:00",
"title": "Test post",
"content": "test content with image id " + imageID + " and image URL " + imageURL,
"status": "publish",
"meta": meta,
"featured_media": imageID
}
responce = requests.post(url + '/posts' , headers=header, json=post)
print(responce)
print(responce.json())
#####################
Is there anything I missing to be able to create post with all fields filled?
Let me know if you need credentials or my problem can be solved without access to site.
Thanks!
That is a good idea and will help others like me. Now I can use all fields with my scripts :)
Congrats for your theme, is really amazing