Web Service with Php

Posted by Community Admin on 04-Aug-2018 20:21

Web Service with Php

All Replies

Posted by Community Admin on 06-May-2015 00:00

I am looking for help with linking the sitefinity pre-built web services to a website. The website is local,
and run in php code. Below are some notes I've taken, in order to post a thread in order for someone to
possibly help me.

Specs, or whatever. What I want to be done:
I want to use the user.svc web service.
I want to crud users.
I want to use the userprofiletypesservice.svc web service.
I want to get profile types based on user id or whatever.
I want this to happen in php.

What I've tried:
I went here (among other places).
www.sitefinity.com/.../getting_started_with_restful_services_in_sitefinity

This told me to use this url to get authentication:
localhost:60876/.../
I run this in a browser, nothing happens.

I do this code in php:
<?php
$test = curl_init("localhost:60876/.../authenticate");
$fp = fopen("test.txt", "w");

curl_setopt($test, CURLOPT_FILE, $fp);
curl_setopt($test, CURLOPT_HEADER, 0);

I get this response:
"IIS 8.0 Detailed Error - 401.0 - Unauthorized"
as well as other stuff.

Conclusion questions:

What am I doing wrong? 
How do I get the cookie with authentication stuff into some php variable?
Do I need to use visual studio to do this, and then link up to a web service that I build myself, that
will do all the validation, and I can then just link the php into that web service? That is too
redundant...

So, there is my synopsis. If anyone has some clarity to throw at me, i'd appreciate it.

 Edit:

I also went here: github.com/.../RESTfulSitefinityClient

I downloaded this, opened the .sln with VS2013, built it, and ran it. It runs at first, but the program doesn't really work. I tried claims authentication, with url: localhost:60876/.../

I typed in my username and pass.

I hit login. Login goes unclickable, I can click list data or logout. If I hit list data, i get an error message saying stuff, but I can click continue, and the program still runs. If I hit logout, the program does nothing. If I hit create new product, things happen. BUT, this is the beginning of response data: 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "www.w3.org/.../xhtml1-strict.dtd"> 
<html xmlns="www.w3.org/.../xhtml"> 
<head> 
<title>IIS 8.0 Detailed Error - 401.0 - Unauthorized</title> 
<style type="text/css"> 

 There's that Unauthorized again!!!!

What is wrong?

Posted by Community Admin on 07-May-2015 00:00

Hello Chris,

You might want to check out this post for a fully-working sample for authenticating through RESTful web services. Hopefully this will help with your task!

Regards,
Grisha 'Greg' Karanikolov
Telerik

 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

Posted by Community Admin on 07-May-2015 00:00

Chris,

I've done a bit of work with the services. Here is a PHP version of the authentication mechanism. Also, I've done quite a bit of tinkering with the services themselves. Here's a C# example of working with them. (The relevant code would just need ported to PHP.)

Hopefully the answers to your questions are in there. :)

Posted by Community Admin on 14-May-2015 00:00

Hi all, 

 I've done a bit of digging, and I still haven't wrapped my head around this yet. I went to this page: <www.sitefinity.com/.../claims-based-login-for-resftul-api and took a look at the RESTfulClient project. TBH, I still don't understand it, and perhaps that is my downfall.

Anyways, I also went to this page: <www.sitefinity.com/.../4-1-sp2---401-on-users-svc-web-service-call>. Tim describes his problem with connecting to the sitefinity web services, using java. This is sort of where I am at.

I have a sitefininty website project that is opened in Visual Studio 2013. I hit start without debugging, and the website opens in my browser. I see the page, and I can login with username/password. 

Then, I have this php website. It uses curl to call the users.svc/authenticate web service. I pass in an array of strings, which give the credentials. $provider = array("MembershipProvider" => "","Password" => "password","Persistent" => true,"UserName" => "username);.

I call curl_exec, to run the call to the web service, and I put the output into a local text file.

When I look at this text file, it has a 401 error.

Now, am I doing this wrong? All I'm doing is calling the web service. Do I need to be doing this from within my sitefinity project, and then passing the token out to the php site? The php site is NOT within the sitefinity project folder. Am I having permission issues? 

 The only two possibilities that I can think of is that my syntax is wrong with passing the parameters to the web service, or that I'm going about this the wrong way, and as a developer, I'm not actually supposed to be calling the web service directly from a sitefinity site. This confuses me, because on the following page, it says that the web services are "exposed and available for 3rd party applications and devices." <docs.sitefinity.com/for-developers-web-services>

 

PS - I started this thread under a different account. This is my actual name...

This thread is closed