Difference between revisions of "NATS5 REST API Message POST message"
From TMM Wiki
Jump to navigationJump to searchLine 1: | Line 1: | ||
{{NATS5 Manual | {{NATS5 Manual | ||
− | | | + | | show_api_admin_message_section = true |
}} | }} | ||
== '''POST /message/message''' == | == '''POST /message/message''' == |
Latest revision as of 15:59, 9 August 2019
POST /message/message
Description
- Get a message
Resource URL
- http://domain/api/message/message
- Replace domain with the nats domain
- POST
Response Format
- JSON
- HTTP headers
Parameters
Parameters can be sent as url encoded params
- subject
- type: string
- required
- body
- type: string
- required
- recipients
- type: string_list (Either a comma-separated string of strings, or a JSON array of strings)
- required
- messageid
- type: digit
- optional
Example Request
Method: POST
URL: http://domain/api/message/message
Form Data:
- subject: testSubject
- body: testBody
- recipients: all
Response:
{ "success": true, "result": "message sent" }
Example Code
PHP
<?php $headers = array( //set your username and API key here 'api-key: 44b5498dbcb481a0d00b404c0169af62', 'api-username: tmm1phrvezsbu' ); $url = 'http://yourdomain.com'; //set your NATS URL here $data = Array( 'subject' => 'testSubject', 'body' => 'testBody', 'recipients' => 'all', ); $request = Array( 'method' => 'POST', 'path' => 'v1/message/message', 'data' => $data ); /*code below is the same for (almost) every API call */ $curl = curl_init(); $url = $url.'/api/'.$request['path']; $query = http_build_query($request['data']); if($request['method'] == 'GET'){ //add query string parameters to the end of the url $url = $url.'?'.$query; }else{ //send parameters as POST fields curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $query); if($request['method'] != 'POST'){ $headers[] ='X-HTTP-Method: '.$request['method']; //send custom request method } } curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); $resp = curl_exec($curl); //dumps an associative array representation of the json var_dump(json_decode($resp, true)); // Close request to clear up some resources curl_close($curl); ?>