How to create Custom REST API in SuiteCRM - php

Im new to SuiteCRM.
Can any one tell how to create a REST API from scratch for a custom module.
I went through the developer guide, but i need to know like in which file those REST API call has to be made (Referring the PHP example from the below link)
http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_6.5/Application_Framework/Web_Services/Examples/REST/PHP/Creating_Documents/#Overview

If you want to add your own API to your module, you probably are looking for https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_6.5/Application_Framework/Web_Services/Extending_Web_Services/
The example code you posted calls the REST API from the "outside" and works independently of Sugar.
So you can just save the example anywhere as test.php and run it with php -f /path/to/test.php.
You could also save it e.g. in the Sugar root dir to make it accessible to the web and just call it from your browser's address bar.

Related

Show api-blueprint documentation of my REST API doesn't work

I've the following situation: I built a REST API using zend (not apigility but single packages like zf-rest).
Now I want to document my API (the endpoints, request and response types etc.). For this purpose I created a folder "data" and a subfolder "api-blueprint" under my project directory. Here I stored some files with markdown. So I have:
/myproject/data/api-blueprint/index.md
/myproject/data/api-blueprint/hal-entry-point.md
...
My expectation is that I can open a browser and call
mydomain.com/api/rest/myproject
(this is the root) and see the content of hal-entry-point.md, so I get an overview about the supported endpoints. But I can't get it to work. Is there a special framework which I forgot to install or a configuration of zf-rest, zf-hal ...?

"Google MC Funnels API" for PHP (simple query) not working

I am trying to put this Google funnels API to work in my php server, just like Gapi, but I can't understand how to write the new queries.
The downloaded example is not working. I am not getting any data back!
I study the .php sample files in the "examples" folder contained in that API. However, they are very different from the original "Gapi".
So far there are no examples to work from. Every step to authorize my API to work seems to be OK, but I don't know how to verify this. How do I check that this API is OK on my php server? If it is, how does one create a simple query with this "MC funnels API"?

Triggering Azure WebJobs API over Basic Auth from external PHP app?

As per the title - I'm trying to trigger an Azure Website "triggered" WebJob from our custom PHP deployment application hosted external to Azure websites.
Thanks to what I believe is Active Directory, I'm able to navigate the /api URLs in my browser and get a JSON output without having to reauthenticate. For example, /api/triggeredwebjobs outputs the triggered WebJob information (that I've set up inside Azure Portal) in my browser.
I've gotten as far in my PHP app as sending a POST request and it is successfully authenticating using basic auth, but every single /api URL that I set in my PHP app returns:
"No route registered for '/api/triggeredwebjobs/{webjobname}'"
where {webjobname} is my custom name for the web job, hidden for privacy of the client. Every URL returns this, but if I navigate in my browser, I only get that error if I navigate to a URL that doesn't exist, such as /api/blahblahblah.
I've set up a deployment user which is what it's using to authenticate... I've even logged in to https://{azuresite}.scm.azurewebsites.net/basicauth using the deployment user and successfully gotten output from each /api page in my browser.
If it helps, I'm using Httpful.phar to handle the HTTP requests.
Thank you very much for taking the time to read and possibly assist.
A colleague helped me get to the bottom of this - the documentation was out of date. I have opened an issue on the Kudu Github Repo to get them to review this:
https://github.com/projectkudu/kudu/issues/1466
To solve the issue for future readers of this question, the correct URL to use within the requester app is:
https://{yoursite}.scm.azurewebsites.net/jobs/triggered/{jobname}/run
Good luck!

API request to same domain

Good day!
I have a PHP based web application, that I am looking to add a Wordpress to.
The main application is in the root folder, and wordpress is installed in /wp
In order to get WP content into my application, I am using a JSON API (http://wordpress.org/plugins/json-api/)
Then, from the application, I am calling the API with CURL.
Is this a good way to go about calling the API? CURL seems to be very slow, and I think it has something to do with sessions, and the fact that it is requesting a url on the same domain.
Or perhaps someone could offer a suggestion on a better way to go about getting wordpress content into a non-wordpress based application.
Thanks for the help!

PHP create a centralized dispatcher for REST like api

hi i am not sure if this is restful related, i think it is , but please do correct me if i am wrong.
so basically i want my server, which is written in PHP, to respond to different api requests, so for example
http://www.myweb.com/api/content/video/get?id=1 which will return a json object that has information regarding of a video of id=1
however, i can also have the following api to be called
http://www.myweb.com/api/content/music/get?name=biever
i want to create a centralized dispatcher, a php file that sits in the api directory in the server, so whenever a request is made where api appears in the RESTful link (which is in both example above), it shoudld 'intercept' these requests, and examine rest of the path to call the function accordingly. so for example
in controller.php in api directory
it will see, oh you are calling content/video, i will do some pre processing (say, adding video name or something) then direct the method call to content/video/get
how can i, in php, make sure that all the requests will go through my controller file first?
By default URLs are mapped to PHP files in your file system. You can't control this in PHP. By the time your PHP is run, you're too late. So you'll need to look into rewriting the URL at the webserver-level. If you're using Apache look into mod_rewrite.

Categories