0

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

2
  • The brackets "]" at the end of "My media file test" does not starts anywhere Commented Oct 10, 2020 at 11:03
  • 1
    The issue was due to non-updated API documentation. Sorry for the inconvenience caused. Commented Oct 19, 2020 at 2:27

2 Answers 2

1

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"
    ]
] 
Sign up to request clarification or add additional context in comments.

11 Comments

Sorry..Error: Invalid value for 'content_type', must be one of 'text', 'location'
That error means you are missing one of required "text" or "location" in your payload, see my above edit, and post your full payload example if doesn't work
ok may caption was not in media, try with above edit.
Caption is in media array, not outside.
The issue was with API documentation. Your answer too was helpful. Thank You.
|
1

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'
    ]
]

3 Comments

Same error: Exception when calling MessageApi->sendMessage: Invalid value for 'content_type', must be one of 'text', 'location'
Look at the API documentation and check which fields are mandatory.
It is one of either text, location or media is allowed

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.