Share via


Update (PUT/MERGE) Credentials

Update using the HTTP PUT/MERGE operation.

Code Examples

Request

Method Request URI HTTP Version

MERGE

HTTPS://<HOST>:<PORT>/00000000-0000-0000-0000-000000000000/Credentials(guid'<GUID>')

HTTP/1.1

Request URI Parameters

URI Parameter Description

GUID

Required. The unique identifier value (CredentialID) for a Credential entity.

Request URI Example

Example URI

MERGE https://sma-server:9090/00000000-0000-0000-0000-000000000000/Credentials(guid'ebc8f55e-008e-4dcc-b97b-45b0c1ae0505') HTTP/1.1

Request Headers

For more information about the common request headers used by this operation, see Standard Service Management Automation POST/GET/PUT/DELETE Headers.

Request Body

<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:d="https://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="https://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
  <id>https://sma-server:9090/00000000-0000-0000-0000-000000000000/Credentials(guid'ebc8f55e-008e-4dcc-b97b-45b0c1ae0505')</id>
  <category term="Orchestrator.ResourceModel.Credential" scheme="https://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
  <title />
  <updated>2014-04-16T16:29:20Z</updated>
  <author>
    <name />
  </author>
  <content type="application/xml">
    <m:properties>
      <d:CreationTime m:type="Edm.DateTime">2014-04-16T16:03:41.063</d:CreationTime>
      <d:CredentialID m:type="Edm.Guid">ebc8f55e-008e-4dcc-b97b-45b0c1ae0505</d:CredentialID>
      <d:Description>Updated test credential.</d:Description>
      <d:LastModifiedTime m:type="Edm.DateTime">2014-04-16T16:03:41.063</d:LastModifiedTime>
      <d:Name>Test Credential Name</d:Name>
      <d:RawValue>test2</d:RawValue>
      <d:TenantID m:type="Edm.Guid">00000000-0000-0000-0000-000000000000</d:TenantID>
      <d:UserName>TESTUSER2</d:UserName>
      <d:Value>AKmi+x15G2r5ZglUDuGeeg==</d:Value>
    </m:properties>
  </content>
</entry>

Response

Response Codes

Response Code Description

HTTP/1.1 204 No Content

Request fulfilled.

Response Headers

For more information about the common response headers used by this operation, see Standard Service Management Automation POST/GET/PUT/DELETE Headers.

Response Body

The PUT/MERGE operation has no response body.

Code Examples

The following example searches for a specific Credential, identified by the CredentialID (a unique guid), and updates a value.

namespace CodeSample.Microsoft.SystemCenter.SMA
{
    public class SMASamples
    {
        public static void Main()
        { 
            // Replace this with the name of your SMA web service endpoint.
            string serviceEndPoint = "https://sma-server:9090/00000000-0000-0000-0000-000000000000";                      

            // Setup the connection to SMA
            OrchestratorApi SMAService = new OrchestratorApi(new Uri(serviceEndPoint));

            // Set credentials to the default or to a specific user.
            ((DataServiceContext)SMAService).Credentials = CredentialCache.DefaultCredentials;
            //((DataServiceContext)SMAService).Credentials = new NetworkCredential("user", "pwd", "domain");

            try
            {
                // Identify a specific credential instance to search for.
                var credentialID = new Guid("ebc8f55e-008e-4dcc-b97b-45b0c1ae0505");

                // Query for the specific credential instance identified by CredentialID.
                var credential= SMAService.Credentials.Where(r => r.CredentialID == credentialID).FirstOrDefault();

                // Modify credential instance property.
                credential.UserName = "TESTUSER2";
                credential.RawValue = "test2";
                credential.Description = "Updated test credential.";

                // Update the credential object.
                // Note: This action is queued up until the SaveChanges action is called.
                SMAService.UpdateObject(credential);

                // Save all pending actions (client -> server communication initiated).
                SMAService.SaveChanges();
            }
            catch (Exception ex)
            {
                throw new ApplicationException("An error occurred during execution.", ex);
            }
        }                 
    }
}

See Also

Concepts

Credential
Credentials