Skip to content

Commit 4e37cee

Browse files
Add script to check publish status, in "Use REST to update extension" (#3474)
* Update contact-extensions-team.md The form is irrelevant. Hence, removing * Update contact-extensions-team.md We are trying to remove email contact and guide all developers through GIthub * writer pass * Use Issues page specifically * add-on -> extension * h2 See also, GitHub: when use which * Sync Issues list & Discussions list w/ Readme * Discussing -> Discussions * focus Extension team or Other devs * link correct * Update addons-api-reference.md Example script added * format code listing * move script, heading * powershell * whitespace before -Method --------- Co-authored-by: Michael S. Hoffman <v-mihoffman@microsoft.com>
1 parent 36837d6 commit 4e37cee

2 files changed

Lines changed: 124 additions & 1 deletion

File tree

microsoft-edge/extensions-chromium/update/api/addons-api-reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ There are several responses, for different scenarios.
189189
###### Response when the operation fails with errors
190190

191191
```json
192-
{
192+
{
193193
"id": "{operationID}",
194194
"createdTime": "Date Time",
195195
"lastUpdatedTime": "Date Time",

microsoft-edge/extensions-chromium/update/api/using-addons-api.md

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,129 @@ See also:
546546
* [Check the publishing status](./addons-api-reference.md#check-the-publishing-status) in _REST API Reference for updating an extension at Microsoft Edge Add-ons_.
547547

548548

549+
<!-- ====================================================================== -->
550+
## Example: Check publication status and publish an extension with a PowerShell script
551+
552+
The following code is an example of a PowerShell script that uses the REST API to check the publication status of an extension, and publish that extension.
553+
554+
To use this script, fill in the `$ClientID`, `$ClientSecret`, `$ProductID`, and `$FilePATH` values at the top of the script.
555+
556+
```powershell
557+
Param(
558+
[string] $ClientID = '',
559+
[string] $ClientSecret = '',
560+
[string] $ProductID = '',
561+
[string] $FilePATH = '',
562+
[int] $RetryLimit = 10,
563+
[int] $RetryAfterPeriod = 5,
564+
[string] $ApiEndpoint = 'https://api.addons.microsoftedge.microsoft.com',
565+
[string] $PublishNotes = 'This is a test publish'
566+
)
567+
568+
function ReadKeyFromJSON($jsonContent, $keyToFetch){
569+
$jsonContent.TrimStart('{').TrimEnd('}').Split(',') |ForEach-Object {
570+
$key,$value = $_.Split(':')
571+
if($key.Trim('"') -eq $keyToFetch) {
572+
return $value.Trim('"')
573+
}
574+
}
575+
return ''
576+
}
577+
578+
function ReadLocationFromRawContent($jsonRawContent) {
579+
$jsonRawContent.Split([System.Environment]::NewLine, [System.StringSplitOptions]::RemoveEmptyEntries) | ForEach-Object {
580+
$key,$value = $_.Split(':')
581+
if ($key -eq 'Location') {
582+
return $value
583+
}
584+
}
585+
return ''
586+
}
587+
588+
$PublishNotesBody = @{
589+
notes = $PublishNotes
590+
}
591+
592+
$GetTokenHeaders = @{
593+
'Content-Type' = 'application/x-www-form-urlencoded'
594+
}
595+
596+
$UploadHeaders = @{
597+
"Authorization" = "ApiKey $ClientSecret"
598+
"Content-Type" = "application/zip"
599+
"X-ClientID" = "$ClientID"
600+
}
601+
602+
$uploadResponse = Invoke-WebRequest "$ApiEndpoint/v1/products/$ProductID/submissions/draft/package" -Headers $UploadHeaders -Method 'POST' -InFile $FilePATH
603+
604+
$uploadResponse
605+
606+
$uploadOperationId = ''
607+
608+
if($uploadResponse.StatusCode -eq 202) {
609+
"Upload Successful"
610+
$uploadOperationId = ReadLocationFromRawContent($uploadResponse.RawContent)
611+
}
612+
613+
$uploadStatusResponse = Invoke-WebRequest "$ApiEndpoint/v1/products/$ProductID/submissions/draft/package/operations/$UploadOperationId" -Headers $UploadHeaders -Method 'GET'
614+
615+
$uploadStatusResponse
616+
617+
$uploadStatus = 'InProgress'
618+
619+
if($uploadStatusResponse.StatusCode -eq 202) {
620+
"Upload Status Received Successfully"
621+
$retryCount = 1;
622+
while($uploadStatus -eq 'InProgress') {
623+
if($retryCount -gt $RetryLimit) {
624+
Exit-PSSession
625+
}
626+
$uploadStatusResponse = Invoke-WebRequest "$ApiEndpoint/v1/products/$ProductID/submissions/draft/package/operations/$UploadOperationId" -Headers $UploadHeaders -Method 'GET'
627+
$retryCount = $retryCount + 1
628+
Start-Sleep -Seconds $RetryAfterPeriod
629+
$uploadStatus = ReadKeyFromJSON($uploadStatusResponse.Content, 'status')
630+
}
631+
}
632+
633+
$publishResponse = Invoke-WebRequest "$ApiEndpoint/v1/products/$productID/submissions" -Headers $UploadHeaders -Method 'POST' -Body $PublishNotesBody
634+
635+
$publishResponse
636+
637+
$PublishOperationId = ''
638+
639+
if($publishResponse.StatusCode -eq 202) {
640+
"Published Successfully"
641+
$PublishOperationId = ReadLocationFromRawContent($publishResponse.RawContent)
642+
}
643+
644+
$PublishOperationId
645+
646+
$publishStatusResponse = Invoke-WebRequest "$ApiEndpoint/v1/products/$ProductID/submissions/operations/$PublishOperationId" -Headers $UploadHeaders -Method 'GET'
647+
648+
$publishStatusResponse
649+
650+
$publishStatus = 'InProgress'
651+
652+
$publishStatusResponse.Content
653+
654+
if($publishStatusResponse.StatusCode -eq 202) {
655+
"Publish Status Received Successfully"
656+
$retryCount = 1;
657+
while($publishStatus -eq 'InProgress') {
658+
if($retryCount -gt $RetryLimit) {
659+
Exit-PSSession
660+
}
661+
$publishStatusResponse = Invoke-WebRequest "$ApiEndpoint/v1/products/$ProductID/submissions/operations/$PublishOperationId" -Headers $UploadHeaders -Method 'GET'
662+
$retryCount = $retryCount + 1
663+
Start-Sleep -Seconds $RetryAfterPeriod
664+
$publishStatus = ReadKeyFromJSON($publishStatusResponse.Content, 'status')
665+
}
666+
}
667+
668+
$publishStatus
669+
```
670+
671+
549672
<!-- ====================================================================== -->
550673
## See also
551674
<!-- all links in article -->

0 commit comments

Comments
 (0)