Getting Started

Using the Fieldmotion API

NOTE: some API calls are not yet documented. If you find you need a specific API call and it is not documented, please contact us and we will work on it.

To use the FieldMotion API, you must create an API key for the user that you want to access the API as.

To create the key, go to the Users section in the FieldMotion CRM, click "Edit" on the user you want to give API access to, and then click "Create Key" in the "Api Keys" section.

When making an API request, you should:

  • create your POST parameters

  • add a "_api_now" parameter which contains the current time in a strtotime-readable format

  • JSON-encode the POST parameters to form a string

  • add '|' and your API key to the end of the string

  • MD5-hash the resulting string

  • add the MD5-has to the POST array as "_api_md5"

  • add a "_api_id" parameter containing the API ID (as shown in the User page)

  • send the request to the API base URL (/a/ on your assigned server) with the API command added to the end

The result will be returned in JSON format.

PHP Example

<?php
$FMAPI=array(
  'api_id'=>123,
  'api_key'=>'dd7f49d3c1ad065f7b8b9ccd1fd767ac',
  'base_url'=>'https://cp123.fieldmotion.com/a/',
);

function FM_api($fn, $post=array()) {
  global $FMAPI;
  $post['_api_now']=date('Y-m-d H:i:s');
  $post['_api_md5']=md5( json_encode($post).'|'.$FMAPI['api_key'] );
  $post['_api_id']=$FMAPI['api_id'];
  
  $ch=curl_init();
  curl_setopt_array($ch, array(
    CURLOPT_URL=>$FMAPI['base_url'].$fn,
    CURLOPT_RETURNTRANSFER=>true,
    CURLOPT_POST=>true,
    CURLOPT_POSTFIELDS=>http_build_query($post)
  ));
  $result=curl_exec($ch);
  curl_close($ch);
  return $result;
}

var_dump(FM_api('Users_list'));

Make sure to replace the parameters at the top of the code with your own details. The sample code is for demonstration purposes only and will not work with the given API key.

NOTE: because POST parameters are interpreted as strings, any integers or floats that you are sending must be converted to strings BEFORE calculating the MD5. Otherwise, this can result in a mismatch in the MD5 calculated by the server vs what you calculated yourself.

NOTE: if using C#, please make sure your network connection supports TLS 1.2 security.

Last updated