Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use PATCH verb with curl

Tags:

curl

patch

I am trying to make a PATCH call to a server. I am using the following command:

curl --data status=closed -X PATCH https://api.viafoura.com/v2/dev.viafoura.com/pages/7000000043515  

Is this the correct way of sending the PATCH request? I am getting an error saying there is no status parameter set. I am guessing the --data is for POST request only and thus the server doesn't find the status parameter.

This is the response (FYI):

{"http_status":400,"error":"Parameter validation errors","validation_errors":{"status":{"error":"Request missing status parameter."}}} 

You can find documentation about this service here.

like image 394
sheidaei Avatar asked Apr 30 '13 18:04

sheidaei


People also ask

How do I send a patch request?

To send a PATCH request to the server, you need to use the HTTP PATCH method and include the request data in the body of the HTTP message. The Content-Type request header must indicate the data type in the body. In this PATCH request example, we send JSON to the ReqBin echo endpoint to update the data on the server.

What is Flag in Curl?

What is a flag in Curl? A flag is a command-line parameter that denotes a specific action in Curl. Curl has over three hundred command-line options, and the number of options increases over time. You can add the listed flags to the Curl command and enter the URL.

Do get with Curl?

To make a GET request using Curl, run the curl command followed by the target URL. Curl automatically selects the HTTP GET request method unless you use the -X, --request, or -d command-line option.


1 Answers

This is the format you should use:

curl --request PATCH https://api.viafoura.com/v2/dev.viafoura.com/pages/7000000043515?status=closed 

That API seems to want the status parameter as a query parameter on the url, not part of the PATCH body.

At this point the server is going to return a 401 error: "You must be logged in to modify page settings." Assumedly you have to login first with something like this:

curl --request POST "https://api.viafoura.com/v2/dev.viafoura.com/users/login?password=TeNn!sNum8er1&[email protected]" 

I've used the credentials from their documentation in that example, which I figured would work on their dev server, but its currently returning an "Incorrect password" error.

If you have valid credentials, though, you should get back a session cookie which you can then use to authenticate your PATCH request.

like image 194
James Holderness Avatar answered Oct 11 '22 11:10

James Holderness