NAV Navbar
CMC Interface API
shell c# node

Introduction

Welcome to the CMC Interface API Documentation. The API endpoints supply information on new and changed contracts in TDM and allow CMC to update the CMC Ids in TDM.

We have example language bindings in shell using curl and in c#, you can view these code examples in the dark area to the right.

Authentication

The CMC Interface uses Oath2 flow to allow access to the API. Each API call requires an authentication token to be provided in the header. To obtain an authentication token you need to supply the Client Id and Client Secret along with your username and password. This will return an authentication token that can be used to call the rest of the API end points. Tehe call will also return a refresh token. The refresh token can be used in subsequent logins instead of the Client Secret and Username and Password.

The CMC Interface expects the Authentication Token to be included in all the non-login API calls, in a header that looks like the following:

Authorization: Bearer GyFXUtCaGbFfo_HQH0U4Ph_XxPvvF6UMTXQJnlpolfFR8suxEoYgCayJ...

token

To obtain an Authentication Token, using username/password you also need to supply the client_id and client_secret, this will be supplied separately.



curl -d "grant_type=password&username=cmcinterface@axiomlaw.com&password=password&\
client_id=cmc&client_secret=secret" -X POST "https://cmc-interface-test.azurewebsites.net/token"


using System;
using System.Net;
using System.IO;
using System.Text;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace ClientTest
{
    class Program
    {
        public static void Main(string[] args)
        {
            // set client to use the latest tls
            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12 | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls;

            // set the endpoint
            string url = "https://cmc-interface-test.azurewebsites.net/token";

            // set the params
            var myParams = new System.Collections.Specialized.NameValueCollection();
            myParams.Add("grant_type", "password");
            myParams.Add("client_id", "cmc");
            myParams.Add("client_secret", "secret");
            myParams.Add("username", "cmcinterface@axiomlaw.com");
            myParams.Add("password", "password");

            using (WebClient client = new WebClient())
            {
                try
                {
                    // set to post form and return json
                    client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
                    client.Headers.Add("Accept:application/json");
                    byte[] responsebytes = client.UploadValues(url,"POST", myParams);
                    string jsonResponse = Encoding.ASCII.GetString(responsebytes);

                    // parse the response and return variable
                    JObject r = JObject.Parse(jsonResponse);

                    // to output the individual return variables
                    // Console.WriteLine("acces_token: " + r["access_token"]);
                    // Console.WriteLine("token_type: " + r["token_type"]);
                    // Console.WriteLine("expires_in: " + r["expires_in"]);
                    // Console.WriteLine("refresh_token: " + r["refresh_token"]);

                    // output the JSON
                    Console.WriteLine(r.ToString());
                }
                catch (WebException webException)
                {
                    // handle exceptions
                    string jsonResponse = "";
                    using (HttpWebResponse webResponse = (HttpWebResponse)webException.Response)
                    {
                        StreamReader responseReader = new StreamReader(webResponse.GetResponseStream());
                        jsonResponse = responseReader.ReadToEnd();
                    }

                    JObject r = JObject.Parse(jsonResponse);

                    // to output the individual return variables
                    // Console.WriteLine("**Error**: " + webException.Message);
                    // if(r.ContainsKey("error")) Console.WriteLine("code: " + r["error"]);
                    // if (r.ContainsKey("error_description")) Console.WriteLine("description: " + r["error_description"]);

                    // output the JSON
                    Console.WriteLine(r.ToString());

                }
            }
        }
    }
}
    
var https = require("https");
var querystring = require("querystring");

var post_data = querystring.stringify({
    "grant_type" : "password",            
    "client_id" : "cmc",
    "client_secret" : "secret",
    "username":"cmcinterface@axiomlaw.com",
    "password":"password"
});

var post_options = {
    host: "cmc-interface-test.azurewebsites.net",
    port: 443,
    path: "/token",
    method: "POST",
    headers: {
        "Content-Type": "application/x-www-form-urlencoded",
        "Content-Length": Buffer.byteLength(post_data)
}}

// set up the POST request
var post_req = https.request(post_options, function(res) {
    res.setEncoding("utf8");

    var data = "";

    res.on("data", function(chunk) {               
        data += chunk
    })

    res.on("end", function () {
        if(this.statusCode==200){
            // handle response
            console.log(data);

            // output the JSON
            var r = JSON.parse(data)

            // to output the individual return variables
            // console.log("access_token: " + r["access_token"]);
            // console.log("token_type: " + r["token_type"]);
            // console.log("expires_in: " + r["expires_in"]);
            // console.log("refresh_token: " + r["refresh_token"]);

        } else {
            console.log("**Error** Status Code: " + this.statusCode);
            console.log(data);
        }
    });
});

// post the data
post_req.write(post_data);
post_req.end();



    

Make sure to replace the values for username and password and client_id and client_secret with the values supplied.

The above returns JSON structured like this (the access_token value has been truncated for brevity):

    
{   "access_token":"GyFXUtCaGbFfo_HQH0U4Ph_XxPvvF6UMTXQJnlpolfFR8suxEoYgCay...",
    "token_type": "bearer",
    "expires_in": 1799,
    "refresh_token":"129cdd59d7f54f30810e4d22766d4d77"}

Once you have obtained a Refresh Token, that can be used to get a new Authentication Token without supplying the username/password or the client_secret. The client_id must match the client_id that was used to generate the original refresh token.


curl -d "grant_type=refresh_token&refresh_token=129cdd59d7f54f30810e4d22766d4d77\
&client_id=cmc" -X POST "https://cmc-interface-test.azurewebsites.net/token"

using System;
using System.Net;
using System.IO;
using System.Text;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace ClientTest
{
    class Program
    {
        public static void Main(string[] args)
        {
            // set client to use the latest tls
            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12 | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls;

            // set the endpoint
            string url = "https://cmc-interface-test.azurewebsites.net/token";

            // set the params
            var myParams = new System.Collections.Specialized.NameValueCollection();
            myParams.Add("grant_type", "refresh_token");
            myParams.Add("client_id", "cmc");
            myParams.Add("refresh_token", "129cdd59d7f54f30810e4d22766d4d77");

            using (WebClient client = new WebClient())
            {
                try
                {
                    // set to post form and return json
                    client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
                    client.Headers.Add("Accept:application/json");
                    byte[] responsebytes = client.UploadValues(url,"POST", myParams);
                    string jsonResponse = Encoding.ASCII.GetString(responsebytes);

                    // parse the response and return variable
                    JObject r = JObject.Parse(jsonResponse);

                    // to output the individual return variables
                    // Console.WriteLine("acces_token: " + r["access_token"]);
                    // Console.WriteLine("token_type: " + r["token_type"]);
                    // Console.WriteLine("expires_in: " + r["expires_in"]);
                    // Console.WriteLine("refresh_token: " + r["refresh_token"]);

                    // output the JSON
                    Console.WriteLine(r.ToString());
                }
                catch (WebException webException)
                {
                    // handle exceptions
                    string jsonResponse = "";
                    using (HttpWebResponse webResponse = (HttpWebResponse)webException.Response)
                    {
                        StreamReader responseReader = new StreamReader(webResponse.GetResponseStream());
                        jsonResponse = responseReader.ReadToEnd();
                    }

                    JObject r = JObject.Parse(jsonResponse);

                    // to output the individual return variables
                    // Console.WriteLine("**Error**: " + webException.Message);
                    // if(r.ContainsKey("error")) Console.WriteLine("code: " + r["error"]);
                    // if (r.ContainsKey("error_description")) Console.WriteLine("description: " + r["error_description"]);

                    // output the JSON
                    Console.WriteLine(r.ToString());

                }
            }
        }
    }
}

var https = require("https");
var querystring = require("querystring");

var post_data = querystring.stringify({
    "grant_type" : "refresh_token",      
    "client_id" : "cmc",
    "refresh_token" : "129cdd59d7f54f30810e4d22766d4d77"
});

var post_options = {
    host: "cmc-interface-test.azurewebsites.net",
    port: 443,
    path: "/token",
    method: "POST",
    headers: {
        "Content-Type": "application/x-www-form-urlencoded",
        "Content-Length": Buffer.byteLength(post_data)
}}

// set up the POST request
var post_req = https.request(post_options, function(res) {
    res.setEncoding("utf8");

    var data = "";

    res.on("data", function(chunk) {               
        data += chunk
    })

    res.on("end", function () {
        if(this.statusCode==200){
            // handle response
            console.log(data);

            // output the JSON
            var r = JSON.parse(data)

            // to output the individual return variables
            // console.log("access_token: " + r["access_token"]);
            // console.log("token_type: " + r["token_type"]);
            // console.log("expires_in: " + r["expires_in"]);
            // console.log("refresh_token: " + r["refresh_token"]);

        } else {
            console.log("**Error** Status Code: " + this.statusCode);
            console.log(data);
        }
    });
});

// post the data
post_req.write(post_data);
post_req.end();


    

This returns the same JSON as the original call (the access_token value has been truncated for brevity):

    
{   "access_token":"Fz94d2pB7MNB7UzqfuTg5cofkfurZS1vHxjwDzKi...",
    "token_type":"bearer",
    "expires_in":1799,
    "refresh_token":"0107f05d08c541c8848b19ce47b153ef"}

This endpoint allows you to get an Autentication Token from the username/password or refresh token. Authentication tokens are valid for 30mins, Refresh tokens are valid for 24 hours.

HTTP Request

POST https://cmc-interface-test.azurewebsites.net/token
Content-Type: application/x-www-form-urlencoded

Parameters

Parameters should be included in the Request body, x-www-form-urlencoded encoded.

Parameter Default Description
grant_type "password" if supplying a username/password authentication or "refresh_token" if supplying a refresh token
username Username of the login supplied to login to the CMC Interface. Not required for refresh_token grant type.
password Password of the login supplied to login to the CMC Interface. Not required for refresh_token grant type.
client_id Client Id of the login supplied to login to the CMC Interface. Required for both grant types.
client_secret Client Secret of the login supplied to login to the CMC Interface. Not required for refresh_token grant type.
refresh_token Refresh token value to login with. Not required for password grant type, required for refresh_token grant type

getCMCMetadataBulk

Returns the metadata for all added or changed contracts.


curl -X GET \
"https://cmc-interface-test.azurewebsites.net/getCMCMetadataBulk?startTime=08/28/2018+00:00:00\
&endTime=08/29/2018+00:00:00"\
 -H "Authorization: Bearer Fz94d2pB7MNB7UzqfuTg5cofkfurZS1vHxjwDzKi..."

using System;
using System.Net;
using System.IO;
using System.Text;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace ClientTest
{
    class Program
    {
        public static void Main(string[] args)
        {
            // set client to use the latest tls
            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12 | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls;

            // set the endpoint
            string url = "https://cmc-interface-test.azurewebsites.net/getCMCMetadataBulk";

            // replace with the correct value
            string token = "Fz94d2pB7MNB7UzqfuTg5cofkfurZS1vHxjwDzKi-XEpBhWvPPcnb5GiTzqdA...";

            // set the params
            var myParams = new System.Collections.Specialized.NameValueCollection();
            myParams.Add("startTime", "08/28/2018 00:00:00");
            myParams.Add("endTime", "08/29/2018 00:00:00");
            
            using (WebClient client = new WebClient())
            {
                try
                {
                    client.Headers[HttpRequestHeader.Authorization] = "Bearer " + token;    
                    client.Headers.Add("Accept:application/json");
                    client.QueryString = myParams;

                    byte[] responsebytes = client.DownloadData(url);
                    string jsonResponse = Encoding.ASCII.GetString(responsebytes);

                    // parse the response and return variable
                    JObject r = JObject.Parse(jsonResponse);

                    // to output the individual return variables
                    // Console.WriteLine("totalContractResultSize: " + r["totalContractResultSize"]);
                    // Console.WriteLine("startTime: " + r["startTime"]);
                    // Console.WriteLine("endTime: " + r["endTime"]);
                    
                    // output the JSON
                    Console.WriteLine(r.ToString());
                }
                catch (WebException webException)
                {
                    // handle exceptions
                    string jsonResponse = "";
                    using (HttpWebResponse webResponse = (HttpWebResponse)webException.Response)
                    {
                        StreamReader responseReader = new StreamReader(webResponse.GetResponseStream());
                        jsonResponse = responseReader.ReadToEnd();
                    }

                    JObject r = JObject.Parse(jsonResponse);

                    // to output the individual return variables
                    // Console.WriteLine("**Error**: " + webException.Message);
                    // if(r.ContainsKey("error")) Console.WriteLine("code: " + r["error"]);
                    // if (r.ContainsKey("error_description")) Console.WriteLine("description: " + r["error_description"]);

                    // output the JSON
                    Console.WriteLine(r.ToString());

                }
            }
        }
    }
}
    

var https = require("https");
var querystring = require("querystring");

var get_data = querystring.stringify({
    "startTime" : "08/28/2018 00:00:00",      
    "endTime" : "08/29/2018 00:00:00"
});

var token = "Fz94d2pB7MNB7UzqfuTg5cofkfurZS1vHxjwDzKi-XEpBhWvPPcnb5GiTzqdA...";

var get_options = {
    host : "cmc-interface-test.azurewebsites.net",
    port : 443,
    path : "/getCMCMetadataBulk?"+ get_data, 
    method : "GET",    
    headers : {
        "Authorization":"Bearer " + token
    }
};

// set up GET request
var get_req = https.request(get_options, function(res) {
    
    var data = "";

    res.on("data", function(chunk) {               
        data += chunk
    })

    res.on("end",function(){
        
        if(this.statusCode==200){
            // output the JSON
            console.log(data);

            // parse the data
            var r = JSON.parse(data)
            // to output the individual return variables
            // console.log("totalContractResultSize: " + r["totalContractResultSize"]);
            // console.log("startTime: " + r["startTime"]);
            // console.log("endTime: " + r["endTime"]);
        } else {
            console.log("**Error** Status Code: " + this.statusCode);
            console.log(data);
        }        
    })
    })

get_req.end();


    

The above returns JSON structured like this:

 
{
  "totalContractResultSize": 1,
  "startTime": "08/28/2018 00:00:00",
  "endTime": "08/29/2018 00:00:00",
  "CMCContracts": [
    {
      "TDMUid": "12359",
      "cmcContractId": "123",
      "cmc_agreement_no_mlh": "GES004230",
      "cmc_business_model": "Direct",
      "cmc_business_unit": "Network Intelligence",
      "cmc_cff_rep_freq": "Quarterly",
      "cmc_conflict_terms": "Agreement Governs",
      "cmc_contract_option": "Base + 4",
      "cmc_cus_agreement_no": "2040-ATSP-3710",
      "cmc_execute_date": "02/01/2009 00:00:00",
      "cmc_expiration_date": "05/02/2013 00:00:00",
      "cmc_group_submitted_by": "Sales Admin",
      "cmc_language": "English",
      "cmc_legal_emc_entity": "Dell Marketing, L.P.",
      "cmc_maint_renewals": "Yes",
      "cmc_mco_payterms": "Net 120",
      "cmc_mco_payterms_adl_dtl": "Terms for payment will be specified in the relevant SOW.",
      "cmc_pass_prd_title": "Other",
      "cmc_payment_terms": "Net 15",
      "cmc_platfrm_transfer_right": "Yes",
      "cmc_prepaid_mnt_duration": "15",
      "cmc_renewal_mnt_duration": "24",
      "cmc_revenue_doc": "Yes",
      "cmc_shipping_terms": "FCA",
      "cmc_signatory": "Unsigned",
      "cmc_src_code_escrow_cl": "No",
      "cmc_submitted_by": "Test Name",
      "cmc_sunset_clauses": "No",
      "cmc_theatre": "NORTH AMERICA",
      "cmc_hw_warranty": "Warranty15",
      "cmc_title_risk_loss": "TitleRiskLoss15",
      "last_changed_date": "08/28/2018 00:00:00"
    }
  ]
}

    

This endpoint returns all the meta data for all the contracts in TDM that have been added or changed in the specified timeframe.

HTTP Request

GET https://cmc-interface-test.azurewebsites.net/getCMCMetadataBulk

Parameters

Parameters should be passed in the QueryString.

Parameter Default Description
startTime The start time of the timeframe that changes or adds should be returned. This field is required and should be in the format MM/dd/yyyy HH:mi:ss and should be UTC
endTime The end time of the timeframe that changes or adds should be returned. The field is not required and should be in the format MM/dd/yyyy HH:mi:ss and should be UTC

getCMCMetadataOnDemand

Returns the metadata for the specified contract.


curl -X GET "https://cmc-interface-test.azurewebsites.net/getCMCMetadataOnDemand?TDMUId=12359"\
 -H "Authorization: Bearer Fz94d2pB7MNB7UzqfuTg5cofkfurZS1vHxjwDzKi..."
    

using System;
using System.Net;
using System.IO;
using System.Text;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace ClientTest
{
    class Program
    {
        public static void Main(string[] args)
        {
            // set client to use the latest tls
            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12 | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls;

            // set the endpoint
            string url = "https://cmc-interface-test.azurewebsites.net/getCMCMetadataOnDemand";

            string token = "Fz94d2pB7MNB7UzqfuTg5cofkfurZS1vHxjwDzKi-XEpBhWvPPcnb5GiTzqdA...";

            // set the params
            var myParams = new System.Collections.Specialized.NameValueCollection();
            myParams.Add("TDMUid", "12359");
                       

            using (WebClient client = new WebClient())
            {
                try
                {

                    client.Headers[HttpRequestHeader.Authorization] = "Bearer " + token;                    
                    client.Headers.Add("Accept:application/json");
                    client.QueryString = myParams;
                    byte[] responsebytes = client.DownloadData(url);
                    string jsonResponse = Encoding.ASCII.GetString(responsebytes);

                    // parse the response and return variable
                    JObject r = JObject.Parse(jsonResponse);

                    // This code takes the returned file content and save the file to the temp directory
                    // error handling code left out for brevity!
                    if (((JArray)r["CMCContracts"]).Count == 1)
                    {
                        JObject contract = (JObject)r["CMCContract"];
                        if (contract["contractContent"] != null && contract["contractContent"].ToString() != "")
                        {
                            string fileBase64 = contract["contractContent"].ToString();
                            byte[] fileContent = Convert.FromBase64String(fileBase64);

                            string filename = contract["contractFileName"].ToString() == "" ? "Contract.pdf" : contract["contractFileName"].ToString();
                            File.WriteAllBytes(System.IO.Path.GetTempPath() + filename, fileContent);
                        }
                    }
                    
                    // output the JSON
                    Console.WriteLine(r.ToString());

                }
                catch (WebException webException)
                {
                    // handle exceptions
                    string jsonResponse = "";
                    using (HttpWebResponse webResponse = (HttpWebResponse)webException.Response)
                    {
                        StreamReader responseReader = new StreamReader(webResponse.GetResponseStream());
                        jsonResponse = responseReader.ReadToEnd();
                    }

                    JObject r = JObject.Parse(jsonResponse);

                    // to output the individual return variables
                    // Console.WriteLine("**Error**: " + webException.Message);
                    // if(r.ContainsKey("error")) Console.WriteLine("code: " + r["error"]);
                    // if (r.ContainsKey("error_description")) Console.WriteLine("description: " + r["error_description"]);

                    // output the JSON
                    Console.WriteLine(r.ToString());

                }
            }
        }
    }
}

var https = require('https');
var querystring = require('querystring');
var fs = require("fs");
var os = require("os");

var get_data = querystring.stringify({
    'TDMUid' : '12359'
});

var token = "Fz94d2pB7MNB7UzqfuTg5cofkfurZS1vHxjwDzKi-XEpBhWvPPcnb5GiTzqdA...";

var get_options = {
    host : 'cmc-interface-test.azurewebsites.net',
    port : 443,
    path : '/getCMCMetadataOnDemand?'+ get_data, 
    method : 'GET',    
    headers : {
        "Authorization":"Bearer " + token
    }
};

// set up GET request
var get_req = https.request(get_options, function(res) {
    
    var data = "";

    res.on("data", function(chunk) {               
        data += chunk
    })

    res.on("end",function(){
        
        if(this.statusCode==200){
            // output the JSON
            console.log(data);

            // parse the data
            var r = JSON.parse(data)

            // Save the file if there is one
            if(r["CMCContracts"].length==1){
                var contract = r["CMCContract"];
                // save the file
                var filename = (contract["contractFileName"] == "" ? "Contract.pdf" :contract["contractFileName"])
                filename = os.tmpdir() + "\\" + filename;
                
                if(contract["contractContent"]!=""){
                    fs.writeFile(filename, contract["contractContent"], "base64", function(err) {
                        if(err){
                            console.log("**Error** Saving File: " + err);
                        } else {
                            console.log("File saved to: " + filename);
                        }
                    });
                }
            }

        } else {
            console.log('**Error** Status Code: ' + this.statusCode);
            console.log(data);
        }        
    })
})

get_req.end();


    

The above returns JSON structured like this, contractContent contains the file contents as a base64 encoded byte array. The example shown has been truncated for brevity:

 
{
  "CMCContract": 
    {
      "TDMUid": "12359",
      "cmcContractId": "123",
      "cmc_agreement_no_mlh": "GES004230",
      "cmc_business_model": "Direct",
      "cmc_business_unit": "Network Intelligence",
      "cmc_cff_rep_freq": "Quarterly",
      "cmc_conflict_terms": "Agreement Governs",
      "cmc_contract_option": "Base + 4",
      "cmc_cus_agreement_no": "2040-ATSP-3710",
      "cmc_execute_date": "02/01/2009 00:00:00",
      "cmc_expiration_date": "05/02/2013 00:00:00",
      "cmc_group_submitted_by": "Sales Admin",
      "cmc_language": "English",
      "cmc_legal_emc_entity": "Dell Marketing, L.P.",
      "cmc_maint_renewals": "Yes",
      "cmc_mco_payterms": "Net 120",
      "cmc_mco_payterms_adl_dtl": "Terms for payment will be specified in the relevant SOW.",
      "cmc_pass_prd_title": "Other",
      "cmc_payment_terms": "Net 15",
      "cmc_platfrm_transfer_right": "Yes",
      "cmc_prepaid_mnt_duration": "15",
      "cmc_renewal_mnt_duration": "24",
      "cmc_revenue_doc": "Yes",
      "cmc_shipping_terms": "FCA",
      "cmc_signatory": "Unsigned",
      "cmc_src_code_escrow_cl": "No",
      "cmc_submitted_by": "Test Name",
      "cmc_sunset_clauses": "No",
      "cmc_theatre": "NORTH AMERICA",
      "cmc_hw_warranty": "Warranty15",
      "cmc_title_risk_loss": "TitleRiskLoss15",
      "last_changed_date": "08/28/2018 00:00:00",
      "contractContent": "JVBERi0xLjcNCiW1tbW1DQoxIDAgb2JqDQo8PC9UeXBlL0NhdGFsb2cvUGFnZXMg ...",
      "contractFileName": "Test.pdf"
    }  
}

    

This endpoint returns all the meta data and the contract Content for a spefecified contract. The contract contents are returned as a base 64 encoded string.

HTTP Request

GET https://cmc-interface-test.azurewebsites.net/getCMCMetadataOnDemand

Parameters

Parameters should be passed in the QueryString.

Parameter Default Description
TDMUId The value of the TDMUid. This field is required.

updateCMCMetadataToTDM

Given the TDMUid, updates the cmcContractId field in TDM.


curl -d "TDMUId=12359&cmcContractId=123"\
 -H "Authorization: Bearer Fz94d2pB7MNB7UzqfuTg5cofkfurZS1vHxjwDzKi..."\
 -X POST "https://cmc-interface-test.azurewebsites.net/updateContractIdToTDM"
    

using System;
using System.Net;
using System.IO;
using System.Text;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace ClientTest
{
    class Program
    {
        public static void Main(string[] args)
        {
            // set client to use the latest tls
            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12 | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls;

            // set the endpoint
            string url = "https://cmc-interface-test.azurewebsites.net/updateContractIdToTDM";

            string token = "Fz94d2pB7MNB7UzqfuTg5cofkfurZS1vHxjwDzKi-XEpBhWvPPcnb5GiTzqdA...";

            // set the params
            var myParams = new System.Collections.Specialized.NameValueCollection();
            myParams.Add("TDMUid", "12359");
            myParams.Add("cmcContractId", "123");                       

            using (WebClient client = new WebClient())
            {
                try
                {
                    client.Headers[HttpRequestHeader.Authorization] = "Bearer " + token;                                                            
                    client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
                    client.Headers.Add("Accept:application/json");
                    byte[] responsebytes = client.UploadValues(url, "POST", myParams);
                    string jsonResponse = Encoding.ASCII.GetString(responsebytes);

                    // parse the response and return variable
                    JObject r = JObject.Parse(jsonResponse);

                    // to output the individual return variables
                    // Console.WriteLine("contractIdUpdateFlag: " + r["contractIdUpdateFlag"]);
                    
                    // output the JSON
                    Console.WriteLine(r.ToString());
                }
                catch (WebException webException)
                {
                    // handle exceptions
                    string jsonResponse = "";
                    using (HttpWebResponse webResponse = (HttpWebResponse)webException.Response)
                    {
                        StreamReader responseReader = new StreamReader(webResponse.GetResponseStream());
                        jsonResponse = responseReader.ReadToEnd();
                    }

                    JObject r = JObject.Parse(jsonResponse);

                    // to output the individual return variables
                    // Console.WriteLine("**Error**: " + webException.Message);
                    // if(r.ContainsKey("error")) Console.WriteLine("code: " + r["error"]);
                    // if (r.ContainsKey("error_description")) Console.WriteLine("description: " + r["error_description"]);

                    // output the JSON
                    Console.WriteLine(r.ToString());

                }
            }
        }
    }
}

var https = require("https");
var querystring = require("querystring");
var fs = require("fs");
var os = require("os");

var post_data = querystring.stringify({
    "TDMUid" : "12345",            
    "cmcContractId" : "12359",
});

var token = "Fz94d2pB7MNB7UzqfuTg5cofkfurZS1vHxjwDzKi-XEpBhWvPPcnb5GiTzqdA...";

var post_options = {
    host: "cmc-interface-test.azurewebsites.net",
    port: 443,
    path: "/updateContractIdToTDM",
    method: "POST",
    headers: {
        "Content-Type": "application/x-www-form-urlencoded",
        "Content-Length": Buffer.byteLength(post_data),        
        "Authorization":"Bearer " + token    
    }
}

// set up the POST request
var post_req = https.request(post_options, function(res) {
    res.setEncoding("utf8");

    var data = "";

    res.on("data", function(chunk) {               
        data += chunk
    })

    res.on("end", function () {
        if(this.statusCode==200){
            // handle response
            console.log(data);

            // parse the JSON
            var r = JSON.parse(data)

            // to output the individual return variables
            // console.log("contractIdUpdateFlag: " + r["contractIdUpdateFlag"]);

        } else {
            console.log("**Error** Status Code: " + this.statusCode);
            console.log(data);
        }
    });
});

// post the data
post_req.write(post_data);
post_req.end();


      

The above returns JSON structured like this:

 
{
   "contractIdUpdateFlag": "Y",
    "TDMUid": "12359"
}

This endpoint updates the supplied cmcContractId field given the TDMUid field.

HTTP Request

POST https://cmc-interface-test.azurewebsites.net/updateContractIdToTDM
Content-Type: application/x-www-form-urlencoded

Parameters

Parameters should be included in the Request body, x-www-form-urlencoded.

Parameter Default Description
TDMUId The value of the TDMUid. This field is required.
cmcContractId The value to update the cmcContractId field.

Errors

For an error the Status code will be returned and the JSON returned will look like this:

 
{
  "error": "invalid_user",
  "error_description": "User does not have api access"
}
    

Errors will either be returned with a response code, e.g. 400 Bad Request or 401 Unauthorized or 404 Not Found or 500 Server Error.