-
Hello, I'm trying to figure out why my publishing function is not working properly. import os
import time
import json
import requests
import logging
from dotenv import load_dotenv
load_dotenv()
EDGE_PRODUCT_ID = os.getenv("EDGE_PRODUCT_ID")
EDGE_CLIENT_ID = os.getenv("EDGE_CLIENT_ID")
EDGE_CLIENT_SECRET = os.getenv("EDGE_CLIENT_SECRET")
EDGE_ACCESS_TOKEN_URL = os.getenv("EDGE_ACCESS_TOKEN_URL")
EDGE_API_ENDPOINT = "https://api.addons.microsoftedge.microsoft.com"
logging.basicConfig(
format="%(asctime)s - %(levelname)s: %(message)s",
datefmt="%Y/%m/%d %H:%M:%S",
level=logging.INFO,
)
def check_for_status(url, headers):
while True:
try:
response = requests.get(url, headers=headers, timeout=10)
response.raise_for_status()
status = response.json().get("status")
if status != "InProgress":
break
logging.info("Status is still InProgress. Waiting for 5 seconds...")
time.sleep(5)
except (
requests.exceptions.Timeout,
requests.exceptions.RequestException,
) as err:
logging.error("Error occurred: %s", err)
raise
def fetch_access_token():
url = EDGE_ACCESS_TOKEN_URL
headers = {"Content-Type": "application/x-www-form-urlencoded"}
data = {
"client_id": EDGE_CLIENT_ID,
"client_secret": EDGE_CLIENT_SECRET,
"grant_type": "client_credentials",
"scope": "https://api.addons.microsoftedge.microsoft.com/.default",
}
token_data = requests.post(url, headers=headers, data=data).json()
return token_data["access_token"]
def upload_extension(access_token, package_path):
url = f"{EDGE_API_ENDPOINT}/v1/products/{EDGE_PRODUCT_ID}/submissions/draft/package"
headers = {
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/zip",
}
with open(package_path, "rb") as package_file:
file = package_file.read()
response = requests.post(url, headers=headers, data=file, timeout=20)
operation_id = response.headers.get("Location")
logging.info("Upload URL: %s", url)
logging.info("status code: %s", response.status_code)
logging.info("operation id: %s", operation_id)
# Check upload status
check_status_url = f"{EDGE_API_ENDPOINT}/v1/products/{EDGE_PRODUCT_ID}/submissions/draft/package/operations/{operation_id}"
check_for_status(check_status_url, headers)
response_status = requests.get(check_status_url, headers=headers)
logging.info(response_status.text)
return response
def publish_extension(access_token):
url = f"{EDGE_API_ENDPOINT}/v1/products/{EDGE_PRODUCT_ID}/submissions"
headers = {"Authorization": f"Bearer {access_token}"}
data = {"notes": ""}
response = requests.post(url, headers=headers, json=json.dumps(data), timeout=20)
operation_id = response.headers.get("Location")
# Check for the status of the publish operation
get_status_url = f"{EDGE_API_ENDPOINT}/v1/products/{EDGE_PRODUCT_ID}/submissions/operations/{operation_id}"
check_for_status(get_status_url, headers)
response_publish = requests.get(get_status_url, headers=headers)
logging.info(response_publish.text)
if __name__ == "__main__":
upload_extension(fetch_access_token(), "extension.zip")
publish_extension(fetch_access_token()) The output from running this is:
So it seems like the upload is fine, but when it tries to publish the extension, it treats it as a new extension instead of an existing one. Any help would be appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I just manually published my extension and ran the script again:
I guess it means Edge expects the extension to be approved at least once? |
Beta Was this translation helpful? Give feedback.
-
Hey @dbeilin, Sorry for the delay. We are looking into this and will let you know as soon as we have an update. |
Beta Was this translation helpful? Give feedback.
I just manually published my extension and ran the script again:
I guess it means Edge expects the extension to be approved at least once?