How to structure JSON to be sent over PHP's cURL
<p>I have an api which works fine when I use POSTMAN, but now that I am trying to send it with PHP I am getting an API error message in response. </p>

<blockquote>
  <p>Format Error: The exception message is 'The incoming message has an unexpected message format 'Raw'</p>
</blockquote>

<p>Which I am sure is related to my data structure. can someone tell me where I am going wrong?</p>

<p><strong>Header</strong></p>

<pre><code>Connection: Keep-Alive
Content-Type: application/json; charset=utf-8
</code></pre>

<p><strong>JSON Body</strong></p>

<pre><code>{
    "accessID": "ASASD22",
    "password": "DASD2DQA",
    "messages": [
        {
            "DestinationID": "22D2D2D22D",
            "UserMessageID": 133,
            "RawPayload": [1,31, 34, 43]
        }
    ]
}
</code></pre>

<p>Here is the PHP code I wrote, but returns an error code; can you guys see any issues?</p>

<pre><code>$headers= array('Connection: Keep-Alive','Content-Type: application/json; charset=utf-8','Connection: Keep-Alive'); 

$data = array(
    "accessID" =&gt; "ASASD22",
    "password" =&gt; "DASD2DQA",
    "messages" =&gt;  array(
    "DestinationID" =&gt; "22D2D2D22D",
    "UserMessageID" =&gt; "133",
    "RawPayload" =&gt; "[1,31, 34, 43]"
    )
);

$url_send ="http://api.SITE.com/RST-MESSAGE.svc/submit.json/";
$str_data = json_encode($data);

function sendPostData($url, $post){
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS,$post);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
    $result = curl_exec($ch);
    curl_close($ch);
    return $result;
}

echo " " . sendPostData($url_send, $str_data);
</code></pre>