Purview API Create glossary terms - azure-purview

I am trying to reference the following page
https://learn.microsoft.com/en-us/rest/api/purview/catalogdataplane/glossary/create-glossary-term?tabs=HTTP
$glossarytermcreateendpoint = 'https://pv-chn-asiabi-sea-dev.purview.azure.com/catalog/api/atlas/v2/glossary'
$Glossaryterm = #{
qualifiedName = "sample"
name= "sample"
longDescription = "sample"
shortDescription = "sample"
status = "Draft"
}
$jsonbody = $Glossaryterm | ConvertTo-Json
$Responsepost = Invoke-WebRequest -Uri $glossarytermcreateendpoint -Method Post -headers $headers -Body $jsonbody -ContentType 'application/json'
I am ok to get status 200
however in the Purview workspace , I can't find the new term is created
Questions
How to make it works? Able to search ?
How to create a glossary term under specific term template .?

$glossarytermcreateendpoint = 'https://pv-chn-asiabi-sea-dev.purview.azure.com/catalog/api/atlas/v2/glossary'
From your script, I noticed that the API you called is to create a glossary, not a term, so you can't find the new term you created.
The right API to create a term is to append /term to the end of your current API:
$glossarytermcreateendpoint = 'https://pv-chn-asiabi-sea-dev.purview.azure.com/catalog/api/atlas/v2/glossary/term'
Let me know if this solves your problem.

Related

Body is not deserialize from powershell call

I have an error with powershell api call.
This is my powershell code :
$body='[{"Criteres":[{"Nom":"Code","Valeur":"lyon"},{"Nom":"Libellé","Valeur":"lyon test"}],"Nom":"X_Site_Geogr","Pseudo":"Site Géographique"}]'
$url="http://localhost/api/OccObjets/"
$Responseappli = Invoke-WebRequest -URI $url -Method "PUT" -Body $body -ContentType "text/json" -UseDefaultCredentials
Write-Output $Responseappli.Content
This is controller method :
[HttpPut]
public IHttpActionResult Put([FromBody] IEnumerable<TOObjetAvecCriteres> listeOccurrence)
If i use the same body on Postman or swagger, it works perfectly but with powershell, my list is null.
I add a handler to get raw body with that :
var bodyStream = new StreamReader(HttpContext.Current.Request.InputStream);
bodyStream.BaseStream.Seek(0, SeekOrigin.Begin);
var bodyText = bodyStream.ReadToEnd();
var test = JsonConvert.DeserializeObject<IEnumerable<TOObjetAvecCriteres>>(bodyText);
body powershell :
"[{\"Criteres\":[{\"Nom\":\"Code\",\"Valeur\":\"lyon\"},{\"Nom\":\"Libell�\",\"Valeur\":\"lyon test\"}],\"Nom\":\"X_Site_Geogr\",\"Pseudo\":\"Site G�ographique\"}]"
body swagger :
"[{\"Criteres\":[{\"Nom\": \"Code\",\"Valeur\": \"lyon\"},{\"Nom\": \"Libellé\",\"Valeur\": \"lyon test\"}],\"Nom\": \"X_Site_Geogr\",\"Pseudo\": \"Site Géographique\"}]"
Deserialization in handler works whith both powershell and swagger but in my controller function, listeOccurrence variable is null with powershell.
I aslo try to write body like this an convert to json but it doesn't work :
$body=#(
#{
"Nom"="X_Site_Geogr"
"Pseudo"="Site Géographique"
"Criteres"= #(
#{
"Nom"="Code"
"Valeur"="lyon"
}
#{
"Nom"="Libellé"
"Valeur"="lyon test2"
}
)
}
)
Do you have any idea ?
Thanks for your help

Powershell - Invoke-RestMethod - POST nested JSON

I'm trying to interact with an API to POST some data to a service we use, in order to add some email addresses to a policy. This will eventually take a list of email addresses and loop through it for each one, but for now I'm just trying to get it to work with a single address.
I'm using Powershell 7, I would say I'm intermediate with powershell, but this is my first foray into interacting with an API, using JSON, and using the Invoke-RESTMethod commandlet. The API reference for the service shows lots of code examples in other languages, just not PS!
Here's the problem I'm running in to. I'm trying to formulate a -Body statement that looks to be 3 elements instead of two. Here is what that example statement looks like in CURL:
{
"custodians": [
{
"emailId": "john.doe#someorg.com"
}
],
"action": "add"
}
The Action:Add part is fine, easy peasy. I'm trying to figure out how to correctly format the custodians part. I cant figure out how to do 3 elements instead of two. I've tried different combinations of {} [] and () to no avail:
"custodians" = ({"emailId" = "emailaddress#place.com"})
gives me an "The assignment expression is not valid" error
"custodians" = [{"emailId" = "emailaddress#place.com"}]
and
"custodians" = [#{"emailId" = "emailaddress#place.com"}]
give me an "Missing type name after '['." error.
These, as well as a few other combinations I've typed out, all showed formatting errors in VSCode so I already knew they wouldn't work, I'm just not sure why. I'm sure I just haven't cracked the right combination of #, {}, [] or () but I cant seem to find any info online (probably because I'm not using the right vocabulary or phrasing in my searches) that shows how to format with three elements.
If its relevant or helpful, here is a larger code sample of the whole query Im working on. Assume the Auth headers are fine (I can request my auth tokens and do GETs without issue so far):
$headers = #{
"Authorization" = $bearerAuthValue
"Accept" = "application/json"
"Content Type" = "application/json"
}
$body = #{
"custodians" = #(emailId = "emailaddress#place.com"),
"Action" = "add"
}
$uri = "https://thisisanaddress.com"
Invoke-RestMethod -Method 'POST' -Uri $uri -Headers $headers -Body $body
You are looking at having multiple emailids in custodians?
$body = #{
custodians = #(
#{emailId = 'emailaddress#place.com' }
#{emailId = 'emailaddress#place.com' }
#{emailId = 'emailaddress#place.com' }
)
Action = 'add'
}
Output:
$body | ConvertTo-Json
{
"Action": "add",
"custodians": [
{
"emailId": "emailaddress#place.com"
},
{
"emailId": "emailaddress#place.com"
},
{
"emailId": "emailaddress#place.com"
}
]
}

Syntax for groovy to duplicate PowerShell Invoke-RestMethod

I'm trying to duplicate the PowerShell Invoke-RestMethod to something similar in Groovy (groovy is standard we use in our coded pipeline).
I've done a lot of searching without success. I was wondering if I can get some help or suggestions on a possible alternative if there isn't a similar call?
The 3 three lines of PowerShell I'm trying to duplicate in Groovy are:
$tokenrequest = #{ "grant_type" = "password"; "username" = "adminuser"; "password" = "adminpassword" }
$token = Invoke-RestMethod -Uri "http://abcd.com/executionmanager/api/Token" -ContentType application/x-www-form-urlencoded -Headers #{ Authorization = ("OAuth2")} -Method POST -Body $tokenrequest
$token = $token.access_token
there are a lot of libraries to do that
the following one quite unknown
//download dependency from maven repository
#Grab(group='acme.groovy', module='acmehttp', version='20180403')
import groovyx.acme.net.AcmeHTTP
def ctx = AcmeHTTP.post(
url: "https://httpbin.org/post", //the url could be used for tests
//define body as map as soon as we are sending it as www-form
body: [ "grant_type": "password", "username": "adminuser", "password": "adminpassword" ],
headers:[
"content-type":"application/x-www-form-urlencoded",
"Authorization": "OAuth2"
],
)
assert ctx.response.code==200
//the url https://httpbin.org/post always returns json
assert ctx.response.contentType =~ "/json"
assert ctx.response.body instanceof Map
println ctx.response.body
//i guess your token should be accessible like this:
//println ctx.response.body.access_token

Powershell HTTP POST method within same session

I have a limited understanding in html, i am trying to automate a form filling like the following:
$JSONLOGIN = #'
{"#type":"login",
"email":"xxx#xxx.com",
"password":"xxxx"
}
'#
$response = Invoke-RestMethod -Uri "http://xxxxxxx/api/users/login" -Method Post -Body $JSONLOGIN -ContentType "application/json"
$response
$JSONADDRATE = #'
{
"#type":"add",
"supplierRef":"S020893",
"buyerRef":"520170509082555",
"fiRef":"7769",
"rateDate":"2017-09-15T14:11:04.684Z",
"rateType":"fixedRate",
"spFee":2,
"comFee":1,
"fiMarginOver":3,
"ttofc":0,"isTtofc":false,
"fixedRate":2,"primeLiborRate":0,
"oneWTenorRate":0,
"oneMTenorRate":0,
"twoMTenorRate":0,
"threeMTenorRate":0,
"sixMTenorRate":0,
"nineMTenorRate":0,
"oneYTenorRate":0}
'#
$response2 = Invoke-RestMethod -Uri "http://xxxxxxx/api/ubiq/rates/add" -Method Post -Body $JSONADDRATE -ContentType "application/json"
$response2
The responses are returning like that:
$response
isSessionValid : True
data : #{email=xxx#xxxx.com; id=5988ad267520a62df46af0a4; name=xxx Back Office}
isSuccessful : True
isError : False
isAllowed : True
message
$response2
isSessionValid : False
data :
isSuccessful : False
isError : False
isAllowed : False
message
Obviously the login session is being lost when jumping into the second link (Hence isSessionValid: false), how can i keep the session alive?
The -SessionVariable parameter creates a Web Request Session Object basically saving your session in the current PowerShell session.
In order to take advantage of that try this:
In the first Request add a -SessionVariable parameter and give it a string
(any string without the preceding $) then in second Request pass that string
(this time with a preceding $) to the -WebSession parameter.

Corrupt Documents in new DocuSign envelope

I'm doing a POC to demonstrate DocuSign programmatically creating and routing an envelope containing a simple document. I'm using PowerShell and the JSON API. Login and the Create Envelope work without complaint, but the resulting Word doc routed to me for signature contains gibberish. I believe I have the base64 encoding and headers right. Any thoughts about what I'm doing wrong?
The entire POC is pasted below. I've just removed the ID, Password, Integrator Key, etc. Thanks!
function boundry {
[System.Guid]::NewGuid().ToString()
}
###this is the corrected code###
function encodeFile {
param ([string]$fileName)
[System.Convert]::ToBase64String([IO.File]::ReadAllBytes((Resolve-Path $fileName).ProviderPath))
}
function logonParams {
[string] $userName = 'DocuSign user name'
[string] $password = 'DocuSign password'
[string] $integratorKey = 'DocuSign Integrator Key'
#"
{
"Username" : "$userName",
"Password" : "$password",
"IntegratorKey" : "$integratorKey"
}
"#
}
function logon {
[string] $loginURL = 'https://demo.docusign.net/restapi/v2/login_information'
$headers =
#{
"X-DocuSign-Authentication"=$(logonParams);
"accept"="application/json";
"content-type"="application/json";
}
$r = Invoke-WebRequest -uri $loginURL -headers $headers -method GET
$responseInfo = $r.content | ConvertFrom-Json
$baseURL = $responseInfo.loginAccounts.baseURL
#return the base URL for the next call
$baseURL
}
function createEnvelope {
param ([string]$file1,
[string]$baseURL
)
[string]$boundry = boundry
$headers =
#{
"X-DocuSign-Authentication"=$(logonParams);
"accept"="application/json";
"content-type"="multipart/form-data; boundary=$boundry";
}
[string]$formData = #"
--$boundry
Content-Type: application/json
{
"status":"sent",
"emailBlurb":"Please sign.",
"emailSubject": "Contract $(date)",
"documents": [{
"name": "$file1",
"documentId":"1",
"order":"1"
}],
"recipients": {
"signers" : [{
"email": "recipient#somecompany.com",
"name": "Recipient Name",
"recipientId":"1",
}]
}
}
--$boundry
Content-Type: application/msword
Content-Transfer-Encoding: base64
Content-Disposition: file; filename="$file1";documentid=1
$(encodeFile $file1)
--$boundry--
"#
$envelopeURL = "$baseURL/envelopes"
Invoke-WebRequest -uri $envelopeURL -headers $headers -body $formData -method POST
}
$baseURL = logon
createEnvelope "test.doc" $baseURL
Try changing your Content-Type header value. I'm not sure if application/msword works here, I think the proper mime-type for .docx is
application/vnd.openxmlformats-officedocument.wordprocessingml.document
See this previous SO post for a more complete list of mime-types:
What is a correct mime type for docx, pptx etc?
I solved it with assistance from the DocuSign support team. You can enable server side logging in DocuSign which is very helpful. From the old UI (not available in new UI as of June '15) choose Preferences from the dropdown next to your ID/photo. Then select Permissions under Member Options on the left. Check "Enable API Request Logging." After you run your test, the Download API Request Logs button becomes active.
It was pretty clear from the logs that my encoding was wrong. Here's the correct version:
function encodeFile {
param ([string]$fileName)
[System.Convert]::ToBase64String([IO.File]::ReadAllBytes((Resolve-Path $fileName).ProviderPath))
}
I've updated this in the original code with the question so feel free to use it.