Issue with API call

I am trying to write a php script to send a message but did not manage to succeed even with the example given.

\<?php $ch = curl\_init(); curl\_setopt($ch, CURLOPT\_URL, "https://gamethrive.apiary-mock.com/api/v1/notifications"); curl\_setopt($ch, CURLOPT\_RETURNTRANSFER, TRUE); curl\_setopt($ch, CURLOPT\_HEADER, FALSE); curl\_setopt($ch, CURLOPT\_POST, TRUE); curl\_setopt($ch, CURLOPT\_POSTFIELDS, "{\"app\_id\": \"5eb5a37e-b458-11e3-ac11-000c2940e62c\",\n\"contents\": {\"en\": \"English Message\"},\n\"isAndroid\": true,\n\"isIos\": true,\n\"included\_segments\": [\"All\"],\n\"send\_after\": \"Fri May 02 2014 00:00:00 GMT-0700 (PDT)\"}"); curl\_setopt($ch, CURLOPT\_HTTPHEADER, array("Content-Type: application/json")); $response = curl\_exec($ch); curl\_close($ch); var\_dump($response); ?\>

Also what is the correct URL to use?

I am seeing a few there.

https://gamethrive.apiary-mock.com/api/v1/notifications

https://gamethrive.com/api/v1/notifications

https://gamethrive.apiary.io/api/v1/notifications

Thanks in advance.

Hi Falcon. I think the issue is that you need to add the Authentication header. Similar to:

Authorization: Basic ZTNhYmEzZmMtZGE2NS0xMWUzLWJmOWUtZWJjMTFjZTZiYjX5

That long string on the end is your GameThrive API key. You can get it from the settings page for your GameThrive app.

Also, remove the “\n”'s from your post fields. Everything else looks fine.

Oh, the correct url is: https://gamethrive.com/api/v1/notifications

Tried that too but it doesn’t work.

curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);

curl_setopt($ch, CURLOPT_USERPWD, “$username:$password”);

$username is the API key and password is empty.

The page doesn’t seem to exist.

That URL only responds to POST requests (like in your PHP code), so trying to load it in your browser won’t work.

Here’s a screenshot of the API call going through. This is with a chrome extension called Advanced Rest Client, and using a test app that I created.

https://www.dropbox.com/s/do2t5hkvwhyb040/Screenshot%202014-05-13%2000.31.46.png

Thanks.

May I know if my approach to setting the API key is correct?  I cannot find any example in your documentation. 

I tried to do it manually using the chrome extension and now I am getting the error “app_id not found” though I am quite sure I copied it correctly.

Finally got it to work!!!

Just for your info.  The following line will need to be included when using https with curl.

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

You guys might want to update your PHP example in your documentation.  I will try out Android next.  :)

Excellent! Glad you got it working :). That’s interesting what the solution turned out to be, I’ll investigate why that line was needed and update our documentation shortly.

Hi guys,

Where do you get the server-side API document from ? I checked their site ( http://docs.gamethrive.apiary.io/ ) but didn’t see any.

thanks

Hey Yosu. That is the server side documentation page.

We don’t have any server specific plugins, but you can interact with our API by making HTTP requests from whatever programming language you’re using on your server. 

In our API docs, you can get an example of how to make the http requests from various programming languages by clicking on the documentation boxes. Make sure to make them to https://gamethrive.com/api/v1/… instead of https://gamethrive.apiary-mock.com/api/v1/ (which is what the examples have) .

Hi Falcon. I think the issue is that you need to add the Authentication header. Similar to:

Authorization: Basic ZTNhYmEzZmMtZGE2NS0xMWUzLWJmOWUtZWJjMTFjZTZiYjX5

That long string on the end is your GameThrive API key. You can get it from the settings page for your GameThrive app.

Also, remove the “\n”'s from your post fields. Everything else looks fine.

Oh, the correct url is: https://gamethrive.com/api/v1/notifications

Tried that too but it doesn’t work.

curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);

curl_setopt($ch, CURLOPT_USERPWD, “$username:$password”);

$username is the API key and password is empty.

The page doesn’t seem to exist.

That URL only responds to POST requests (like in your PHP code), so trying to load it in your browser won’t work.

Here’s a screenshot of the API call going through. This is with a chrome extension called Advanced Rest Client, and using a test app that I created.

https://www.dropbox.com/s/do2t5hkvwhyb040/Screenshot%202014-05-13%2000.31.46.png

Thanks.

May I know if my approach to setting the API key is correct?  I cannot find any example in your documentation.