We help IT Professionals succeed at work.

OpenSRS API and Coldfusion

Medium Priority
77 Views
Last Modified: 2020-02-20
I am familiar with Coldfusion and a little javascript. I am not familiar with calling APIs. I am trying to understand how I can use the OpenSRS API. Unfortunately none of their examples use Coldfusion. Can someone help me understand how I would use their API using Coldfusion

See https://domains.opensrs.guide/docs
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2015
Commented:

From the documentation, you'd use a simple cfhttp POST request with a specific body and headers. The request body is an xml string containing the command to execute (see API examples). The response back from the API will also be an xml string.


Required Headers

  • Content-Type = text/xml
  • X-Username = <YOUR_RESELLER_USERNAME_HERE>
  • X-Signature = Dynamic value constructed by hashing the XML string and your API Key


Something along these lines.  Just replace "< YOUR_API_KEY_HERE >" and " <YOUR_API_KEY_HERE> " with real values.


<cfscript>
    // xml command string
    xml = "<?xml version='1.0' encoding='UTF-8' standalone='no' ?><!DOCTYPE OPS_envelope SYSTEM 'ops.dtd'><OPS_envelope><header><version>0.9</version></header><body><data_block><dt_assoc><item key='protocol'>XCP</item><item key='action'>LOOKUP</item><item key='object'>DOMAIN</item><item key='attributes'><dt_assoc><item key='domain'>myfirstopensrsapitest.com</item></dt_assoc></item></dt_assoc></data_block></body></OPS_envelope>";

    // hash xml and apiKey to build signature
    variables.signature = lcase(hash(variables.xml & "<YOUR_API_KEY_HERE>", "md5"));
    variables.signature = lcase(hash(variables.signature & "<YOUR_API_KEY_HERE>", "md5"));

    // Using TEST environment for demo
    cfhttp(method="post", url="https://horizon.opensrs.net:55443") {
        cfhttpparam(type="header", name="Content-Type", value="text/xml");
        cfhttpparam(type="header", name="X-Username", value="<YOUR_RESELLER_USERNAME>");
        cfhttpparam(type="header", name="X-Signature", value=variables.signature);
        cfhttpparam(type="body", value=xml);
    }

    if (cfhttp.statusCode eq "200 OK"){
        writeOutput( "<h3>Response</h3>" );
        writeOutput( "<code>"& encodeForHTML(cfhttp.fileContent) &"</code>") ;
    }
    else {
        // Something went wrong
        writeOutput( "<h3>Error</h3>");
        writeDump( cfhttp );
    }
</cfscript>

Author

Commented:
Thank you.

I did exactly what you suggested (see https://www.adreflex.com/d5.cfm) and I get the error:

Unknown host: Connection to https://horizon.opensrs.net:55443 refused
CERTIFIED EXPERT
Most Valuable Expert 2015

Commented:

It connects okay from trycf.com


https://trycf.com/gist/f893d55067abb3e2f2e403421052d0ce/lucee5?theme=monokai

CERTIFIED EXPERT
Most Valuable Expert 2015

Commented:

What happens when you try that exact code on your server?

Author

Commented:
The error that I was getting: Unknown host: Connection to https://horizon.opensrs.net:55443 refused

was due to an older version of a java file on the server. It works now. Thank you.
CERTIFIED EXPERT
Most Valuable Expert 2015

Commented:

Glad it's working now.  In case anyone else runs into the same issue, was it an old jar file or cached template?

Author

Commented:
It was an old jar file
CERTIFIED EXPERT
Most Valuable Expert 2015

Commented:

Weird.  That's a new one ;-) Anyway, glad you got it worked out.