MicrosoftDocs / edge-developer

Developer documentation for Edge.
https://learn.microsoft.com/microsoft-edge/developer/
Creative Commons Attribution 4.0 International
377 stars 506 forks source link

Resource not found when uploading my extension #3091

Closed dbeilin closed 4 months ago

dbeilin commented 4 months ago

I'm trying to update my dummy Extension using Edge's store API:

import os
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 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("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}/products/{EDGE_PRODUCT_ID}/submissions/draft/package/operations/{operation_id}"
    response_status = requests.get(check_status_url, headers=headers)
    logging.info(response_status.text)
    return response

if __name__ == "__main__":
    upload_extension(fetch_access_token(), "confetti-extension.zip")

The above script returns:

2024/03/07 15:22:01 - INFO: url: https://api.addons.microsoftedge.microsoft.com/v1/products/7d7aaf64-f935-454b-b912-a05ba24685fa/submissions/draft/package
2024/03/07 15:22:01 - INFO: status code: 202
2024/03/07 15:22:01 - INFO: operation id: 7c9a8bc9-79d3-4a04-bd95-879df7509556
2024/03/07 15:22:02 - INFO: { "statusCode": 404, "message": "Resource not found" }

I double checked all of my details like the Product ID, Client key/secret, and everything seems to be correct, but no matter what, I still get a Resource not found error when I try to upload my ZIP file.

I'm following their docs but it seems I'm still doing something wrong.

captainbrosset commented 4 months ago

Thanks for raising this issue. But I would suggest creating this issue again on the https://github.com/microsoft/microsoftEdge-Extensions/ repository instead, for example by using the Discussions tab on that repo. This repo here is only about the documentation of the API, not its implementation.

Hope that makes sense!