Invision Community 4: SEO, prepare for v5 and dormant account notifications By Matt Monday at 02:04 PM
Refsmmat Posted August 21 Posted August 21 Hi, I am currently trying to create a message using the https://invisioncommunity.com/developers/rest-api?endpoint=core/messages/POSTindex api. The "to" parameter is stated to be of type "array". I only need to pass one recipient there, but regardles of how I format the paramater (when testing the api in Postman), I always get "errorCode": "1C374/3", "errorMessage": "INVALID_RECIPIENT" back. I tried to give the user id just as number 2, or as json formated array [2], or a string in json formated array ["2"]. Nothing seems to work. Am I doing something obvious wrong or is there a problem with this api parameter? The documentation say, that "1C374/3" means that the paramater haven't been given at all. Creating forum topic, posts, download comments a.s.o. works fine via the api, I just struggle with sending messages. Regards, Tom.
Daniel F Posted August 21 Posted August 21 [2] should work fine. Can you post your whole request? Here's a working example code https://invisioncommunity.com/forums/topic/473252-api-rest-apicoremessages/?do=findComment&comment=2937939
Refsmmat Posted August 21 Author Posted August 21 This is what Postman creates as CURL command line curl --location 'https://xxx/api/core/messages/?key=xxx' \ --header 'Cookie: PHPSESSID=0s52vp09q9qdffb2ahi83adq4c; ips4_IPSSessionFront=84gk38i1l4cra3jn48kljjevol; ips4_clearAutosave=newContentItem-forums%2Fforums-147' \ --form 'from="4"' \ --form 'to="[2]"' \ --form 'title="test title"' \ --form 'body="test body"' or as PHP code <?php $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://xxx/api/core/messages/?key=xxx', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => array('from' => '4','to' => '[2]','title' => 'test title','body' => 'test body'), CURLOPT_HTTPHEADER => array( 'Cookie: PHPSESSID=0s52vp09q9qdffb2ahi83adq4c; ips4_IPSSessionFront=84gk38i1l4cra3jn48kljjevol; ips4_clearAutosave=newContentItem-forums%2Fforums-147' ), )); $response = curl_exec($curl); curl_close($curl); echo $response; Is the problem maybe that Postman paases the parameter as strings, enclosed in ' ' ? For the from parameter, and all the other apis I have already used that always worked. In my application I use a wrapper around CURL which creates this request (with all parameters in the url) which also fails with the same error: ~POST /api/core/messages/?body=Ich%20bin%20ein%20Body&from=4&title=Ich%20bin%20ein%20Subject&to=%5B2%5D HTTP/2 ~Host: xxx ~authorization: Basic xxx ~accept: */* ~content-type: multipart/form-data ~user-agent: SwyxIPSIntegration/1.0.0 ~content-length: 0
Refsmmat Posted August 21 Author Posted August 21 (edited) Using Postman and also passing all parameters within the URL doesn't change the outcome, even without escaping the [ ] curl --location --globoff --request POST 'https://xxx/api/core/messages/?key=xxx&from=4&body=Ich%20bin%20ein%20Body&title=Ich%20bin%20ein%20Subject&to=[2]' --header 'Cookie: PHPSESSID=0s52vp09q9qdffb2ahi83adq4c; ips4_IPSSessionFront=84gk38i1l4cra3jn48kljjevol; ips4_clearAutosave=newContentItem-forums%2Fforums-147' Edited August 21 by Refsmmat
Refsmmat Posted August 22 Author Posted August 22 Would you (or a colleague of yours) be able to provide a CURL command line that generates a message? I have spent a lot of time now with trying to get the "to" parameter accepted by the IPS REST API, but without any success at all. This is how it should work, according to your documentation: curl --location "https://xxx/api/core/messages/?key=xxx" --header "Content-Type: multipart/form-data" --header "Host: xxx" --header "accept: */*" --form "from=4" --form "to=[2]" --form "title=test title" --form "body=test body" But all I get back is this: { "errorCode": "1C374\/3", "errorMessage": "INVALID_RECIPIENT" } This is the REST API log in the ACP for the above request: POST core/messages/ Request Data { "key": "xxx", "from": "4", "to": "[2]", "title": "test title", "body": "test body" } Response { "errorCode": "1C374\/3", "errorMessage": "INVALID_RECIPIENT" }
Solution Stuart Silvester Posted August 22 Solution Posted August 22 Hi, It's an HTTP POST array, "to[]=2" should work for you.
Recommended Posts