API documentation

API documentation

Account

/message/new POST

Create a new message.

Parameters:

POST data
subject

Subject

message_type

Message Type

See /message/types

message

Message

attachment

(Optional) Attach file

Return values:

SUCCESS

status=SUCCESS, message_id=[message id]

ERROR

status=ERROR, error=[error message*], errors_list=[input data errors list**]

*[INPUT_DATA]

**[File upload error|File exceed allowed file size limit|File is empty|File type not allowed| File has a virus|Subject is required|Message Type is required|Message is required|Subject contain not allowed characters| Message contain not allowed characters|Message Type has invalid value]

Code:

cURL:

curl -H "MicroworkersApiKey:YOUR_API_KEY" -X POST https://api.microworkers.com/message/new -F "attachment=@<filename>" -F "subject=<subject>" -F "message_type=<message_type>" -F "message<message>"

PHP:

<?php

include "includes/RESTClient.php";
define("cAPI_KEY", "YOUR_API_KEY");
define("cAPI_URL", "https://api.microworkers.com");
$client = new RESTClient();
$client->setApiKey(cAPI_KEY);
$client->setUrl(cAPI_URL . "/message/new");
$client->setMethod("POST");
$client->setData(
  array(
    "subject"=>"Create message - API testing",
    "message_type"=>"O-GENERAL",
    "message"=>"This is a test"
  )
);
$client->execute();
$response = $client->getLastResponse();
$client->resetClient();
echo $response;

?>

Perl:

use MW_API;
use Data::Dumper qw(Dumper);
my $mw_api = MW_API->new('api_key' => 'YOUR_API_KEY');
my $res = $mw_api->do_request('POST', '/message/new', {
  "subject" => "Create message - API testing",
  "message_type" => "O-GENERAL",
  "message" => "This is a test"
});
print Dumper($res);

Python:

from pprint import pprint
from MW_API import MW_API
mw_api = MW_API('YOUR_API_KEY')
res = mw_api.do_request('POST', '/message/new', {
  "subject": "Create message - API testing",
  "message_type": "O-GENERAL",
  "message": "This is a test"
})
pprint(res)

C#:

using System;
using MWAPI;
using System.Collections.Specialized;

public class Test
{
  public static void Main (string[] args)
  {
    MW_API MW_API_Client = new MW_API ("YOUR_API_KEY");
    NameValueCollection postData = new NameValueCollection();
    postData.Add("subject", "Create message - API testing");
    postData.Add("message_type", "O-GENERAL");
    postData.Add("message", "This is a test");
    string body = MW_API_Client.postRequest("/message/new", postData);
    Console.WriteLine (body);
  }
}

Examples:

Output (Success):

{
  "status": "SUCCESS",
  "message_id": "c5237707dcf7"
}

Output (Error):

{
  "status": "ERROR",
  "error": "INPUT_DATA",
  "errors_list": ["Message Type has invalid value"]
}