<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Error on update an UserSyncTask using Qlik QRS API in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Error-on-update-an-UserSyncTask-using-Qlik-QRS-API/m-p/1896611#M73992</link>
    <description>&lt;P&gt;Can you preview the Invoke lines using variables to make sure that your are constructing your requests correctly? A small syntax issue here can go unnoticed unless you inspect all variables throughout the script as it executes. Does the body inside $json object look like it should?&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 23 Feb 2022 14:46:25 GMT</pubDate>
    <dc:creator>Mario_Petre</dc:creator>
    <dc:date>2022-02-23T14:46:25Z</dc:date>
    <item>
      <title>Error on update an UserSyncTask using Qlik QRS API</title>
      <link>https://community.qlik.com/t5/App-Development/Error-on-update-an-UserSyncTask-using-Qlik-QRS-API/m-p/1896582#M73988</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;
&lt;P&gt;I'm trying to use the QRS API through Qlik-Cli on PowerShell to add a tag to an UserSyncTask, but got a 400 error.&lt;/P&gt;
&lt;P&gt;Below, a sequence of commands which I tried to add a tag to an UserSyncTask.&lt;/P&gt;
&lt;P&gt;Has someone got this issue?&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;PS C:\Users\user&amp;gt; $resp = Invoke-QlikGet -path /qrs/usersynctask/full -filter "name eq '99899_usersynctask'"

PS C:\Users\user&amp;gt; $resp


id                 : e497da37-f7d2-4907-8573-8bd68999dfdf
createdDate        : 2022/02/21 14:26
modifiedDate       : 2022/02/23 13:18
modifiedByUserName : QLIK-VM\user
customProperties   : {}
userDirectory      : @{id=47023d8a-71c1-4fc7-9994-aa4b9b0cc692; name=99899; 
                     type=Repository.UserDirectoryConnectors.ODBC.OdbcSql; privileges=}
operational        : @{id=d826cdea-29c9-4451-a898-f623f0a3e76b; lastExecutionResult=; nextExecution=2022/02/28 14:31; 
                     privileges=}
name               : 99899_usersynctask
taskType           : UserSync
enabled            : True
taskSessionTimeout : 1440
maxRetries         : 0
tags               : 
privileges         : 
schemaPath         : UserSyncTask




PS C:\Users\user&amp;gt; $tag = Get-QlikTag -filter "name eq '99899'"

PS C:\Users\user&amp;gt; $tag

id                                   name  privileges
--                                   ----  ----------
10cbbf94-9a92-4b5e-b7d5-d762acb43345 99899           



PS C:\Users\user&amp;gt; $resp.tags = $tag

PS C:\Users\user&amp;gt; $resp


id                 : e497da37-f7d2-4907-8573-8bd68999dfdf
createdDate        : 2022/02/21 14:26
modifiedDate       : 2022/02/23 13:18
modifiedByUserName : QLIK-VM\user
customProperties   : {}
userDirectory      : @{id=47023d8a-71c1-4fc7-9994-aa4b9b0cc692; name=99899; 
                     type=Repository.UserDirectoryConnectors.ODBC.OdbcSql; privileges=}
operational        : @{id=d826cdea-29c9-4451-a898-f623f0a3e76b; lastExecutionResult=; nextExecution=2022/02/28 14:31; 
                     privileges=}
name               : 99899_usersynctask
taskType           : UserSync
enabled            : True
taskSessionTimeout : 1440
maxRetries         : 0
tags               : @{id=10cbbf94-9a92-4b5e-b7d5-d762acb43345; name=99899; privileges=}
privileges         : 
schemaPath         : UserSyncTask




PS C:\Users\user&amp;gt; $json = $resp | ConvertTo-Json

PS C:\Users\user&amp;gt; Invoke-QlikPut -path "/qrs/usersynctask/$($resp.id)" -body $json
Invoke-RestMethod : The remote server returned an error: (400) Bad Request.
At C:\Program Files\WindowsPowerShell\Modules\Qlik-CLI\functions\core.ps1:66 char:23
+ ...            $result = Invoke-RestMethod @paramInvokeRestMethod @params
+                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExceptio 
   n
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Feb 2022 13:58:46 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Error-on-update-an-UserSyncTask-using-Qlik-QRS-API/m-p/1896582#M73988</guid>
      <dc:creator>José</dc:creator>
      <dc:date>2022-02-23T13:58:46Z</dc:date>
    </item>
    <item>
      <title>Re: Error on update an UserSyncTask using Qlik QRS API</title>
      <link>https://community.qlik.com/t5/App-Development/Error-on-update-an-UserSyncTask-using-Qlik-QRS-API/m-p/1896611#M73992</link>
      <description>&lt;P&gt;Can you preview the Invoke lines using variables to make sure that your are constructing your requests correctly? A small syntax issue here can go unnoticed unless you inspect all variables throughout the script as it executes. Does the body inside $json object look like it should?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Feb 2022 14:46:25 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Error-on-update-an-UserSyncTask-using-Qlik-QRS-API/m-p/1896611#M73992</guid>
      <dc:creator>Mario_Petre</dc:creator>
      <dc:date>2022-02-23T14:46:25Z</dc:date>
    </item>
    <item>
      <title>Re: Error on update an UserSyncTask using Qlik QRS API</title>
      <link>https://community.qlik.com/t5/App-Development/Error-on-update-an-UserSyncTask-using-Qlik-QRS-API/m-p/1896687#M73998</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/49970"&gt;@Mario_Petre&lt;/a&gt;!&lt;/P&gt;
&lt;P&gt;Thank you for your feedback.&lt;/P&gt;
&lt;P&gt;I don't know if that was what you're talking about preview lines, but Qlik-Cli allows the use of -Debug and -Verbose flags. By this way I could inspect the URL and JSON data in request body:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;PS C:\Users\user&amp;gt; Invoke-QlikPut -path "/qrs/usersynctask/$($resp.id)" -body $json -Debug -Verbose
VERBOSE: Raw output: 
VERBOSE: Adding header x-Qlik-Xrfkey: qzuoyhqnkgseqnaf
VERBOSE: {
    "id":  "e497da37-f7d2-4907-8573-8bd68999dfdf",
    "createdDate":  "2022/02/21 14:26",
    "modifiedDate":  "2022/02/23 13:18",
    "modifiedByUserName":  "QLIK-VM\user",
    "customProperties":  [

                         ],
    "userDirectory":  {
                          "id":  "47023d8a-71c1-4fc7-9994-aa4b9b0cc692",
                          "name":  "99899",
                          "type":  "Repository.UserDirectoryConnectors.ODBC.OdbcSql",
                          "privileges":  null
                      },
    "operational":  {
                        "id":  "d826cdea-29c9-4451-a898-f623f0a3e76b",
                        "lastExecutionResult":  {
                                                    "id":  "11147879-e125-4d0a-b660-82546aebcbc9",
                                                    "executingNodeName":  "server.company.com.br",
                                                    "status":  "FinishedSuccess",
                                                    "startTime":  "2022/02/21 14:31",
                                                    "stopTime":  "2022/02/21 14:31",
                                                    "duration":  10382,
                                                    "fileReferenceID":  "00000000-0000-0000-0000-000000000000",
                                                    "scriptLogAvailable":  false,
                                                    "details":  "   ",
                                                    "scriptLogLocation":  "",
                                                    "scriptLogSize":  -1,
                                                    "privileges":  null
                                                },
                        "nextExecution":  "2022/02/28 14:31",
                        "privileges":  null
                    },
    "name":  "99899_usersynctask",
    "taskType":  "UserSync",
    "enabled":  true,
    "taskSessionTimeout":  1440,
    "maxRetries":  0,
    "tags":  {
                 "id":  "10cbbf94-9a92-4b5e-b7d5-d762acb43345",
                 "name":  "99899",
                 "privileges":  null
             },
    "privileges":  null,
    "schemaPath":  "UserSyncTask"
}
VERBOSE: Calling Put for https://server.company.com.br:4242/qrs/usersynctask/e497da37-f7d2-4907-8573-8bd68999dfdf?xrfke
y=qzuoyhqnkgseqnaf
VERBOSE: PUT https://server.company.com.br:4242/qrs/usersynctask/e497da37-f7d2-4907-8573-8bd68999dfdf?xrfkey=qzuoyhqnkg
seqnaf with -1-byte payload
Invoke-RestMethod : The remote server returned an error: (400) Bad Request.
At C:\Program Files\WindowsPowerShell\Modules\Qlik-CLI\functions\core.ps1:66 char:23
+ ...            $result = Invoke-RestMethod @paramInvokeRestMethod @params
+                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExceptio 
   n
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The JSON displayed above is the same value in the $json variable - as expected.&lt;/P&gt;
&lt;P&gt;I validated the JSON generated and it seems to be OK.&lt;/P&gt;
&lt;P&gt;While analyzing the model for UserSyncTask endpoint (&lt;A href="https://help.qlik.com/en-US/sense-developer/November2021/APIs/RepositoryServiceAPI/index.html?page=1844" target="_blank" rel="noopener"&gt;https://help.qlik.com/en-US/sense-developer/November2021/APIs/RepositoryServiceAPI/index.html?page=1844&lt;/A&gt;), I noticed that the property "taskType" should be an Integer and I'm sending a String. However, even changing its "UserSync" by 2, the same error 400 is still getting in place.&lt;/P&gt;
&lt;P&gt;Do you know how to get more details besides the HTTP code, in order to get better understanding on what is wrong?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;José&lt;/P&gt;</description>
      <pubDate>Wed, 23 Feb 2022 17:03:44 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Error-on-update-an-UserSyncTask-using-Qlik-QRS-API/m-p/1896687#M73998</guid>
      <dc:creator>José</dc:creator>
      <dc:date>2022-02-23T17:03:44Z</dc:date>
    </item>
  </channel>
</rss>

