---
sourceDocument: Yokohama-API-Referenz
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/de-DE/yokohama/api-reference

 Release :

    - yokohama

ft:locale :

    - de-DE

ft:publication_title :

    - Yokohama-API-Referenz

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# SOAP-Webservice „AttachmentCreator"

# SOAP-Webservice „AttachmentCreator" {#ariaid-title1}

* Freigeben Version: Yokohama
* 
* Aktualisiert 30. Januar 2025
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 5 Minuten Lesedauer

Hängen Sie Dokumente an Datensätze in ServiceNow an, indem Sie eine SOAP-Nachricht senden, die auf die Tabelle „ecc_Queue" ausgerichtet ist.
Wichtig:  
Der SOAP-Webservice „AttachmentCreator" wird nicht empfohlen. Verwenden Sie stattdessen den REST [Anhang-API](https://servicenow-prod.fluidtopics.net/yvHCr6JSNqXgjBt_D_9IoQ#c_AttachmentAPI "Die Anhang Die API stellt Endpunkte bereit, mit denen Sie Dateianhänge hochladen und abfragen können.")Dient zum Verwalten von Anhängen mit Webservices. Mit dem SOAP-Webservice „AttachmentCreator" können Sie ein einzelnes Dokument an eine Nachricht anhängen, die maximal 5 MB beträgt. Folgendes ist ein Beispiel für eine URL oder einen Zielendpunkt: `https://instance_name.service-now.com/ecc_queue.do?WSDL ` {#r_AttachmentCreatorSOAPWebService__table_yl4_4ks_z4__entry__3}

| Feldname | Beschreibung | Wert |
|-|-|-|
| Service Desk-Mitarbeiter | Der Name des Service Desk-Mitarbeiters, der in der Anforderung sendet. Dies kann ein beliebiger Wert sein, da er nicht für die Verarbeitung verwendet wird. | AttachmentCreator |
| Thema | Das Thema des Warteschlangendatensatzes. Dieser Wert muss auf „AttachmentCreator" festgelegt werden, um die Anhangserstellung auszulösen | AttachmentCreator |
| name | Dieses Feld muss einen durch „:" getrennten Wert des Dateinamens und seines Inhaltstyps enthalten | File_Name.xls:Application/vnd.ms-Excel |
| Quelle | Dieses Feld muss einen durch „:" getrennten Wert der Zieltabelle und ihre sys_ID enthalten | Incident:dd90c5d70a0a0b39000aac5aee704ae8 |
| Nutzlast | Dieses Feld muss die codierte Base 64-Zeichenfolge enthalten, die das anzufügende Objekt darstellt | Die codierte Base 64-Zeichenfolge |
[Tabelle : 1. ecc_Queue-Felder für die Erstellung von Anhängen]

{#r_AttachmentCreatorSOAPWebService__table_yl4_4ks_z4}

Durch das Senden der in der obigen Tabelle beschriebenen Werte wird eine Excel-Datei an die Incident-Tabelle für den Datensatz angehängt, der sich durch die sys_ID befindet Dd90c5d70a0a0b39000aac5aee704ae8

## Sicherheit

Wie alle anderen HTTP-basierten Webservices, die auf der Plattform verfügbar sind, ist der SOAP-Webservice AttachementCreator erforderlich, um sich standardmäßig mit Standardauthentifizierung zu authentifizieren. Die Anwender-ID, die für die Authentifizierung verwendet wird, unterliegt der Zugriffssteuerung wie ein interaktiver Anwender.

Zum Erstellen von Anhängen muss der SOAP-Anwender über alle Rollen verfügen, die zum Erstellen von Anhangsdatensätzen \[sys_attachment\] erforderlich sind, sowie über die Rolle SOAP_create und alle Rollen, die zum Lesen und Schreiben von Datensätzen in der Zieltabelle erforderlich sind, z. B. die itil-Rolle zum Hinzufügen von Anhängen zu Incident-Datensätzen. Standardmäßig gibt es keine einzelne Rolle, mit der Sie Anhänge hinzufügen können. Sie können eine Rolle erstellen, um das Hinzufügen von Anhängen explizit zu ermöglichen, und diese Rolle dann dem SOAP-Anwender zuweisen.

## Dateitypsicherheit

Sie können steuern, welche Dateitypen Anwender anhängen können, indem Sie festlegen glide.attachment.extensionsUnd glide.security.file.mime_type.validationEigenschaften.

Damit diese Eigenschaften auf den Webservice „AttachmentCreator" angewendet werden, die Eigenschaft glide.attachment.enforce_security_validationMuss auf „wahr" festgelegt werden. Diese Eigenschaft ist standardmäßig „wahr".

## Beispiel für SOAP-Nachricht

Im Folgenden finden Sie ein Beispiel für eine SOAP-Nachricht, die eine Textdatei „john1.txt" vom MIME-Typ „Text/plain" verwendet und an einen Incident mit der GUID e6eed6950a0a3c59006f32c8e3ff3cf9 angehängt würde. Beachten Sie, dass die Nutzlast die base64-Codierung der Datei selbst ist.

    <?xml version="1.0" encoding="UTF-8"?>
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ecc="http://www.service-now.com/ecc_queue">
        <soapenv:Header />
        <soapenv:Body>
            <ecc:insert>
                <agent>AttachmentCreator</agent>
                <topic>AttachmentCreator</topic>
                <name>john1.txt:text/plain</name>
                <source>incident:e6eed6950a0a3c59006f32c8e3ff3cf9</source>
                <payload>SSB3b25kZXIgaWYgc2hlIGtub3ducyB3aGF0IHNoZSdzIGRvaW5nIG5vdy4K</payload>
            </ecc:insert>
        </soapenv:Body>
    </soapenv:Envelope>

## Beispiel für Node.js-Skript

Das folgende Beispiel für das Node.js-Skript fügt einem Incident-Datensatz einen Anhang hinzu. Führen Sie dieses Skript von einem Client-Computer aus, nicht von einer Instanz.

    /**
     * 
     * Node.js to ServiceNow attachment upload via SOAP
     * 
     * Andrew Venables andrew.venables@servicenow.com
     * July 2014
     * 
     * Version 1.0
     * 
     */

    var soap = require('soap'), // https://github.com/vpulim/node-soap
    	mime = require('mime'), // https://github.com/broofa/node-mime
    	fs = require("fs");

    var WSDL_FILENAME = 'ecc_queue.xml'; // Goto https://instancename.service-now.com/ecc_queue.do?WSDL and save a copy of the WSDL locally for simplicity
    var DIRECTORY_CONTAINING_FILES = '/Users/andrew.venables/Documents/Uploads'; // Local path to the directory containing all the files we want to upload
    var USERNAME = 'andy.venables'; // An admin user account on the instance
    var PASSWORD = 'MY_PASSWORD'; // Password for above account
    var TARGET_TABLE = 'incident'; // Target table to attach the files to
    var TARGET_SYS_ID = '9d385017c611228701d22104cc95c371'; // Target record / sys_id to attach the files to. OOTB INC0000002

    var files_to_upload; // Global that will contain our list of files to be uploaded
    var pos = 0; // Global pointer for our position in the files_to_upload list

    // Create a SOAP client to use to post to the instance
    soap.createClient(WSDL_FILENAME, function(err, client) { // Node uses callbacks
    	if (err) console.error(err);
    	
    	// Set the username and password
    	client.setSecurity(new soap.BasicAuthSecurity(USERNAME, PASSWORD));
    	
    	// Read all the files in our source directory, will include . and ..
    	files_to_upload = fs.readdirSync(DIRECTORY_CONTAINING_FILES);
    	
    	console.log('Files to upload: ' + files_to_upload.length + '\n');
    	
    	// Start iterating through the list of files to upload
    	next(client);
    		
    });

    // Process the next file in the files_to_upload array
    // This is a neat way of dealing with Node and its expectation of callbacks
    function next(client) {
    	
    	// Check we haven't reached the end
    	if (pos >= files_to_upload.length) return;
    	
    	// Get the next file to upload
    	var file_name = files_to_upload[pos];
    	
    	// Increment the pointer to the next file
    	pos++;
    	
    	console.log(pos + '/'+ files_to_upload.length+ ' - Uploading file: ' + file_name);

    	// A blank file is the end of the list
    	if (file_name == '') return;
    	
    	// Skip to the next file as this one is invalid
    	if (file_name == '.' || file_name == '..' || file_name.indexOf('.') == 0) 
    		next(client);
    	
    	// Get the file type using an module called mime
    	var file_type = mime.lookup(file_name);
    	console.log('   of type: ' + file_type);
    	
    	var file_payload;
    	// Load the file into a buffer
    	fs.readFile(DIRECTORY_CONTAINING_FILES + '/' + file_name, function(err, the_data) {
    		if (err) console.error(err);
    		
    		// Encode the buffer to base64
    		file_payload = new Buffer(the_data, 'binary').toString('base64');
    		
    		// Set the parameters before we call the Web Service
    		var parameters = {
    			'agent': 	'AttachmentCreator',
    	        'topic': 	'AttachmentCreator',
    	        'name': 	file_name+':'+file_type,
    	        'source': 	TARGET_TABLE+':'+TARGET_SYS_ID,
    	        'payload': 	file_payload
    		};
    		
    		console.log('      sending...')
    		// Make the Web Service call, remember node likes callbacks
    		client.insert(parameters, function(err, result) {
    			if (err) console.error(err);
    			
    			console.log(result);
    			
    			// This file is done, next!
    			next(client);
    		});
    	});
    }

## Beispiel-Perl-Skript

Das folgende Beispiel-Perl-Skript erstellt einen Anhang zu einem Incident-Datensatz.

    use MIME::Base64;
    use strict;
    use SOAP::Lite;
     
    # the ServiceNow instance
    my $SNC_HOST = "https://instance_name.service-now.com";
    my $base64;
    my $buf;
     
    # upload and attach a file on the local disk, base 64 encode it into a string first
    open(FILE, "/Users/davidloo/Desktop/test_files/number_test.xls") or die "$!";
    binmode FILE; #preserves file formatting on Windows
    while (read(FILE, $buf, 60*57)) {
      $base64 .= encode_base64($buf);
    }
     
    # call the sub routine to attach
    attach_incident();
     
    sub attach_incident {
      # target the ecc_queue table
      my $soap = SOAP::Lite->proxy("$SNC_HOST/ecc_queue.do?SOAP");
      $soap->{_transport}->{_proxy}->{ssl_opts}->{verify_hostname} = 0;
      my $method = SOAP::Data->name('insert')->attr({xmlns => 'http://www.service-now.com/'});
     
      # set the ecc_queue parameters
      my @params = (SOAP::Data->name(agent => 'AttachmentCreator'));
      push(@params, SOAP::Data->name(topic => 'AttachmentCreator') );
     
      # identify the file name and its mime type
      push(@params, SOAP::Data->name(name => 'number_test.xls:application/vnd.ms-excel') );
     
      # attach to the incident, specifying its sys_id
      push(@params, SOAP::Data->name(source => 'incident:dd90c5d70a0a0b39000aac5aee704ae8') );
     
      # set the payload to be the base 64 encoded string representation of the file
      push(@params, SOAP::Data->name(payload => $base64) );
     
      # invoke the web service
      my $result = $soap->call($method => @params);
     
      print_fault($result);
     
      print_result($result);
    }
     
    sub print_result {
      my ($result) = @_;
     
      if ($result->body && $result->body->{'insertResponse'}) {
        my %keyHash = %{ $result->body->{'insertResponse'} };
        foreach my $k (keys %keyHash) {
            print "name=$k   value=$keyHash{$k}\n";
        }
      }
    }
     
    sub print_fault {
      my ($result) = @_;
     
      if ($result->fault) {
        print "faultcode=" . $result->fault->{'faultcode'} . "\n";
        print "faultstring=" . $result->fault->{'faultstring'} . "\n";
        print "detail=" . $result->fault->{'detail'} . "\n";
      }
    }
     
    # use the itil user for basic auth credentials
    sub SOAP::Transport::HTTP::Client::get_basic_credentials {
       return 'itil' => 'itil';
    }


