While I’ve found the solution, I’ve also created a python script to duplicate an entry from one local to another. I’m posting it here in case it could be useful to someone who need a scriptable tool.
import requests
import json
import sys, getopt
urlBase = "COPY HERE YOUR STRAPI URL BASE: https://strapi.mydomain.com/api"
token = "COPY HERE YOUR API KEY WITH WRITE ACCESS"
# ---------------
# --- duplicate
# ---------------
def duplicate(contentType, id, source, target):
url = urlBase +"/"+contentType+"s/"+id
print(url)
parameters = {"locale" : source, "populate" : "*"}
headers = {"Authorization": "Bearer "+token}
reponse = requests.get(url,params=parameters, headers=headers)
data = reponse.json()
print(json.dumps(data,indent=4))
# --- manipulate the data
data["data"]["attributes"]["locale"]=target
del data["data"]["attributes"]["createdAt"]
del data["data"]["attributes"]["updatedAt"]
del data["data"]["attributes"]["publishedAt"]
# --- create the same data for new locale
url = urlBase +"/"+contentType+"s/"+id+"/localizations"
reponse = requests.post(url,headers=headers,json=data["data"]["attributes"])
print(json.dumps(data,indent=4))
###############################
# --- MAIN
################################
def main(argv):
opts, args = getopt.getopt(argv,"hc:i:s:t:",["contentType=","contentTypeId=","localeSource=","localeTarget="])
for opt, arg in opts:
if opt == '-h':
print ('''python strapi-duplicate.py --contentType (or -c) <contentType> --contentTypeId (or -i) <id> --localeSource (or -s) <locale> --localeTarget (or -t) <locale>
ex: python strapi-duplicate.py -contentType article -contentTypeId 1 -localeSource fr -localeTarget en ''')
sys.exit()
elif opt in ("-c", "--contentType"):
contentType = arg
elif opt in ("-i", "--contentTypeId"):
id = arg
elif opt in ("-s", "--localeSource"):
source = arg
elif opt in ("-t", "--localeTarget"):
target = arg
else:
print("Error: unknown option "+opt)
sys.exit(1)
duplicate(contentType, id, source, target)
###############
# --- bootstrap to run as a script
###############
if __name__ == "__main__":
main(sys.argv[1:])
And some usage exemples :
python strapi-duplicate.py -h
python strapi-duplicate.py -c article -i 1 -s fr -t de
python strapi-duplicate.py -contentType article -contentTypeId 1 -localeSource fr -localeTarget en