Copy link to clipboard
Copied
Hi all,
I am working on communicating to an api of a domain register, now i found the following code that is voor php:
$domain = "test.nl";
$params = array();
$request_url = "https://httpapi.yoursrs.com/v1/domains/" . urlencode($domain) . "/check";
$response = sendRequest($request_url, $params, "tester", "pass1234");
print_r($response);
Now i need to change this to cfml code and i tried:
<cfset jsondata = {
login_handle = "username",
login_pass = "password"
} />
<cfhttp
url="https://httpapi.yoursrs.com/v1/domains/test.nl/check"
method="post"
result="result">
#SerializeJSON(jsondata)#
</cfhttp>
Still i have no luck, does anyone can translate that php to cfml?
$response = sendRequest($request_url, $params, "tester",
"pass1234");
A quick google search suggests sendRequest is not a standard php function. What does the sendRequest function do and how is json involved ...?
Copy link to clipboard
Copied
$response = sendRequest($request_url, $params, "tester",
"pass1234");
A quick google search suggests sendRequest is not a standard php function. What does the sendRequest function do and how is json involved ...?
Copy link to clipboard
Copied
From the API doc this is the code how it should be used:
Request
Method: POST
URL: https://httpapi.yoursrs.com/v1/domains/example.com/check
BODY:
{
"login_handle":"example_user",
"login_pass":"********"
}
Response
{
"command":"domain:check",
"handle":"example.com",
"code":1000,
"msg":"Command completed successfully",
"error":[
],
"params":{
"handle":"example.com"
},
"svTRID":"158759-2-yoursrs",
"response":{
"avail":"0"
}
}
So this JSON markup needs to be placed inside the body of the post request.
Any idea's? Or examples somewhere?
I can find pieces of info around the net but nowhere a full example...
Copy link to clipboard
Copied
Try using cfhttpparam type="body"
http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_g-h_10.html
Copy link to clipboard
Copied
Tried that also like:
<cfhttp url="https://httpapi.yoursrs.com/v1/domains/test.nl/check" method="post">
<cfhttpparam type="body" name="login_handle" value="namevalue">
<cfhttpparam type="body" name="login_pass" value="passvalue">
</cfhttp>
#cfhttp.fileContent#
Keep getting error about:
{"command":null,"handle":null,"code":2400,"msg":"Command failed","error":["Internal Server Error. resulted in the following error: array_key_exists() [function.array-key-exists<\/a>]: The second argument should be either an array or an object"],"params":[],"svTRID":null,"response":[],"children":[{"command":"Internal Server Error.","handle":null,"code":2400,"msg":"Command failed","error":["array_key_exists() [function.array-key-exists<\/a>]: The second argument should be either an array or an object"],"params":{"errno":2,"errstr":"array_key_exists() [function.array-key-exists<\/a>]: The second argument should be either an array or an object","errfile":"\/home\/live\/httpapi\/v1\/index.php","errline":54},"svTRID":null,"response":[]}]}
Copy link to clipboard
Copied
From what you have described, the encoded json should be sent as the body of the request. So there should be only one tag with type="body".
Copy link to clipboard
Copied
OK, tried this:
<cfset jsondata = {
login_handle = "namevalue",
login_pass = "passvalue"
} />
<cfset jsondata = SerializeJSON(jsondata)>
<cfhttp
url="https://httpapi.yoursrs.com/v1/domains/test.nl/check"
method="post">
<cfhttpparam type="body" name="params" value="#jsondata#">
</cfhttp>
Now i get:
{"command":null,"handle":null,"code":2003,"msg":"Required parameter missing","error":["Parameter 'login_handle' missing.","Parameter 'login_pass' missing."],"params":{"LOGIN_PASS":"passvalue","LOGIN_HANDLE":"namevalue","handle":"test.nl"},"svTRID":null,"response":[]}
Message was edited by: marco van den oever
Copy link to clipboard
Copied
<cfhttpparam type="body" name="params" value="#jsondata#">
It looks right. Try it without the name "params". Maybe that is confusing things?
Copy link to clipboard
Copied
Ah got it, i used:
<cfset jsondata = {
login_handle = "namevalue",
login_pass = "passvalue"
} />
That should be:
<cfset jsondata = {
"login_handle":"namevalue",
"login_pass":"passvalue"
} />
So the JSON markup was not correctly set...
Thanks for correcting and guiding me!
Copy link to clipboard
Copied
So the JSON markup was not correctly set...
Yes, but calling SerializeJSON() before you send the packet should generate the correct mark up. Maybe it was a case sensitivity problem. (Notice how CF converted the keys to upper case in the error message). Just for grins try setting the keys with assocative array notation. Any difference ?
<cfset jsonData = {}>
<cfset jsonData["login_handle"] = "namevalue">
<cfset jsonData["login_pass "] = "passvalue">
<cfset jsonData = SerializeJSON(jsonData)>
Copy link to clipboard
Copied
I tried and now it works! That is the correct way of doing so