1

I have two ColdFusion sites in different servers. I need to send a structure of an Agent (person) to be inserted in the other database server. in the source server I wrote this code:

public Struct function addAgentToRemote(struct oAgent) {

        local.stResult = {};

        try {
            myHttp = new http();
            myHttp.setMethod("POST");
            myHttp.setCharset("utf-8");
            myHttp.setUrl(application.APIURL & "_com/API/agentAPI.cfc?method=addAgent");
            myHttp.addParam(name="api_token", type="url", value=application.APIToken);
            myHttp.addParam(name="agent", type="url", value=serializeJSON(arguments.oAgent));
            local.stResult.data = myHttp.send().getPrefix();

        } catch (Any excpt) {
            local.stResult.success = false;
            local.stResult.error = excpt;
        }
        return local.stResult;
    }

In the destination server I wrote this code:

Remote String function addAgent(Required String api_token, Required String agent) {
        local.stResult = newResult();
        if (arguments.api_token NEQ application.APIToken) {
            local.stResult.success = false;
            local.stResult.error = "Wrong API Token...";
        } else {
            try {
                agentDAO = new cfc.API.daos.agentDAO().init();
                local.stResult = agentDAO.insertNewAgent(deserializeJSON(arguments.agent));
            } catch (Any excpt) {
                local.stResult.success = false;
                local.stResult.error = excpt;
            }
        }
        return serializeJSON(local.stResult);
    }

I'm getting 500 error. What is wrong ? My source or destination codes ? Thanks.

rparente
  • 59
  • 3
  • and... what is the error? – Kevin B Aug 16 '17 at 19:39
  • If you are simply copying data from one server to another, why not simply use sql? – Dan Bracuk Aug 16 '17 at 21:27
  • They are in different servers, no cross access. – rparente Aug 17 '17 at 11:44
  • Why are you using `POST` with `type="url"`? – PeterKA Aug 17 '17 at 14:02
  • 1
    If these are both your servers, and you have an api "trust" between the two CF servers, can you talk to your tech team to see if they can set up a trust between the two SQL servers? It would be much better to just send this directly through SQL rather than over HTTP. This is kinda like driving a railroad spike with a hand hammer, because that's what you have in your toolbox. It will work, but sometimes you need to add better tools to the toolbox. – Shawn Aug 17 '17 at 17:52
  • Thanks.I will try doing direct through SQL. But I'm frustrated. I though I could use the API method/ – rparente Aug 17 '17 at 20:28

0 Answers0