Jump to content

PUT to Restful API using PHP cURL


Inspector Mills

Recommended Posts

Hi there

I 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 appreciated

Thanks.

Link to comment
Share on other sites

  • 3 weeks later...

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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.