I'm attempting to use the addResources operation to upload JSON confiuguration files (e.g., config.json, image-resources-list.json, etc.) to a programatically-created ExB app, and keep running into issues.
I've tried sending the JSON body in the Text parameter, sending the JSON body in the File parameter, sending as binary in the File parameter, all manner of encoding, and nothing works. I usually get a "Success" response from the addResources call, but when I attempt to list the item resources, they're empty.
I feel like I'm missing something obvious. Here's one version of my Python code:
import arcgis
from arcgis import GIS
import requests
gis = GIS('https://arcgis.com', username, password)
web_experience_item = gis.content.add(
{'type': 'Web Experience',
'title': 'New Experience',
'tags':'web experience'})
url = f"https://www.arcgis.com/sharing/rest/content/users/{username}/items/{web_experience_item.id}/addResources"
with open(f"{tempdir}//images//icon-resources-list.json", 'rb') as f:
data = {
"file": f, # also tried "text", also tried encoded json string
"fileName": "icon-resources-list.json",
"resourcesPrefix": "images",
"access": "inherit",
"token": token,
"f": "json"}
response = requests.post(url, data=data)
print(response.json()) # returns success
with open(f"{tempdir}//images//image-resources-list.json", 'rb') as f:
data = {
"file": f, # also tried "text", also tried encoded json string
"fileName": "image-resources-list.json",
"resourcesPrefix": "images",
"access": "inherit",
"token": token,
"f": "json"}
response = requests.post(url, data=data)
print(response.json()) # returns success
with open(f"{tempdir}//config//config.json", 'rb') as f:
data = {
"file": f, # also tried "text", also tried encoded json string
"fileName": "config.json",
"resourcesPrefix": "config",
"access": "inherit",
"token": token,
"f": "json"}
response = requests.post(url, data=data)
print(response.json()) # returns success
exb_item = gis.content.get(web_experience_id)
item_resources = exb_item.resources.list()
print(exb_resources) # empty list
response = requests.get(f"https://orgname.maps.arcgis.com/sharing/rest/content/items/{web_experience_id}/resources/config/config.json?f=json&token={token}")
print(response.json()) # 404 error because no resources exist