NAV Navbar
shell ruby python javascript php java csharp
  • Introduction
  • Installation
  • Authentication
  • SMS API
  • Verify API
  • Query API
  • Response Status
  • Introduction

    Mocean API makes sending and receiving SMS easy. Find the documentation, sample code, and developer tools you need to build exactly what you want, fast. We’ll handle the complexity of mobile carrier and global regulations. Let’s get building.

    "Ahoy, World" is a few lines of code away. Choose your programming language and dive in. We’ve got helper libraries and Quickstarts to get you sending SMS and Verify in your web app.

    You’ve got an idea in mind. Let’s get it to production.

    Installation

    To install Mocean SDK, run this command in terminal:

    # you may need to install curl, if it is not installed
    sudo apt install curl
    
    # you need to have pip installed
    pip install moceansdk
    
    # you need to have gem installed
    gem install moceansdk
    
    // you need to have npm installed
    npm install mocean-sdk
    
    # you need to have composer installed
    composer require mocean/client
    
    
    
    Install-Package Mocean.Csharp.Client -Version 1.0.2.1
    

    Make sure you have the required package manager installed.

    Mocean SDK supports up to 6 programming languages for fellow developers to work with. Choose your favourite programming language, and install our SDK to immediately enables your application to send SMS right away!

    Otherwise, if a simple curl is what you've preferred. You may send SMS with our curl sample code which will work the same.

    Authentication

    To authorize Mocean SDK, use the following code:

    # include API credentials in all HTTP POST data to authorize, as demonstrated below:
    
    curl -X GET "https://rest.moceanapi.com/rest/1/account/balance?
                 mocean-api-key=API_KEY_HERE&
                 mocean-api-secret=API_SECRET_HERE"
    
    require "moceansdk"
    
    token = Client.new("API_KEY_HERE", "API_SECRET_HERE")
    mocean = Mocean.new(token)
    
    from moceansdk import Mocean, Client
    
    token = Client("API_KEY_HERE", "API_SECRET_HERE")
    mocean = Mocean(token)
    
    <?php
    require_once '../vendor/autoload.php';
    
    $token = new Mocean\Client\Credentials\Basic(
        'API_KEY_HERE', 
        'API_SECRET_HERE'
    );
    $mocean = new Mocean\Client($token);
    ?>
    
    const moceanjs = require('mocean-sdk');
    
    var token = new moceanjs.Client('API_KEY_HERE','API_SECRET_HERE');
    var mocean = new moceanjs.Mocean(token);
    
    import mocean.system.*;
    
    class program {
    
        public static void main(String [] args)
        {
            Client token = new Client("API_KEY_HERE","API_SECRET_HERE");
            Mocean mocean = new Mocean(token);
        }
    }
    
    Credentials creds = new Credentials
    {
        mocean_api_key = "API_KEY_HERE",
        mocean_api_secret = "API_SECRET_HERE"
    };
    

    Make sure to replace API_KEY_HERE and API_SECRET_HERE with your API credential.

    To make the API requests, you need to create a Client and provide it with authentication credentials (which can be found at https://dashboard.moceanapi.com/).

    SMS API

    Overview

    Mocean SMS API allows you to send and receive text messages to users around the globe through simple RESTful APIs.

    Concepts

    To use the Mocean SMS API, you may need to familiarise yourself with:

    Getting Started

    Before you begin, please make sure you already have a Mocean API account, or sign up for a Mocean account here.

    Using your Mocean API_KEY and API_SECRET, available from the dashboard page, you can now send an SMS message:

    Send SMS

    Example request

    curl -X POST "https://rest.moceanapi.com/rest/1/sms" \
      -d "mocean-api-key=API_KEY_HERE&
          mocean-api-secret=API_SECRET_HERE&
          mocean-from=YourCompany&
          mocean-to=60123456789&
          mocean-text=Hello"
    
    require "moceansdk"
    
    token = Client.new("API_KEY_HERE", "API_SECRET_HERE")
    mocean = Mocean.new(token)
    
    res = mocean.sms.create({
            "mocean-text"=>'Hello World',
            "mocean-from"=>'MOCEAN',
            "mocean-to"=>'60123456789'
            }).send()
    
    puts res
    
    from moceansdk import Mocean, Client
    
    token = Client("API_KEY_HERE", "API_SECRET_HERE")
    mocean = Mocean(token)
    
    res = mocean.sms.create({
        "mocean-from": "MOCEAN",
        "mocean-to": 60123456789,
        "mocean-text": "Hello World"
    }).send()
    
    print(res)
    
    <?php
    require_once '../vendor/autoload.php';
    
    $token = new Mocean\Client\Credentials\Basic(
        'API_KEY_HERE',
        'API_SECRET_HERE'
    );
    $mocean = new Mocean\Client($token);
    
    $res = $mocean->message()->send([
        'mocean-to' => '60123456789',
        'mocean-from' => 'MOCEAN',
        'mocean-text' => 'Hello World',
        'mocean-resp-format' => 'json'
    ]);
    
    echo $res;
    ?>
    
    const moceanjs = require('mocean-sdk');
    
    var token = new moceanjs.Client('API_KEY_HERE','API_SECRET_HERE');
    var mocean = new moceanjs.Mocean(token);
    
    mocean.sms().create({
      from: 'MOCEAN',
      to: '60123456789',
      text: 'Hello World'
    }).send((err, res) => {
      if(err) throw err;
    
      console.log(res);
    });
    
    String res = mocean.sms()
                 .setFrom("MOCEAN")
                 .setTo("60123456789")
                 .setText("Hello World")
                 .send();
    
    System.out.println(res);        
    
    Mocean.Message.Message _message = new Mocean.Message.Message()
    {
        mocean_to = "60123456789",
        mocean_from = "MOCEAN",
        mocean_text = "Hello World",
        mocean_resp_format = "json",
    };
    
    string response = Mocean.Message.Client.Send(_message, creds);
    

    Send an outbound SMS from your Mocean account

    POST https://rest.moceanapi.com/rest/1/sms

    Query Parameter

    A successful response for MT-SMS will be as follows:

    {
      "messages":[
        {
          "status":0,
          "receiver":"60173788399",
          "msgid":"cust20013050311050614001"
        }
      ]
    }
    

    While unsuccessfully response will be as follows:

    {
      "status":1,
      "err_msg":"Authorization failed"
    }
    
    Parameter Format Description
    mocean-api-key
    required
    string Your account API key.
    mocean-api-secret
    required
    string Your account API secret.
    mocean-from
    required
    string SMS Sender ID (also referred as to SMS Sender Name) is the information that is displayed to the recipient as the sender of the SMS when a message is received at a mobile device.
    mocean-to
    required
    string Phone number of the receiver. To send to multiple receivers, separate each entry with white space (‘ ’) or comma (,). Phone number must include country code, for example, a Malaysian phone number will be like 60123456789.
    mocean-text
    required
    string Contents of the message, URL encoded as necessary (e.g. Text+message+test%21). If you are sending binary content, this will be a hex string. For example, 030616AE966C6F...
    mocean-udh
    optional
    string User Data Header (UDH) part of the message. For example, 0605040B8423F0.
    mocean-coding
    optional
    number Sets the coding scheme bits in DCS field. Accepts values 1 to 3, for 7-bit, 8-bit and UCS2 respectively. If unset, defaults to 7 bits unless a mocean-udh is defined, which sets coding to 8-bit. If charset is not set or set to UTF-8, when non-GSM character is detected, coding will set to UCS2.
    mocean-dlr-mask
    optional
    number Request for delivery reports with the state of the sent message. To enable delivery reports, set this value to ‘1’. If this field is not specified, the default value will be ‘0’ and no DLR will be returned.
    mocean-dlr-url
    optional
    URL URL to receive delivery reports. This is required if DLR is requested.
    mocean-schedule
    optional
    datetime When this field is used, the message will be sent out on the specified date time (on best effort basis due to large number of SMS is queued for scheduling). The format of the date time is YYYY-MM-DD hh:mm:ss (in 24-hours format, e.g. 2007-02-11 23:30:00). The wrong date format will cause the gateway to reject the request. NOTE: Please use Malaysia time (or GMT +8:00) while making scheduled SMS request.
    mocean-mclass
    optional
    number To send Flash SMS, set mocean-mclass and mocean-alt-dcs value to '1'.
    mocean-alt-dcs
    optional
    number To send Flash SMS, set mocean-mclass and mocean-alt-dcs value to '1'.
    mocean-charset
    optional
    string Indicates the character set used in the mocean-text parameter. Supported character sets are:
    1. ISO-8859-1
    2. ISO-8859-7
    3. UTF-8
    4. Windows-1252
    mocean-validity
    optional
    number To define the validity period of message. User has to input validity in terms of SECONDS. For example, if user wants message to expire after 5 minutes upon submission, user has to configure mocean-validity as 300.
    mocean-resp-format
    optional
    string Response format. By default, response format will be returned in XML. Supported formats are:
    • XML
    • JSON

    Delivery Report

    Receiving PUT request

    require 'sinatra'
    require 'sinatra/multi_route'
    require 'json'
    
    helpers do
      def parsed_body
         json? ? JSON.parse(request.body.read) : {}
      end
    
      def json?
        request.content_type == 'application/json'
      end
    end
    
    route :put, '/webhooks/delivery-report' do
      puts params.merge(parsed_body)
      status 204
    end
    
    set :port, 3000
    
    from flask import Flask,request
    
    app = Flask(__name__)
    
    @app.route('/webhooks/delivery-report', methods=['PUT'])
    def getDeliveryReport():
        data = request.form
    
        _to = data['mocean-to']
        _from = data['mocean-from']
        _dlrStatus = data['mocean-dlr-status']
        _msgid = data['mocean-msgid']
        _errorCode = data['mocean-error-code']
    
    const app = require('express')();
    const bodyParser = require('body-parser');
    
    app.use(bodyParser.json());
    app.use(bodyParser.urlencoded({ extended: true }));
    
    app.route('/webhooks/delivery-report').put('handleDlr');
    function handleDlr(req, res)
    {
      console.log(res.body);
      res.status(204).send();
    }
    
    app.listen(8080)
    
    import mocean.system.*;
    
    class program {
    
        public static void main(String [] args)
        {
            Client token = new Client("API_KEY_HERE","API_SECRET_HERE");
            Mocean mocean = new Mocean(token);
    
            try
            {
                put("/webhooks/delivery-report", (req, res) -> {                   
    
                    for (String param : req.queryParams()) 
                    {
                        System.out.printf("%s: %s\n", param, req.queryParams(param));
                    }
    
                    res.status(204);
                    return "";
                });
            }
            catch(Exception e)
            {
                System.out.println(e.getMessage());
            }
        }
    }
    
    <?php
    public void ReceiveDLR()
    {
        Debug.WriteLine("------");
        Debug.WriteLine("DELIVERY RECEIPT");
        Debug.WriteLine("mocean-msgid: " + Request.Form["mocean-msgid"]);
        Debug.WriteLine("mocean-from: " + Request.Form["mocean-from"]);
        Debug.WriteLine("mocean-to: " + Request.Form["mocean-to"]);
        Debug.WriteLine("mocean-dlr-status: " + Mocean.Message.Client.DLRStatus(Request.Form["mocean-dlr-status"]));
        Debug.WriteLine("mocean-error-code: " + Request.Form["mocean-error-code"]);
        Debug.WriteLine("------");
    }
    
    <?php
    use \Psr\Http\Message\ServerRequestInterface as Request;
    use \Psr\Http\Message\ResponseInterface as Response;
    
    require 'vendor/autoload.php';
    
    $app = new \Slim\App;
    
    $handler = function (Request $request, Response $response) {
        $params = $request->getParsedBody();
    
        // Fall back to query parameters if needed
        if (!count($params)){
            $params = $request->getQueryParams();
        }
    
        error_log(print_r($params, true));
    
        return $response->withStatus(204);
    };
    
    $app->put('/webhooks/delivery-report', $handler);
    
    $app->run();
    ?>
    

    Request sent from Mocean

    > PUT /webhooks/delivery-report HTTP/1.1
    > Host: example.com
    > Accept: */*
    > Content-Length: 114
    > Content-Type: application/x-www-form-urlencoded
    
    
    {
      mocean-from: 60123456789,
      mocean-to: 63001,
      mocean-dlr-status: 1,
      mocean-msgid: "cust20013050311050614001",
      mocean-error-code: 0
    }
    

    If delivery report is requested, Mocean shall returned delivery report to the callback url submitted under parameter "mocean-dlr-url" in Outbound SMS request.

    After returning delivery report, Mocean API Server is expecting a respond with “HTTP OK” (Status 200) or it will keep on retrying until it expired(36 hours).

    Note: If you're using localhost environment for receiving Delivery Reports, you will need to make your local environment publicly available so Mocean API server can reach your local server. We recommend you try ngrok to do this quite easily.

    PUT https://example.com/webhooks/delivery-report

    Parameter Format Descriptions
    mocean-from number Phone number of the original SMS recipient.
    mocean-to number Phone number of the original SMS sender.
    mocean-dlr-status number Status of the delivery.
    1. Success
    2. Failed
    3. Expired
    mocean-msgid string Message ID of the message where this report is associated.
    mocean-error-code number Error code of the submission.
    Code Descriptions
    000 No error.
    001 Absent subscriber.
    002 Handset memory capacity exceeded. Handset has run out of free memory to store new message.
    003 Equipment protocol error.
    004 Equipment not equipped with short-message capability.
    005 Unknown subscriber. The IMSI is unknown in the HLR.
    006 Illegal subscriber. The mobile station failed authentication.
    007 Teleservice not provisioned. Mobile subscription identified by the MSISDN number does include the short message service.
    008 Illegal equipment. IMEI check failed, i.e. the IMEI is either black listed or not white listed.
    009 Call barred. Operator barred the MSISDN number.
    010 Facility not supported. VLR in the PLMN does not support MT short message service.
    011 Subscriber busy for MT short message. Mobile terminated short message transfer cannot be completed because:
    a. another MT SM transfer is going on and the delivery node does not support buffering.
    b. another MT SM transfer is going on and it is not possible to buffer the message for later delivery.
    c. the message was buffered but it is not possible to deliver the message before the expiry of the buffering time defined in GSM 03.40.
    012 System failure. Task cannot be completed because of a problem in another entity.
    013 Data missing. Necessary parameter is not present in the primitive.
    014 Unexpected data value. Necessary data is badly formatted in the primitive.
    015 Unidentified subscriber.
    016 Absent subscriber. No paging response.
    017 Absent subscriber. IMSI detached.
    018 Absent subscriber. Roaming restriction.
    047 Application context not supported.
    049 SMS discarded. This error is specific to IP-based protocols like SMPP.
    050 Temporary error received from peer SMSC.
    051 SMS malformed. SMS is not formed correctly. This error is specific to IP-based protocols like SMPP
    052 SMS expired.
    053 Insufficient credit. The user has insufficient credit/not allowed to send to that destination.
    054 Invalid destination. Receiver is not a valid number.
    055 Unable to find outbound route for this SMS.
    056 SMS buffered.
    057 Timeout waiting for response from peer.
    058 Throttling error. The user has exceeded allowed message limit.
    059 SMS suspected spam message.
    061 Subscriber blacklisted.
    062 Subscriber not white listed.
    063 Invalid sender length.
    065 System down for maintenance.
    068 SMS flooding detected.
    069 Invalid sender ID.
    071 Subscriber opted out from receiving SMS.
    074 SMS rejected. Error received from peer SMSC.
    075 SMS rejected. Inappropriate SMS content.
    076 Sender ID blacklisted.
    077 Sender ID not white listed.
    094 URL blacklisted.
    095 URL not white listed.
    096 Message expired in system with no final status from carrier.
    255 Unknown error.

    Receive SMS

    Receiving POST request

    require 'sinatra'
    require 'sinatra/multi_route'
    require 'json'
    
    helpers do
      def parsed_body
         json? ? JSON.parse(request.body.read) : {}
      end
    
      def json?
        request.content_type == 'application/json'
      end
    end
    
    route :get, :post, '/webhooks/inbound-sms' do
      puts params.merge(parsed_body)
      status 204
    end
    
    set :port, 3000
    
    from flask import Flask,request
    
    app = Flask(__name__)
    
    @app.route('/webhooks/inbound-sms', methods=['POST'])
    def receiveSMS():
        data = request.form
    
        _from = data['mocean-from']
        _to = data['mocean-to']
        _time = data['mocean-time']
        _text = data['mocean-text']
        _keyword = data['mocean-keyword']
        _coding = data['mocean-coding']
    
    const app = require('express')();
    const bodyParser = require('body-parser');
    
    app.use(bodyParser.json());
    app.use(bodyParser.urlencoded({ extended: true }));
    
    app.route('/webhooks/inbound-sms').post(handleMoSms);
    function handleMoSms(req, res)
    {
      console.log(res.body);
      res.status(204).send();
    }
    
    app.listen(8080)
    
    import mocean.system.*;
    
    class program {
    
        public static void main(String [] args)
        {
            Client token = new Client("API_KEY_HERE","API_SECRET_HERE");
            Mocean mocean = new Mocean(token);
    
            try
            {
                post("/webhooks/inbound-sms", (req, res) -> {               
    
                    for (String param : req.queryParams()) 
                    {
                        System.out.printf("%s: %s\n", param, req.queryParams(param));
                    }
    
                    res.status(204);
                    return "";
                });
            }
            catch(Exception e)
            {
                System.out.println(e.getMessage());
            }
        }
    }
    
    <?php
    use \Psr\Http\Message\ServerRequestInterface as Request;
    use \Psr\Http\Message\ResponseInterface as Response;
    
    require 'vendor/autoload.php';
    
    $app = new \Slim\App;
    
    $handler = function (Request $request, Response $response) {
        $params = $request->getParsedBody();
    
        // Fall back to query parameters if needed
        if (!count($params)){
            $params = $request->getQueryParams();
        }
    
        error_log(print_r($params, true));
    
        return $response->withStatus(204);
    };
    
    $app->post('/webhooks/inbound-sms', $handler);
    
    $app->run();
    

    Request sent from Mocean

    > POST /webhooks/inbound-sms HTTP/1.1
    > Host: example.com
    > Accept: */*
    > Content-Length: 114
    > Content-Type: application/x-www-form-urlencoded
    
    {
      mocean-from: 60123456789,
      mocean-to: 63001,
      mocean-keyword: MOC,
      mocean-text: Hello+World,
      mocean-coding: 1,
      mocean-time: 2018-12-30 23:59:59
    }
    

    If you rent one or more virtual numbers from Mocean, inbound messages to that number are sent to your webhook endpoint.

    When you receive an inbound message, you must send a 2xx response. If you do not send a 2xx response Mocean will resend the inbound message for the next 24 hours.

    Note: If you're using localhost environment for receiving Inbound SMS, you will need to make your local environment publicly available so Mocean API server can reach your local server. We recommend you try ngrok to do this quite easily.

    POST https://example.com/webhooks/inbound-sms

    Request Body

    Parameter Format Descriptions
    mocean-from number Phone number of the original SMS sender.
    mocean-to number Phone number of the original SMS recipient, normally the short code (e.g. 63001).
    mocean-time datetime The datetime when the message is received by SMS gateway. (Format YYYY-MM-DD hh:mm:ss).
    mocean-text string Content of the SMS.
    mocean-keyword string Keyword used for the MO.
    mocean-coding number Message type of SMS. 1 for text/Mobile telephony character set and 3 for Unicode SMS.

    Verify API

    Overview

    The Verify API allows you to send a random generated code by SMS or Voice call to prove a user can be contacted at a specific phone number.

    This is useful for:

    By default, the code is first sent via text message (SMS). If there is no reply the Verify API will attempt to send another voice call using text-to-speech (TTS).

    Verify Request

    Send Code

    Example request

    curl -X POST https://rest.moceanapi.com/rest/1/verify/req \
      -d "mocean-api-key=API_KEY_HERE&
          mocean-api-secret=API_SECRET_HERE&
          mocean-to=60123456789&
          mocean-brand=BRAND_NAME"
    
    const moceanjs = require('mocean-sdk');
    
    var token = new moceanjs.Client('API_KEY_HERE','API_SECRET_HERE');
    var mocean = new moceanjs.Mocean(token);
    
    mocean.verify_request().create({
      'mocean-to': '60123456789',
      'mocean-brand': 'BRAND_NAME'
    }).send((err,res) => {    
      if (err) throw err;
      console.log(res);
    });
    
    <?php
    require_once '../vendor/autoload.php';
    
    $token = new Mocean\Client\Credentials\Basic(
        'API_KEY_HERE',
        'API_SECRET_HERE'
    );
    $mocean = new Mocean\Client($token);
    
    $res = $mocean->verify()->start([
        'mocean-to' => '60123456789',
        'mocean-brand' => 'BRAND_NAME',
        'mocean-resp-format' => 'json'
    ]);
    
    echo $res;
    ?>
    
    Mocean.Verify.Verify _verification = new Mocean.Verify.Verify(){
        mocean_to = "60123456789",
        mocean_brand = "BRAND_NAME"
    };
    
    string response = Mocean.Verify.Client.Start(_verification, creds);
    
    require "moceansdk"
    
    token = Client.new("API_KEY_HERE", "API_SECRET_HERE")
    mocean = Mocean.new(token)
    
    res = mocean.verify_request.create({
        "mocean-to" => "60123456789",
        "mocean-brand" => "BRAND_NAME"
    }).send()
    
    puts res
    
    String res = mocean.verify_request().setTo("60123456789")
                 .setBrand("BRAND_NAME")
                 .send();
    
    System.out.println(res);
    
    from moceansdk import Mocean, Client
    
    token = Client("API_KEY_HERE", "API_SECRET_HERE")
    mocean = Mocean(token)
    
    res = mocean.verify_request.create({
        "mocean-to": "60123456789",
        "mocean-brand":"BRAND_NAME"
    }).send()
    
    print(res)
    

    Successful reponse

    {
      "reqid":"XXXXXXXXXXXXXXXXXXXXXX",
      "status":"0"
    }
    

    Send a random generated code to a specified contact number for verification purpose.

    POST https://rest.moceanapi.com/rest/1/verify/req

    Parameter Format Description
    mocean-api-key
    required
    string Your account API key.
    mocean-api-secret
    required
    string Your account API secret.
    mocean-to
    required
    string Phone number of the receiver. (must include country code, e.g. 60123456789)
    mocean-brand
    required
    string The name of the company or application you are using for verification.
    mocean-from
    optional
    string SMS Sender ID will be displayed as sender of SMS.
    mocean-resp-format
    optional
    string Response format. By default, response format will be returned in XML. Supported formats are:
    • XML
    • JSON
    mocean-code-length
    optional
    number The length of verification code. Possible values are 4 and 6 digits.

    Default is 4 or as defined in account.
    mocean-pin-validity
    optional
    number The expiring time of generated code. Values can be number between 60 to 3600 seconds. Default is 300 or as defined in account.
    mocean-next-event-wait
    optional
    number Each channel waiting time for verification code before next attemp.

    An integer value between 60 and 900 seconds.

    The defaut mocean-next-event-wait will follow your account setting if configured else default is 60 seconds.
    Code Descriptions
    0 OK. No error encountered.
    1 Throttled. You are trying to send more than allowed requests per second.
    2 Authorization failed.
    3 System error, please try again.
    4 Missing mandatory parameter: brand
    5 Missing mandatory parameter: receiver phone number
    6 Receiver phone number is invalid.
    7 Missing mandatory parameter: request id
    8 Missing mandatory parameter: pin code
    9 Brand name too long.
    10 Sender ID is too long.
    11 Invalid code length.
    13 Invalid pin validity.
    14 Invalid next event wait time.
    15 Incorrect code was provided too many times. Maximum retry limit is 3.
    16 Incorrect code.
    17 Associated verify request id not found.
    18 Insufficient balance.
    19 Concurrent verify request to the same number and brand are not allowed.
    20 Request could not be routed.
    21 System error, request could not be processed.
    22 Unknown request.

    Verify Code

    Example request

    curl -X POST https://rest.moceanapi.com/rest/1/verify/check \
      -d "mocean-api-key=API_KEY_HERE&
          mocean-api-secret=API_SECRET_HERE&
          mocean-reqid=MOCEAN_REQUEST_ID&
          mocean-code=123456&
          resp-format=json"
    
    const moceanjs = require('mocean-sdk');
    
    var token = new moceanjs.Client('API_KEY_HERE','API_SECRET_HERE');
    var mocean = new moceanjs.Mocean(token);
    
    mocean.verify_validate().create({
      "mocean-reqid": "MOCEAN_REQUEST_ID",
      "mocean-code": "123456"
    }).send((err, res) => {
      if(err) throw err;
      console.log(res);
    });
    
    <?php
    require_once '../vendor/autoload.php';
    
    $token = new Mocean\Client\Credentials\Basic(
        'API_KEY_HERE',
        'API_SECRET_HERE'
    );
    $mocean = new Mocean\Client($token);
    
    $res = $mocean->verify()->check([
        'mocean-reqid' => 'MOCEAN_REQUEST_ID',
        'mocean-code' => '123456',
        'mocean-resp-format' => 'json'
    ]);
    
    echo $res;
    ?>
    
    Mocean.Verify.Verify _verification = new Mocean.Verify.Verify(){
        mocean_reqid = "MOCEAN_REQUEST_ID",
        mocean_code = "123456"
    };
    
    string response = Mocean.Verify.Client.Check(_verification, creds);
    
    from moceansdk import Mocean, Client
    
    token = Client("API_KEY_HERE", "API_SECRET_HERE")
    mocean = Mocean(token)
    
    res = mocean.verify_validate.create({
        "mocean-reqid": "MOCEAN_REQUEST_ID",
        "mocean-code": "123456"
    }).send()
    
    print(res)
    
    require "moceansdk"
    
    token = Client.new("API_KEY_HERE", "API_SECRET_HERE")
    mocean = Mocean.new(token)
    
    res = mocean.verify_validate.create({
        "mocean-reqid" => "MOCEAN_REQUEST_ID",
        "mocean-code" => "123456"
    }).send()
    
    puts res
    
    String res = mocean.verify_validate().setReqid("MOCEAN_REQUEST_ID")
                 .setCode("123456")
                 .send();
    
    System.out.println(res);
    

    Successful reponse

    {
      "reqid": "XXXXXXXXXXXXXXXXXXXXXXXXX",
      "status": "0",
      "price": "0.1000",
      "currency": "EUR"
    }
    

    To use Verify Code you:

    POST https://rest.moceanapi.com/rest/1/verify/check

    Parameter Format Description
    mocean-api-key
    required
    string Your account API key.
    mocean-api-secret
    required
    string Your account API secret.
    mocean-reqid
    required
    string The identifier of theVerify request to check. This is the request ID you received in the Verify request response.
    mocean-code
    required
    string The CODE given by your user.
    mocean-resp-format
    optional
    string Response format. By default, response format will be returned in XML. Supported formats are:
    • XML
    • JSON

    Query API

    Overview

    This is an overview of Query API, this is where you do check Balance, Pricing, Messages Status and everything other than Sending SMS and Verify transaction.

    Get Balance

    Example request

    curl -X GET "https://rest.moceanapi.com/rest/1/account/balance?
                 mocean-api-key=API_KEY_HERE&
                 mocean-api-secret=API_SECRET_HERE"
    
    require "moceansdk"
    
    token = Client.new("API_KEY_HERE", "API_SECRET_HERE")
    mocean = Mocean.new(token)
    
    res = mocean.balance.inquiry()
    puts res
    
    from moceansdk import Mocean, Client
    
    token = Client("API_KEY_HERE", "API_SECRET_HERE")
    mocean = Mocean(token)
    
    res = mocean.balance.inquiry()
    print(res)
    
    <?php
    require_once '../vendor/autoload.php';
    
    $token = new Mocean\Client\Credentials\Basic(
        'API_KEY_HERE',
        'API_SECRET_HERE'
    );
    $mocean = new Mocean\Client($token);
    
    $res = $mocean->account()->getBalance([
        'mocean-resp-format' => 'json'
    ]);
    
    echo $res;
    ?>
    
    const moceanjs = require('mocean-sdk');
    
    var token = new moceanjs.Client('API_KEY_HERE','API_SECRET_HERE');
    var mocean = new moceanjs.Mocean(token);
    
    mocean.balance().inquiry((err, res) => {
      if(err) throw err;
    
      console.log(res);
    });
    
    String res = mocean.balance().inquiry();
    System.out.println(res);        
    
    Mocean.Account.Balance _balance = new Mocean.Account.Balance()
    {
        mocean_resp_format = "json"
    };
    
    string response = Mocean.Account.Client.GetBalance(_balance, creds);
    

    Successful reponse

    {
      "status":0,
      "value":100.0000
    }
    

    Unsuccessful reponse

    {
      "status":1,
      "err_msg":"Authorization+failed"
    }
    

    Retrieve your current account balance via Mocean API Server at Base URL

    Response will be given for every request in XML format by default. In fact, you get to choose between XML or JSON format by setting value for optional parameter "mocean-resp-format" and submit along your account balance query.

    GET https://rest.moceanapi.com/rest/1/account/balance

    Parameter Format Description
    mocean-api-key
    required
    string Your account API key.
    mocean-api-secret
    required
    string Your account API secret.
    mocean-resp-format
    optional
    string Response format. By default, response format will be returned in XML. Supported formats are:
    • XML
    • JSON

    Account Pricing

    Example request

    curl -X GET "https://rest.moceanapi.com/rest/1/account/pricing?
                 mocean-api-key=API_KEY_HERE&
                 mocean-api-secret=API_SECRET_HERE"
    
    require "moceansdk"
    
    token = Client.new("API_KEY_HERE", "API_SECRET_HERE")
    mocean = Mocean.new(token)
    
    res = mocean.pricing_list.inquiry()
    puts res
    
    from moceansdk import Mocean, Client
    
    token = Client("API_KEY_HERE", "API_SECRET_HERE")
    mocean = Mocean(token)
    
    res = mocean.price_list.inquiry()
    print(res)
    
    <?php
    require_once '../vendor/autoload.php';
    
    $token = new Mocean\Client\Credentials\Basic(
        'API_KEY_HERE',
        'API_SECRET_HERE'
    );
    $mocean = new Mocean\Client($token);
    
    $res = $mocean->account()->getPricing([
        'mocean-resp-format' => 'json'
    ]);
    
    echo $res;
    ?>
    
    const moceanjs = require('mocean-sdk');
    
    var token = new moceanjs.Client('API_KEY_HERE','API_SECRET_HERE');
    var mocean = new moceanjs.Mocean(token);
    
    mocean.pricing_list().inquiry((err, res) => {
      if(err) throw err;
      console.log(res);
    });
    
    String res = mocean.pricing_list().setRespFormat("json").inquiry();
    System.out.println(res);
    
    Mocean.Account.Pricing _pricing = new Mocean.Account.Pricing()
    {
        mocean_resp_format = "json",
        mocean_mcc = "502",
        mocean_mnc = "01",
        mocean_delimiter = ";",
    
    };
    
    string response = Mocean.Account.Client.GetPricing(_pricing, creds);
    

    Successful response

    {
      "status":0,
      "destinations":[
        {
          "country":"Default",
          "operator":"Default",
          "mcc":"Default",
          "mnc":"Default",
          "price":"0.0100",
          "currency":"MYR"
        },
        {
          "country":"Malaysia",
          "operator":"Default",
          "mcc":"502",
          "mnc":"Default",
          "price":"0.0040",
          "currency":"MYR"          
        },
        {
          "country":"Malaysia",
          "operator":"Celcom",
          "mcc":"502",
          "mnc":"13,19",
          "price":"0.0020",
          "currency":"MYR"          
        }
      ]
    }
    

    Unsuccessful reponse

    {
      "status":1,
      "err_msg":"Authorization failed"
    }
    

    Retrieve your account's pricing & supported destination via Mocean API Server at Base URL

    Response will be given for every request in XML format by default. In fact, you get to choose between XML or JSON format by setting value for optional parameter "mocean-resp-format" and submit along your account pricing query.

    GET https://rest.moceanapi.com/rest/1/account/pricing

    Parameter Format Description
    mocean-api-key
    required
    string Your account API key.
    mocean-api-secret
    required
    string Your account API secret.
    mocean-resp-format
    optional
    string Response format. By default, response format will be returned in XML. Supported formats are:
    • XML
    • JSON
    mocean-mcc
    optional
    number User can specify to get pricing for a particular Mobile Country Code (MCC).
    mocean-mnc
    optional
    number Mobile Network Code (MNC) needs to be specified if user passes in mocean-mcc. User is allowed to pass ONE MNC only per query.
    mocean-delimiter
    optional
    string Delimiter to be used in CSV format. By default, delimiter is set to “;”. User can specify to set delimiter to “;”, “:” or “

    Message Status

    Example request

    curl -X GET "https://rest.moceanapi.com/rest/1/report/message?
                 mocean-api-key=API_KEY_HERE&
                 mocean-api-secret=API_SECRET_HERE&
                 mocean-msgid=MSG_ID"
    
    require "moceansdk"
    
    token = Client.new("API_KEY_HERE", "API_SECRET_HERE")
    mocean = Mocean.new(token)
    
    res = mocean.message_status.inquiry({
        'mocean-msgid'=>'example0528181518667384.0002',
        'mocean-resp-format'=>'JSON'
    })
    puts res
    
    const moceanjs = require('mocean-sdk');
    
    var token = new moceanjs.Client('API_KEY_HERE','API_SECRET_HERE');
    var mocean = new moceanjs.Mocean(token);
    
    mocean.pricing_list().inquiry((err, res) => {
        if (err) throw err;
        console.log(res);
    });
    
    from moceansdk import Mocean, Client
    
    token = Client("API_KEY_HERE", "API_SECRET_HERE")
    mocean = Mocean(token)
    
    res = mocean.message_status.inquiry({'mocean-msgid':'example0528181518667384.0002'})
    print(res)
    
    <?php
    require_once '../vendor/autoload.php';
    
    $token = new Mocean\Client\Credentials\Basic(
        'API_KEY_HERE',
        'API_SECRET_HERE'
    );
    $mocean = new Mocean\Client($token);
    
    $res = $mocean->message()->search([
        'mocean-msgid' => 'example0528181518667384.0002',
        'mocean-resp-format' => 'json'
    ]);
    
    echo $res;
    ?>
    
    String res = mocean.message_status().setMsgid("example0528181518667384.0002").inquiry();
    System.out.println(res);
    
    Mocean.Message.Message _message = new Mocean.Message.Message()
    {
        mocean_resp_format = "json",
        mocean_msgid = "example0528181518667384.0002"
    
    };
    
    string response = Mocean.Message.Client.Search(_message, creds);
    

    Successful response

    {
      "status":0,
      "message_status":1,
      "msgid":"cust20013050311050614001",
      "credit_deducted":"1"
    }
    

    Unsuccessful response

    {
      "status":1,
      "err_msg":"Authorization failed"
    }
    

    Query your Outbound SMS's current status via Mocean API Server at Base URL

    Response will be given for every request in XML format by default. In fact, you get to choose between XML or JSON format by setting value for optional parameter "mocean-resp-format" and submit along your query.

    GET https://rest.moceanapi.com/rest/1/report/message

    Parameter Format Description
    mocean-api-key
    required
    string Your account API key.
    mocean-api-secret
    required
    string Your account API secret.
    mocean-msgid
    required
    string Message ID associated with the transaction which given during SMS submission.
    mocean-resp-format
    optional
    string Response format. By default, response format will be returned in XML. Supported formats are:
    • XML
    • JSON
    Parameter Description
    1 Transaction success.
    2 Transaction failed.
    3 Transaction failed due to message expired.
    4 Transaction pending for final status.
    5 Transaction not found.

    Response Status

    Mocean API uses the following error codes:

    Status Code Meaning
    0 OK. No error encountered.
    1 Authorization failed. Invalid mocean-api-key or mocean-api-secret.
    NOTE: When this error is encountered, NO SMS is sent to any of the receivers.
    2 Insufficient balance. Not enough credit in the account to send to at least one of the receivers.
    4 At least one of the destination numbers is not white listed.
    5 At least one of the destination numbers is black listed.
    6 No destination number specified.
    8 Sender ID not found.
    9 Invalid UDH field.
    10 Invalid mclass field.
    17 Invalid validity field.
    19 Invalid character set or message body.
    20 Insufficient headers for sending SMS.
    23 Empty mocean-text.
    24 Unknown error.
    26 Invalid schedule format. (Hint: must have leading zero for time.)
    2007-03-02 08:55:00 is correct.
    2007-03-02 8:55:00 is not correct.
    27 Max number of receivers in a single request reached. Too many receivers in mocean-to field.
    28 Invalid destination number. Receiver is invalid after stripping all non-numerics.
    29 Message body is too long.
    32 Message throttled.
    34 Unknown request.
    37 Invalid sender length.
    40 System down for maintenance.
    43 SMS flooding detected.
    44 Invalid Sender ID.
    45 System error, please retry later.
    48 At least one of the senders is black listed.
    49 At least one of the senders is not white listed.
    50 Inappropriate content detected.