Important Update: Some Community URL Redirects are Under Maintenance. Learn More. .

cancel
Showing results for 
Search instead for 
Did you mean: 

Can anyone help me out to download the attachment by using Rest API in Archer?

AbhishekRai
Collaborator III

I am working on one request where I need to download all the attachment from an application. I tried by using GetAttachmentFile , but still it doesnot works.

9 REPLIES 9

EricaChalfin
Archer Employee
Archer Employee

Abhishek Rai‌,

 

I've moved your question to the RSA Archer Customer/Partner Community" data-type="space space where it will be seen by the product's support engineers, other customers and partners.  Please bookmark this page and use it when you have product-specific questions.

 

Alternatively, from the RSA Customer Support" data-type="space page, click on Ask A Question on the blue navigation bar and choose Ask A Product Related Question.  From there, scroll to RSA Archer Suite" data-type="space and click Ask A Question.  That way your question will appear in the correct space.

 

Regards,

Erica

DavidPetty
Archer Employee
Archer Employee

Abhishek, can you post the SOAP call you're using?

 

More on, https://community.rsa.com/docs/DOC-98592 

 Advisory Consultant

Hi David,

 

I used below SOAP as a reference:

 

<soap:Body>
<GetAttachmentFileResponse xmlns="http://archer-tech.com/webservices/">
<GetAttachmentFileResult>string</GetAttachmentFileResult>
</GetAttachmentFileResponse>
</soap:Body>
</soap:Envelope>

 

Additonally, I also tried record.GetAttachmentFile($session_token, 436); but it is  returning "</File>"

 

It would be great if you could provide me some reference related to powershell? 

 

Thanks for the help!!

Thanks, the link I posted in my initial response is to the doc that tells you how to construct the SOAP request to get the file and what's expected when successful.

 

SOAP Request

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">

<soap:Body>
<GetAttachmentFile xmlns="http://archer-tech.com/webservices/">
<sessionToken>string</sessionToken>
<fileId>int</fileId>
</GetAttachmentFile>
</soap:Body>
</soap:Envelope>‍‍‍‍‍‍‍‍‍‍

 Advisory Consultant

Thank you so much, David

JeffLetterman
Archer Employee
Archer Employee

To download Attachments using REST API, check out the attachment sections in the  Content  segment.  

 

REST API call to download:

Verb: GET

URL: /api/core/content/attachment/*attachmentid*

Sample Response for /api/core/content/attachment/23

{
  "Links": [],
  "RequestedObject": {
    "AttachmentBytes": "R0lGODlhDwAPAKECAAAAzMzM/////wAAACwAAAAADwAPAAACIISPeQHsrZ5ModrLlN48CXF8m2iQ3YmmKqVlRtW4MLwWACH+H09wdGltaXplZCBieSBVbGVhZCBTbWFydFNhdmVyIQAAOw==",
    "AttachmentName": "image.png"
  },
  "IsSuccessful": true,
  "ValidationMessages": []
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍ 

 

The following PowerShell shows how to download attachments to disk using a list of file ids:

# Set Instance info
$base_url = "http://web65/RSAarcher" 
$instance_name = "Archer"
$user_domain = ""
$username = "apiuser"
$password = "Password123$"

# Login and get session token
$login_url = $base_url + "/api/core/security/login"
$body = '{"InstanceName":"' + $instance_name + '","Username":"' + $username + '","UserDomain":"' + $user_domain + '","Password":"' + $password + '"}'
$response_login = Invoke-RestMethod -Method Post -Uri $login_url -Body $body -ContentType "application/json" 
if ($response_login.IsSuccessful) {
    $session_token = $response_login.RequestedObject.SessionToken
} else {
    Write-Warning "Unable to login with specified credentials"
    exit
}

# Create headers
$headersGET = @{}
$headersGET.Add("Authorization", "Archer session-id=" + $session_token)
$headersGET.Add("X-Http-Method-Override", "GET")
$headers = @{}
$headers.Add("Authorization", "Archer session-id=" + $session_token)

# Get list of attachment file ids, loop thru them and save to disk.
$fileIds = @(23,24,999)
foreach($fileId in $fileIds) {
    try {
        $api_url = $base_url + "/api/core/content/attachment/$fileId"
        $results = Invoke-RestMethod -Method POST -Uri $api_url -Headers $headersGET -ContentType "application/json" 
        if($results.IsSuccessful) { 
            $bytes = [System.Convert]::FromBase64String($results.RequestedObject.AttachmentBytes)
            $filename = $results.RequestedObject.AttachmentName
            $filepath = "c:\temp\download\" + $filename
            [IO.File]::WriteAllBytes($filepath, $bytes)
            Write-Host $filepath
        } else {
            Write-Warning ("Downloading File Id $fileid failed. " + ($results.ValidationMessages.Description | Join-String))
        }
    }
    catch {
        Write-Warning ("Unexpected error processing File Id $fileid. " + $_.Exception.Message)
    }
    finally {
        $results=$null; $bytes=$null; $filename=$null; $filepath=$null
    }
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍ 

 

PowerShell Output:

pastedImage_8.png

 

 

Using the  Archer API Templates - an Archer application to quickly test the Archer Web Services API, REST API, and Content API using Custom Objects and much more

pastedImage_1.png

Thank you jeff, It is really helpful.

Hi Jeff,

 

I am getting below error as attached:

 

pastedImage_1.png

AbhishekRai
Collaborator III

Hi Jeff,

 

I resolved the issue. Thanks for your support.