Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I am trying to update my ODAG links in the backend, and I am using the PUT method for the endpoint PUT /links/{linkId}. However, I keep geting a 409 error: System.Net.WebException: The remote server returned an error: (409) Conflict. or Invoke-RestMethod : {"message":"The update conflicts with another update and could not be completed.","statusCode":409,"msgCode":"ODAG-ERR-1042","errType":"Calling Application"}. From what I understand, the issue is coming becuse the date format is incorrect for the modified date payload - but how would I format this to get it to update on the server?
This is all I can get from the very porr Qlik API documentation:
Name | Description | Type |
---|---|---|
statusCode |
The HTTP status code for the error. Generally speaking, the following codes have these meanings: 200 - Success, 201 - Success (object created), 400 - Error with user input, 403 - Authorization error (user lacks permission), 404 - Object not found, 409 - Attempt to change an object using an obsolete last ModifiedDate. |
Integer |
try
{
$certPathAndName = "\\Cert\dev.pfx"
$cert = Get-PfxCertificate -FilePath $certPathAndName
$hdrs = @{}
$hdrs.add("X-Qlik-User","UserDirectory=INTRANET;UserId=Richard")
$url = 'https://myserver.com:9098/v1/links/4e286502-45bf-4130-bfeb-d5e2c35d95eb'
$url
$modifiedDate = [DateTime]::ParseExact("2023-10-30T15:35:25.223Z", "yyyy-MM-ddTHH:mm:ss.fffZ", $null)
$futureDate = (Get-Date).AddDays(2).ToString("yyyy-MM-ddTHH:mm:ss.fffZ")
$modifiedDate
$futureDate
# $modfiedDate Output # 30 October 2023 15:35:2
# $futureDate Output ##2023-11-11T12:24:50.244
$body = '{"modifiedDate" : "' + $modifiedDate + '"}'
[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
}
catch {
write-error "Error : $($_.Exception)"
write-error "Error : $($_.Exception.Message)"
}
Does anyone know what format modified dat is in, I have tried different types and nothing seems to be working?
Ok, 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!
Ok, 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!
I will add some get functions later, that will autofill/get the parts needed!