Inspector Mills Posted April 17, 2014 Share Posted April 17, 2014 Hi thereI need to use cURL to change the status of an order on a Restful API using PHP. The instructions I received from the developers of the API is as follows:curl -X PUT \-d"order[status]=S"[site url]In addition to this, they informed me that it is necessary to be signed in, with the credentials supplied.So, my problems are these:1. what is the syntax for the PUT action in PHP cURL?2. how do I sign in to the site with PHP?Any guidance will be appreciatedThanks. Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted April 17, 2014 Share Posted April 17, 2014 1: RTFM! We're not gonna read it to you. 2: There is no magical “sign in” parameter. The API provider has to tell you how they expect you to send the credentials. Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted April 17, 2014 Share Posted April 17, 2014 what is the syntax for the PUT action in PHP cURL? PUT method? I've not heard of it more than 13 years ago when Java was on top of the world. Is it a Java application? Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted April 17, 2014 Share Posted April 17, 2014 Looks like you've indeed missed the last 13 years. Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted April 17, 2014 Share Posted April 17, 2014 The programming is just my hobby Jacques Quote Link to comment Share on other sites More sharing options...
Inspector Mills Posted May 6, 2014 Author Share Posted May 6, 2014 HiThanks for the feedback. It turned out that the authentication was what was getting me stuck.This is what eventually worked:<?php$order = “[API order no]";$data = http_build_query(array("order[status]" => "S"));$email = “";$password = “[password]";$url = "[API URL]/$order";$ch=curl_init();curl_setopt($ch,CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC ) ;curl_setopt($ch, CURLOPT_USERPWD, "$email:$password");curl_setopt($ch, CURLOPT_SSLVERSION,3);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");curl_setopt($ch, CURLOPT_POSTFIELDS, $data);curl_exec($ch);curl_close($ch);?>RegardsMills Quote Link to comment Share on other sites More sharing options...
gizmola Posted May 6, 2014 Share Posted May 6, 2014 Since it was brought up here, in general REST advocates the following concept: GET -- for Getting information about something. POST -- for creating a new item PUT -- for modifying an existing item DELETE -- for removing an item. Since these items are orders, it seems like they follow the REST conventions although it's unclear what the restful endpoint that identifies the order would be just from your example. It looks like you have something like: foo.com/order# Where I'd expect something like: foo.com/order/order# If you use chrome, I've found this plugin provides a nice alternative to testing things with command line curl: https://chrome.google.com/webstore/detail/postman-rest-client/fdmmgilgnpjigdojojpjoooidkmcomcm?hl=en Quote Link to comment Share on other sites More sharing options...
QuickOldCar Posted May 7, 2014 Share Posted May 7, 2014 That postman looks useful. Easier to read about it here. http://www.getpostman.com/ Quote Link to comment Share on other sites More sharing options...
gizmola Posted May 7, 2014 Share Posted May 7, 2014 That postman looks useful. Easier to read about it here. http://www.getpostman.com/ Yeah it has a macro capability which is really nice when you are testing against multiple server environments. You can setup your routes to use variables, and reference endpoints or header variables that way. And of course the main advantage is you can save the routes into groups. Here's one example I have: {{host}}{{port}}{{con}}/member/account Then you create an environment and go in and setup those variables, so for example you might have my-local-api env: host localhost port :4066 con /app_dev.php authkey c342oiu4o2u3.... etc And wherever there are parameters or header variables you need to set you can use the environment variables, so in the routes or in a header variable like our-api-token {{token}} Really a nice tool! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.