Jump to content

Curl Syntax


Recommended Posts

Jesus! - for the love of God just give me C and an assembler!

 

I'm fighting here! ; simple to someone that knows curl - I'm on windows aswell so I'm even more annoyed than usual!

 

Here's what I'm trying to achieve ....

 

curl -H 'Content-Type: application/json' -X PUT -d '{"configured": true}' http://IP:PORT/api/APIKEY/sensors/ID/config

 

ip:port my HA, APIKEY I got.

 

It's which brackets of which type with which quotes where - that I can't get right. Googling is just adding fuel to the flames.

 

One of you will be some modern sado web page type deal with this mess person ( and much appreciated I will be! )

Link to comment
Share on other sites

What error are you getting?

 

I think windows isn't a fan of the single quotes on the json - try escaping the inner ones

 

curl -XPUT -H "Content-type: application/json" -d "{\"configured\": true}" http://IP:PORt/api/APIKEY/sensors/ID/config

 

 

Link to comment
Share on other sites

22 minutes ago, elite said:

What error are you getting?

 

I think windows isn't a fan of the single quotes on the json - try escaping the inner ones

 

curl -XPUT -H "Content-type: application/json" -d "{\"configured\": true}" http://IP:PORt/api/APIKEY/sensors/ID/config

 

 

Mucking windows! > tried as you suggested get rescue/sensors/2, not available, "type 3" error now

Link to comment
Share on other sites

5 minutes ago, Sparrowhawk said:

Since you're on Windows, can you install Windows Subsystem for Linux (WSL)? It makes tasks like this much easier (I have run out of patience with curl on Windows).

 

Alternatively use Postman (it's free) and run the command there instead of at the command line.

I thought ( after googling ) I had chrome postman add on.  But can't see how I do a CURL in it ; just post/get etc.

Link to comment
Share on other sites

2 minutes ago, pocster said:

I thought ( after googling ) I had chrome postman add on.  But can't see how I do a CURL in it ; just post/get etc.

https://www.tutorialspoint.com/how-to-create-a-put-request-in-postman

 

You're replicating the cURL command inside Postman. It's a different syntax but does allow you to save these commands in a playbook to rerun in future.

Edited by Sparrowhawk
Link to comment
Share on other sites

3 minutes ago, pocster said:

Mucking windows! > tried as you suggested get rescue/sensors/2, not available, "type 3" error now

Add quotes around the URL?

 

curl -XPUT -H "Content-type: application/json" -d "{\"configured\": true}" "http://IP:PORt/api/APIKEY/sensors/ID/config"
Link to comment
Share on other sites

2 minutes ago, pocster said:

Tried that

Works for me - things I'd check

 

  1. Weird characters in api key - should've been fixed with quotes
  2. Is the URL / path you're hitting 100% correct?
  3. Try with verbose flag (-v)
Link to comment
Share on other sites

7 minutes ago, elite said:

What service are you connecting to?

Do you know . I can’t answer that . I’m following some German advice that I need to connect to a local physical advice to change configured from false to true . It’s insane how convoluted this is - and I’ve still not achieved it .

I do appreciate all the help though !

 

BIT_SET(*(device,).configuration,TRUE);  ( apologies if syntax a little rusty ! )

Link to comment
Share on other sites

Are you getting a http status code back -v flag in curl - postman in chrome will prob give you this too? - this might give a clue as to an error (prob 5** range) or not found 4** - Is it definatley device ID 2? This should begiving you a 200 if all is good

 

Happy to cast a second pair of eyes over the german advice if you want to PM

 

Link to comment
Share on other sites

An extra space believe it or not - which you couldn't 'see' as the curl line was split.

 

Things like this shouldn't exist in 2023. Like on a webpage where you must enter the date and then it complains you need to put spaces in ( no; your code should do that ). Seems to be a common thing with postcode enteries.

Don't get it. Validate the input pad/remove spaces etc. - basic stuff ffs!

 

Anyway! - did my curl and something else is a miss now ( I was told the device id was 2 ; but I reckon it's 6 ) - either way inching forward...

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...