Skip to content

Commit

Permalink
Snippet - adding tssapi for a generic oauth2 token and API call
Browse files Browse the repository at this point in the history
  • Loading branch information
wsmelton committed Mar 18, 2021
1 parent aa75be9 commit 7e0e0f5
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .vscode/tss.code-snippets
Original file line number Diff line number Diff line change
Expand Up @@ -612,5 +612,26 @@
" ${4:Function name utilizing it, list multiple if it applies}"
],
"description": "template for the about_classname_help.txt files"
},
"Generic API call": {
"prefix": "tssapi",
"body": [
"\\$SecretServerHost = '${1:SS URL}'",
"\\$apiUrl = \"${1}/api/v1\"",
"",
"\\$Body = @{",
" \"grant_type\" = \"password\"",
" \"username\" = '${2:Username}'",
" \"password\" = '${3:Password}'",
"}",
"\\$token = Invoke-RestMethod -Method Post -Uri \"\\$SecretServerHost/oauth2/token\" -Body \\$Body",
"\\$headers = New-Object \"System.Collections.Generic.Dictionary[[String],[String]]\"",
"\\$headers.Add(\"Authorization\", \"Bearer \\$(\\$token.access_token)\")",
"",
"\\$url = \"\\$apiUrl/${4:endpoint and params}\"",
"Invoke-RestMethod -Method ${5:Method} -Uri \\$url -Headers \\$headers",
""
],
"description": "Generic API call"
}
}

0 comments on commit 7e0e0f5

Please sign in to comment.