Highlighted
Respected Contributor.. Respected Contributor..
Respected Contributor..
458 views

"Messages": ["Key word \"attachments\" is missing."], "ReturnCode": 71 When updating via REST API

I'm attempting to update Service Manager request task fields via the following URL to a REST API and receive the response below from the web server.  Any ideas on how to troubleshoot or fix this would be appreciated.

{
  "Messages": ["Key word \"attachments\" is missing."],
  "ReturnCode": 71
}

An example URL (server and user name redacted for security purposes):

http://<servername>:13087/SM/9/rest/xcelrequesttasks/RFT00799645/action/Update System.Net.HttpWebRequest { "RequestTask": { "xcelDataCollectYesNo":"No", "ClosureCode":1, "ClosureComments":"Add user CN=<User Name>,OU=Minneapolis Service Region,OU=TCUsers,DC=corp,DC=xcelenergy,DC=net to or from group TCORP us-usr-inf-adm Adding user <domain username> to group TCORP us-usr-inf-adm was successful" }}

The section of the Powershell script calling this:

######################################
#Function to create the JSON object
######################################
function AddJsonToRequest {
 param($rq, $body);
 $bodyStream = $rq.GetRequestStream();
 $bodyWriter = New-Object System.IO.StreamWriter($bodyStream);
 $bodyWriter.Write($body);
 $bodyWriter.Close();
 $bodyStream.Close();

########################################
#Writing back to the HPSM Task record
########################################

$cred = "<username>:<password>";
$cred = [System.Text.Encoding]::GetEncoding("ISO-8859-1").GetBytes($cred);
$cred = [System.Convert]::ToBase64String($cred);
$url = ("{0}/SM/9/rest/xcelrequesttasks/{1}/action/Update" -f $baseHpsmUrl, $taskId);
$rq = [System.Net.WebRequest]::Create($url);
$rq.Method = "POST";
$rq.ContentType = "application/json";
$rq.Timeout = 100000;
$rq.ReadWriteTimeout = 100000;
$rq.Headers.Add("Authorization", "Basic " + $cred);

if($finalStatus -eq "ok") {
 $xcelDataCollectYesNo="No";
 $ClosureCode = '1';
} else {
 $xcelDataCollectYesNo="Yes";
 $ClosureCode = '3';
}

$ClosureComments = [string]::Join(" ", $comments);
$ClosureComments = $ClosureComments -replace '"', ""
$ClosureComments = $ClosureComments -replace '\\', ""

$body = '{{ "RequestTask": {{ "xcelDataCollectYesNo":"{0}", "ClosureCode":{1}, "ClosureComments":"{2}" }}}} ';
$body = ($body -f $xcelDataCollectYesNo, $ClosureCode, $ClosureComments );

AddJsonToRequest $rq $body
$rq.GetResponse();

0 Likes
2 Replies
Highlighted
Respected Contributor.. Respected Contributor..
Respected Contributor..

Re: "Messages": ["Key word \"attachments\" is missing."], "Return

Do I need to set up an external access record for this type of thing (update Service Manager from an external script)?

0 Likes
Highlighted
Knowledge Partner
Knowledge Partner

Re: "Messages": ["Key word \"attachments\" is missing."], "Return

You need to have the extaccess configured for this resource you are using.
Anothing thing I noticed is that the action must be in lowercase, regardless of how its configured in your extacces..
http://<servername>:13087/SM/9/rest/xcelrequesttasks/RFT00799645/action/Update
try to change to /update.
Regards,
Breno Abreu

If you feel this was helpful please click the KUDOS! thumb below!
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.