The request sample of an API is as follows:
{
"channel":"sms",
"source":"+1xxxxxxxx6",
"destination":[
"+1xxxxxxxx"
],
"content":{
"text":"Hey, Peter. It's Rick.",
"location":{
"longitude":"XX.9716",
"latitude":"XX.5946",
"label":"California",
"address":"Test Address"
},
"media":{
"url":"https://media.example.com/file",
"caption":"your media file"
}
},
"events_url":"https://events.example.com/message"
}
Being a newbie, I am having difficulty in setting up the setContent, i tried the following and it results in error:
->setChannel("XXXXXX")
->setSource("+XXXXXXX")
->setDestination(["+1XXXXXXXX"])
->setContent(["media"]["url"] => "https://Big_buck_bunny_poster_big.jpg",
"caption" => "My media file test"])
->setEventsUrl("example.com/events");
Error is as follows:
Error:
PHP Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ']' in
->setContent(["text" => "This is test message 3"]) works fine..
I know that this is something basic but being a newbie i can't figure it out. Requesting help.
UPDATE: Error in documentation
-
The brackets "]" at the end of "My media file test" does not starts anywhereBack2Lobby– Back2Lobby2020年10月10日 11:03:18 +00:00Commented Oct 10, 2020 at 11:03
-
1The issue was due to non-updated API documentation. Sorry for the inconvenience caused.Pamela– Pamela2020年10月19日 02:27:13 +00:00Commented Oct 19, 2020 at 2:27
2 Answers 2
unexpected '=>' (T_DOUBLE_ARROW) error is with ["media"]["url"]
["media"]["url"] => "https://Big_buck_bunny_poster_big.jpg",
"caption" => "My media file test"]
you have to initialize an array like
[
"text" => "test text",
"media" => [
"url" => "https://Big_buck_bunny_poster_big.jpg",
"caption" => "My media file test"
]
]
11 Comments
media array, not outside.You have to create and set following array:
[
'media' => [
'url' => 'https://Big_buck_bunny_poster_big.jpg',
'caption' => 'My media file test'
]
]
Look at the format of sample JSON and make the same levels (dimensions) of your array.
If all fields are mandatory you should send following array:
[
'text' => 'Your text',
'location' => [
'longitude' => 'XXX',
'latitude' => 'XXX',
'label' => 'your label',
'address' => 'your address'
],
'media' => [
'url' => 'https://Big_buck_bunny_poster_big.jpg',
'caption' => 'My media file test'
]
]