Use API Parameters to Run an Agent - Mozenda Help Center
  • The Data You Want is Closer Than You Think

    Tell us about your data extraction needs.

  • Can‘t wait and need answers now?
    Here are other ways to reach us:

    +1 (801) 995-4550

    sales@mozenda.com

  • 100% Privacy. You are that important to us. Privacy Policy

Use API Parameters to Run an Agent

June 23, 2016

This walkthrough uses the Agent.Run API call to demonstrate how to pass parameters through an API call to an agent. These can be replicated for any API call.

To use Mozenda Rest API, you must first generate a web service key.

To begin, we recommend using a simple text editor such as Notepad so that you can see the entire URL on a single line.

  1. Copy and paste the first part of the API call into a text editor.

    https://api.mozenda.com/rest?
  2. Insert WebServiceKey= and your web service key (the one below is an example key).

    https://api.mozenda.com/rest?WebServiceKey=C70E1F84-E12B-4e73-B199-2EE6D43AF44E
  3. Insert &Service=Mozenda10&Operation= after the key.

    …api.mozenda.com/rest?WebServiceKey=C70E1F84-E12B-4e73-B199-2EE6D43AF44E&Service=Mozenda10&Operation=
  4. Insert the Agent.Run API call.

    …da.com/rest?WebServiceKey=C70E1F84-E12B-4e73-B199-2EE6D43AF44E&Service=Mozenda10&Operation=Agent.Run

    As the name implies, the Agent.Run call will start a new job for the agent. Running this call will require the agent ID and any parameters built into the agent. For a full synopsis, see the Agent.Run API page.

  5. Enter &AgentID= after Agent.Run.

    …st?WebServiceKey=C70E1F84-E12B-4e73-B199-2EE6D43AF44E&Service=Mozenda10&Operation=Agent.Run&AgentID=
  6. Find the agent ID for the agent you want to run, and enter it after &AgentID=

    To find the agent ID, log in to the Web Console, go to the Agents tab, and look at the ItemID next to the agent you’d like to run.

    ebServiceKey=C70E1F84-E12B-4e73-B199-2EE6D43AF44E&Service=Mozenda10&Operation=Agent.Run&AgentID=1009
  7. Identify one of the parameters in the agent.

    You may need to open the agent in the Agent Builder and look for any Set User Input actions with an input value that appears between two percent signs. It would look something like this: %ZipCode%

  8. Insert &AgentParameter. followed by the parameter name and value.

    &AgentParameter.ZipCode=90210

    Here’s what it looks like at the end of the API call:

    73-B199-2EE6D43AF44E&Service=Mozenda10&Operation=Agent.Run&AgentID=1009&AgentParameter.ZipCode=90210
  9. Repeat step 8 for any additional parameters in the agent.

    The completed API call should look something like this:

    https://api.mozenda.com/rest?WebServiceKey=C70E1F84-E12B-4e73-B199-2EE6D43AF44E&Service=Mozenda10&Operation=Agent.Run&AgentID=1009&AgentParameter.ZipCode=90210

Notes

To test this API call, copy the API call you’ve assembled and paste it into a browser, then press Enter. Depending on the browser you choose, the response may be shown differently, but it should look something like this:

<AgentRunResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <Result>Success</Result>
    <AgentID>1057</AgentID>
    <JobID>ef77f48a-62fa-4ee6-b231-82d748a1df2d</JobID>
    <JobType>WebPageHarvest</JobType>
</AgentRunResponse>

    <Result>Success</Result> indicates not that the agent has completed the job, but that the job has successfully started.