Skip to main content
Announcements
Accelerate Your Success: Fuel your data and AI journey with the right services, delivered by our experts. Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Richard_Smith_Uchotski
Contributor II
Contributor II

Automatic ODAG link generation: Can not post to qlik Server

Dear Qlik Users, 

I have been tasked with the autodeployment of ODAG links, in the Qlik Sense Enterprise on Windows. I am able to write a get request to get the odag links from the server, a post request to generate a new link on the server, but I can not update the links that are already there, I just get either a 409 or 400 error. 

My current code is: 

$certPathAndName = "\\Cert\certificate.pfx"
$cert = Get-PfxCertificate -FilePath $certPathAndName
$hdrs = @{}
$hdrs.add("X-Qlik-User","UserDirectory=INNER;UserId=Richard")
$url = 'https://myserver.com:9098/v1/links/4e286502-45bf-4130-bfeb-d5e2c35d95eb'

 

$body = '{
"modifiedDate" : "2017-08-07T09:35:16.011Z"
}'

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12
$resp = Invoke-RestMethod -Uri $url -Method Put -Headers $hdrs -Body $body -ContentType 'application/json' -Certificate $cert
$resp.objectDef.id


Firstly, can some explain what the structure of the payload for the put should be. All I can find is:  the endpoint is 
'https://myserver.com:9098/v1/links/4e286502-45bf-4130-bfeb-d5e2c35d95eb' and the documents for the put say the payload should contain: 

Request Body

A JSON payload containing the contents to use for updating an existing link.

Name Type Required
modifiedDate LinkModifyPayload Yes
name LinkModifyPayload  
templateApp LinkModifyPayload  
dynamicView LinkModifyPayload  
rowEstExpr LinkModifyPayload  
statusSetting LinkModifyPayload  
bindings LinkModifyPayload  
properties LinkModifyPayload  
modelGroups LinkModifyPayload


Also, I do not understrand the authentication process, on the get request I can authenticate just using an xrfx key, but on the post request I need to use a certificate, and now on the put I am unsure. Is it okay to use -UseDefaultUser in the invoke-RestMethod, am I meant to be adding users to the headers of the request, what combination of auth and user shoudl work?

Qlik Sense Enterprise on Windows  @Damien_V 




Labels (4)
1 Reply
Richard_Smith_Uchotski
Contributor II
Contributor II
Author

I have half solved this myself - I thought that using the id of the navigation link 89762c75-d6be-4d17-a782-39f9c8a79b16 would be specific enough, but you also need the most recent modified date on that link too, so if you have the JSON object from your ODAG you need to take the most recent modified date from that and put in your payload - it has to be that specific date, not just a random one. 


$url = 'https://myserver/api/odag/v1/links'

$hdrs = @{}

$hdrs.Add("X-Qlik-xrfkey","12345678qwertyui")

$odagLinks2 = Invoke-RestMethod -Uri $url -Method Get -Headers $hdrs -UseDefaultCredentials

$odagLinks2 | Where-Object {$_.name -eq 'Changed it Magic'} | ConvertTo-JSON | Out-File -FilePath .\byname.Json

This returns on object by the ODAG name, and basically, I take the modified date from that, and use it in my payload for the odag put request, so you will need the ID from the ODAG link, as well as the last modified date from the ODAG link for the put to work! 

So, when it says requires the modifiedDate, it needs the modified date from the backend for that id.