Tobias
Posts: 0
Joined: Thu Oct 02, 2014 6:06 am

cURL set up in appery.io interface - Why does this simple cURL fail?

Hello awesome appery.io,

after going through countless threads and documentations I still couldn't figure out how to transfer this simple cURL to a service in appery.io:
$ curl
-X PUT
-H 'Content-Type: application/json'
-d '{"status":"completed"}'
https://URL.com/wc-api/orders/777
-u consumer_key:consumer_secret

The request does return data for the order ID but it does not change the order ID's status even though in theory it should.

I am new to this and any help is very much appreciated! Here are my settings, query, header and body. Please let me know where i go wrong:
Image

Image

Image

Image

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

cURL set up in appery.io interface - Why does this simple cURL fail?

Hello Tobias,

Authorization of type curl-u username:password
can be implemented using header of parameter Authorization. For more information, please look here https://getsatisfaction.com/apperyio/...

Tobias
Posts: 0
Joined: Thu Oct 02, 2014 6:06 am

cURL set up in appery.io interface - Why does this simple cURL fail?

Hi Evgene,

thank you for coming back to me.

I had a look at the thread but am confused. Encode it even though it's via https? How? What parameter name? Proxy?

Could you give me step by step instructions like:

  1. Enter user name here

  2. Enter password here

  3. combine the two like this and encode the string like that (if needed)

  4. take the encoded result and put it HERE with THAT parameter name

  5. use proxy (if needed)

    These things may seem basic to you but i tried to understand and tested all kinds of things (including proxy, etc.) for the whole day (more than shown in first post). Literally it was my only goal for the day and i came up short :-( So i hope you can save the day and let me know in the most simplest way so my grandma would understand how to do it.

    Thank you very much!
    Tobias

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

cURL set up in appery.io interface - Why does this simple cURL fail?

Hi Tobias,

It's easy to use basic autentification with appery.io

In accordance to RFC http://tools.ietf.org/html/rfc2617 when basic auth need request should have "Authorization" header.

So there is no "login" request. You can accept to any web page/resource with basic auth.

Please follow these steps to implement basic autentification to your web resource:

1 Open "App settings". Navigate to "External resources" and add following url: http://prntscr.com/3lodbi/direct

pre

http://crypto-js.googlecode.com/files/2.5.3-crypto-min.js

/pre

2 Create new JS asset. And fill it with following JS. http://prntscr.com/3loeg6/direct

pre

function getAuth() {
//You should replace "user:password" string with your values.
var bytes = Crypto.charenc.Binary.stringToBytes("user:password");
var base64 = Crypto.util.bytesToBase64(bytes);
return "Basic " + base64;
}

/pre

3 Create REST service. And call it "getInfoWithBasic".

4 Set "getInfoWithBasic" with following settings(see screen shot):

http://prntscr.com/3lofgx/direct

5 Navigate to "Request" tab and add "Authorization" parameter. Check "Header" option: http://prntscr.com/3log6e/direct

6 Add datasoruce with service "getInfoWithBasic" on the "data" tab of the page and call it "getInforWithBasicDataSource". http://prntscr.com/3lohdb/direct

7 Click "Edit Mapping". Open "Request tab" and click "Add JS" on "Authorization" field. http://prntscr.com/3lohqp/direct

8 JS Editor will appear. Populate it with following code: http://prntscr.com/3loi5k/direct

pre

return getAuth();

/pre

9 Open "EVENTS" bottom panel. And add "Complete" event handler to your datasource. And populate it with following code: http://prntscr.com/3lok18/direct

pre

//This is just a test code that's show you response from the server.

console.log("Response from server with basic auth = " + jqXHR.responseText);

alert("Response from server with basic auth = " + jqXHR.responseText);

/pre

10 Add button to the page. And set "Click" event handler with action - invoke service "getInforWithBasicDataSource". http://prntscr.com/3lokr4/direct

11 Run your app on this page in chrome browser. And open "net" tab of browser debuger.

12 Click on Button. And you will get the alert with server response. http://prntscr.com/3loljj/direct

13 Close alert and open request in "Net" tab of the debugger. http://prntscr.com/3lomhv/direct

That's all.

Regards.

Tobias
Posts: 0
Joined: Thu Oct 02, 2014 6:06 am

cURL set up in appery.io interface - Why does this simple cURL fail?

Hi Yurii,

thank you very much for the detailed explanation. I hope it will help others to successfully set cURLs up.

For me unfortunately it didn't work. The error message i got from the server said "consumer key is missing". Regarding this error the instructions to the api say: "Authentication: There are two aways to authenticate with the API....Over HTTPS: You may use HTTP Basic Auth by providing the API Consumer Key as the username and the API Consumer Secret as the password:
$ curl https://www.example.com/wc-api/v1/orders \
-u consumer_key:consumer_secret
Occasionally some servers may not properly parse the Authorization header (if you see a "Consumer key is missing" error when authenticating over SSL, you have a server issue)...."

I also tested the "getInfoWithBasic" service by entering the encoded value directly into the Authorization field "Basic encodedstring" - same result. I tried various times in all ways i could think off. I also verified that the encoded string in the chrome network report is the same that i got encoding the string via an online encoder.

Attached all the steps i took following your instructions including the test and error messages. I am happy to share more details, app, login, etc. with you via email.

Let me know if you find something i did wrong or how we can solve it.

Thank you
Tobias

Image

Image

Image

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

cURL set up in appery.io interface - Why does this simple cURL fail?

Hi Tobias,

Your implementations looks good.

We can try to test it.

So please give us your app public link(you can send it on a href="mailto:support@appery.io" rel="nofollow"support@appery.io/a if you can not share it here, and give there link on this thread) and describe steps to reproduce this problem.

Regards.

Tobias
Posts: 0
Joined: Thu Oct 02, 2014 6:06 am

cURL set up in appery.io interface - Why does this simple cURL fail?

Hi Yurii,

thank you for offering your help. I have just sent you an email with all the information and user credentials for the API. If you need anything else, let me know.

Looking forward to hearing from you.
Tobias

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

cURL set up in appery.io interface - Why does this simple cURL fail?

Hi Tobias,

I've checked your implementation and it's ok.

But i tested basic auth in URL mode in browser and get the same error.

So the culprit could be:
1 Wrong credentials.
2 HTTP handler does not support basic auth.
3 Missed some mandatory parameter.

Please try it with following way:

https://user:pass@domain.com/path/pat...

Where you need to replace user:pass with your credentials. And "domain.com/path/path1/path2/20" with your url.

Then put this url in browser. Then you will get response.

In case if you can not get correct response please contact this 3rd party api to get directions why you can not login with basic auth.

Regards.

Tobias
Posts: 0
Joined: Thu Oct 02, 2014 6:06 am

cURL set up in appery.io interface - Why does this simple cURL fail?

Thank you for your help. I'll contact the server and API guys and come back to you.

Johnny7459624
Posts: 0
Joined: Tue Mar 31, 2015 7:49 am

cURL set up in appery.io interface - Why does this simple cURL fail?

@tobias did you get any response from Woocommerce API?

Did you get it working. Also trying to implement it.

Return to “Issues”