How to you use Azure documentdb using php - azure-cosmosdb

Is any one know how to work with azure document db using php.
i want to create collection add the data in the document db using php.
please send any sample code for it.
http://azure.microsoft.com/en-in/services/documentdb/
Thanks
Thanigaivelan

DocumentDB currently does not have an official PHP client SDK available.
You can interact with DocumentDB using the REST API.
Alternatively, you could look for unofficial 3rd-party SDKs like this one (I'm not sure how well supported this project is - but the source code looks to be good reference for interacting with the REST API).

Documentdb offers a REST API, so what you need is a REST API client. You can write one on your own, or use one of the 3 available on github (search for php documentdb)
Basically you need to request the resource you need via POST and add the required headers using CURL.
The only tricky part is the authorization token you need to create based on various information.
Here is a code snippet for the token :
function gettoken($master_key,$vrb,$rtype,$rid,$da_date) {
$key = base64_decode($master_key);
$st_to_sign = $vrb . "\n" .
$rtype . "\n" .
$rid . "\n" .
$da_date . "\n" .
"\n";
$sig = base64_encode(hash_hmac('sha256', strtolower($st_to_sign), $key, true));
return $sig;
}
My repo on github is a good , simple way to start but not oop. (https://github.com/upggr/documentdb-for-php)
There are currently 2 more repos that provide the full API functionality via a class :
The one from cocteau666 as mentioned in the previous comment and one from crassaert (https://github.com/crassaert/php-azure-documentdb)
For some reason, there is not much interest yet on people implementing this with php, I hope this changes soon.

Related

After on-premise setup of mesibo . Do I need to change this url from client side mesibo-lib.js https://storage.mesibo.com/api/api.php

After on-premise setup of mesibo , Do I need to change anything from mesibo-lib.js end ?
I could see some url in mesibo-lib.js - a.Gc="https://storage.mesibo.com/api/api.php"
Please help to understand here from client side what changes needs to be done.
Im using angularjs client side code.
Cloud or On-premise, you should use your server to store your files. storage.mesibo.com is only provided for evaluation and files can be regularly cleaned up.
Refer to https://mesibo.com/documentation/tutorials/get-started/file-transfer/

Call a REST API from Kusto function

I have a logs endpoint rest url that I want to call and get the contents by calling a function. In a simplified way, create function like below.
create function getData(url:string)
{
let data = curl GET url;
print data
}
//Call it.
getData("<some rest url here>")
The documentation from Microsoft seems to talk about Kusto's own APIs not not how to call an external API. Am I missing something?
The documentation you reference relates to calling Kusto service REST APIs.
Kusto query language is a query language, not a open-ended programming platform.
Call-outs to external sources such as SQL Azure are possible, but subject to certain restrictions, primarily security-oriented by nature.
See external data operator, sql_request plugin, and callout policy articles.

How to programmatically create a database in ADX using Java

I am using REST API (https://learn.microsoft.com/en-us/azure/kusto/api/rest/request) to interact with the database in ADX.
I want to create more databases in the same cluster. How should I do it using Java?
I am not using the Java SDK. I have relied on the REST APIs so far.
I think I cannot create a new database using the REST API, so looking for alternative.
It would have been really helpful if there was a command like ".create table tablename" just for the database.
Clusters and databases can be managed using the "Control Plane", aka ARM APIs. These APIs have libraries in different languanges (as well as REST).
For instance, for the java library use this link, for C# use this link
Example for how to create a database in C# library (Java should be very similar):
var database = managementClient.Databases.CreateOrUpdate(resourceGroup, clusterName, databaseName, new Database(location, softDeletePeriod: softDeletePeriod, hotCachePeriod: hotCachePeriod));
Read more here
I think you'll need to use the Azure ARM REST API since the database is treated as a resource. From that point you can interact with it through the ADX APIs.

MarkLogic I don't know how to get all the result

Hello I am trying to read a module with this code:
(: Entry point - must be a read-only query. :)
xdmp:invoke(
'/path/mydocument.xqy',
(xs:QName('var1'), 'test',
xs:QName('var2'), "response"))
I am new in MarkLogic, I am using groovy and the api to connect to it, but also I saw I can invoke the module with this and indeed I did but it returns me
your query returned an empty sequence
I want to know if I can query xs:QName('var1'), 'test', changing test with a wildcard or how can I get all the information from the file called /path/mydocument.xqy?
I tried to use this:
xdmp:document-get("/path/mydocument.xqy)
but it says the file is not found. Although, if I use invoke I can query it, but I don't know what are the values I have to pass. I was wondering if there is something like sql using %% or something to give me all the data.
To answer the first question: "I am trying to read a module "
IF the module is in the database, then you must query the Modules database in which the module resides.
If the module is in the filesystem then you cannot directly access its source as a document but you can by executing xdmp:filesystem-file()
Simplification:
With the Default configuration of the server and REST client, user placed modules are in the "Modules" database and user placed documents are in the "Documents" database. This means, if you do a GET (read a "Document") with no additional parameters, it will return documents from the "Documents" database. Assuming you are using the default configuration for client and server, this would result in the behavior you are seeing. E.g. your Module code is in the Modules database, doing a GET for it by name will search the Documents database and correctly not find it.
You don't mention, and I don't know, the groovy library being used, but the REST API itself and all implementations of general purpose ML REST client libraries I am familiar with have options for overriding the default database with another. If the groovy library supports that, then specify the "Modules" database for your query and it should return the module document. Note: content-type will be application/text not text/xml.
You can simplify things for testing by bypassing the libraries and simply use a browser and try a URL like this http://yourserver.com:8000/v1/documents?uri=/your/module.xqy&database=Modules
Ref: https://docs.marklogic.com/REST/GET/v1/documents
Making the appropriate changes to the path and server for your use.
If you are still confused, then you should start with the basic MarkLogic tutorials and work through them one by one. You will most likely succeed faster by doing this then jumping straight into coding you don't understand yet.
DETAIL:
Note: The default behaviour is to EXECUTE documents when doing a GET call, using the Modules database. Thus doing a GET of http://yourserver:8000/your/module.xqy will EXECUTE it not return its source.
You will notice the REST API has a uri query parameter. This is EXECUTING the REST API code on /v1/documents which in turn will read the document specified by the uri and database parameters and return it.
I guess I can use:
xdmp:invoke(/pview/get-pview-browse-profiles.xqy,
cts:and-query((
cts:element-value-query(
xs:QName("letter"),"*", "wildcarded"),
cts:element-value-query(
xs:QName("collection"),"*", "wildcarded"))))
although it doesn't return anything

How to check if user has permission to edit content using the eZ Platform Public API in PHP?

eZ Platform is a Full Stack Symfony based Content Management System (CMS). It adds a content repository and other features that allow users to create content. This is controlled by a sophisticated permissions system that allows finegrained control.
Normally these permissions are exposed through the user interface so that users can either perform certain functions or not. But how do I achieve this in my custom code, in Controllers or Console Commands?
Developers use standard services to interact with the repository. There are plenty of good examples of this in the CookBookBundle. One thing that is not covered by the examples in the bundle is how to check if a user has permission to do a certain function.
You can do this easily by using the PermissionResolver from the repository, for example:
$content = $contentService->loadContent(52);
$canEdit = $permissionResolver->canUser('content','edit',$content);
if($canEdit){
echo "Logged in user can edit object " . $content->getName();
} else {
echo "Logged in user can't edit object " . $content->getName();
}
This naturally applies to any commands and functionalities in the repository. For example, the content module has functionalities such as create, edit and remove.

Resources