cancel
Showing results for 
Search instead for 
Did you mean: 

Archer API - Create Sub-Forms error - Powershell

DonaldDanielson
Contributor III

I'm getting an error when trying to create a new sub-form record.

Sub-Form has a couple dates, and a couple text fields.   Its basically a comment form, attached to another application.  I believe I have the format correct, Level ID is from the Sub-Form, and the SubFormFieldID is from the parent application.

 

{ "Content": { "LevelId": 498, "FieldContents": {
"20196": { "Type": 1, "Value": "Test Message" , "FieldId": 20196 },
"20195": { "Type": 3, "Value": "3/31/2020", "FieldId": 20195 },
"20197": { "Type": 3, "Value": "12/1/2019", "FieldId": 20197 },
"20198": { "Type": 1, "Value": "", "FieldId": 20198 }
}},"SubFormFieldId": 20199 }

$results = Invoke-RestMethod -Method POST -Uri $api_url -Body $body -Headers $headers -ContentType "application/json" -WebSession $sess

 

Status : ProtocolError
Response : System.Net.HttpWebResponse
Message : The remote server returned an error: (400) Bad Request.
Data : {}
InnerException :
TargetSite : System.Net.WebResponse GetResponse(System.Net.WebRequest)
StackTrace : at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request)
at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()
HelpLink :
Source : Microsoft.PowerShell.Commands.Utility
HResult : -2146233079

 

Looking in the web server logs, I do see an error "Can't save contents from different levels", but I am not completely sure they are related.   All the fields within the body are from the sub-form, except the once from the SubFormFieldID

Also, is there a specific log to look in for API errors ?

 

4 REPLIES 4

Ilya_Khen
Champion III

DonaldDanielson,

How did you get LevelID? Because it is not the same as moduleID.

Also, you could try over SOAP call just to test:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchemainstance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <CreateSubformRecord xmlns="http://archer-tech.com/webservices/">
      <sessionToken>AE6936AAC5FF08260C3FBA715F810594</sessionToken>
      <subformModuleId>int</subformModuleId>
      <subformFieldId>int</subformFieldId>
      <fieldValues>
        <![CDATA[xmlstring]]>
      </fieldValues>
    </CreateSubformRecord>
  </soap:Body>
</soap:Envelope>

DavidPetty
Archer Employee
Archer Employee

@DonaldDanielson, you have to create the record first (/api/core/content/), then the ID you get back would be it's content/tracking ID  which would be used to update the parent record sub-form ID with that ID.

 Advisory Consultant - Archer, an RSA Business

This is my attempt at the first step to create the record, I'm not making it to the second part yet since I am not getting a record ID returned.  This one seems unique in the sense of the additional SubFormFieldID in the body, as compared to all the other examples.

 

Following this template.  I have gotten other content creates and updates to work, this is my first attempt at sub-forms though.

###########################################################################################################################################
# CREATE a Sub-Form Record and save the Sub-Form Content Id to be used below. 
#      192 = Sub-Form Level Id
#    13884 = Text field in the Sub-Form
#    13886 = Sub-Form field in the parent app
###########################################################################################################################################
try {
    $api_url = $base_url + "/api/core/content"
    $body = 
    '{"Content": {
        "LevelId": 192, "FieldContents": {
        "13884": { "Type": 1, "Value": "Subform created via REST API", "FieldId": 13884 }
    }}, "SubformFieldId": 13886}'
    $results = Invoke-RestMethod -Method POST -Uri $api_url -Body $body -Headers $headers -ContentType "application/json" -WebSession $sess
    if ($results.IsSuccessful -and $results.ValidationMessages.count -eq 0) {
        $results
        $subform_id = $results.RequestedObject.Id
    }
    else {
        $results.ValidationMessages
    }
}
catch { $_.Exception|Format-List -Force }
finally { $results = $null }

 

I normally use one of the API calls to get the list;

I was using the wrong one in the code I pasted, but I had been switching back and forth to see I had that wrong.  It is 298

Id Guid ModuleId Name Description
-- ---- -------- ---- -----------
10 8faed204-3bcb-4519-a382-1ff76dc0a026 335 Vendors The Vendors level contains information relati...
11 67444794-5236-4f99-8ae4-19bf8e6411d1 335 Technologies The Technologies level contains information r...
12 853d2fa2-eaa7-402a-af2f-76d0958a441d 335 Technology Versions The Technology Versions level contains inform...
33 a68e7a0f-de97-4abe-a8f2-d60c87fad3fc 149 Business Unit Migrated Level
37 bfa0280e-a1c7-40bd-8972-22157d2a051d 84 Contacts Migrated Level
56 6697fdad-3776-4b3d-bed3-7d059e7165ab 321 Exception Request Extensions Migrated Level
57 3c5b481a-6698-49f5-8111-e43bb7604486 83 Exception Requests Migrated Level
60 7eb2544d-95aa-4122-9ee5-4f458f9cb1bc 69 Facilities Migrated Level
62 b085b230-e20f-41df-a849-f5d6811447ea 167 Findings Migrated Level
102 c18501bf-4bb9-4346-8a61-81b57a3c3483 165 Task Management Migrated Level
104 8484ff06-e265-4745-a791-1795b1af5237 336 Technology Provider Information Migrated Level
262 6ff1f147-7770-49ce-aac6-85645e641eb5 464 Risk Assessment Rejection Comments
284 be039327-ed05-4d2a-a5b7-53191af63f45 485 Finding Rejection Comments
292 2c0278b1-f5a4-4f00-92eb-317deaf2e625 494 System Identification
293 afc84164-0e89-4805-9937-2bdf571b1ac7 494 Control Families Allows grouping of the control workbook items...
294 dc0ce45f-8d6f-4018-8939-c706bf0940b1 494 Control Workbook Contains the individual controls and responses
298 c5319db4-4bed-4ef9-b529-fe323996a48f 498 XXXX Remediation Update Comment
303 9ca8b5aa-6ea1-4b18-9afc-3c95f9a84c89 504 SSP System User Detailed Description