Re: Tearing my bloody hair out.


Brian Christmas
 

G’day All

A very big thank you to everyone who replied.

Turned out that Jim Skibbie was spot on, (once I put the correct passcode in), possibly only because I tried his suggestion first, the other answers may have worked as well.

set jsonURL to do shell script "curl --verbose -A UserAgentString -u 2V57JR9HQNAZNZVOW6OZXG:my-password https://api.fastspring.com/subscriptions?limit=10000"
-- RETURNS {"action":"subscription.getall","result":"success","page":1,"limit":10000,"nextPage":null,"total":1,"subscriptions":["f-DfdENtRvuhBtKJUIA8QQ"]}

Why I did not need a -G perplexes me, FastSpring insists on a GET. And -A UserAgentString was something I had overlooked when reading the MAN pages for CURL.

You’re two great bunches of people!!!



HOWEVER, the code that Nigel had supplied me with earlier (below), fails to convert the “subscriptions’ key to an applescript list.

Here it is with errors. I’ve played around with it, but really don’t follow it.

Obviously URLWithString:(jsonURL must be incorrect, cause Nigel expected me to supply a URL, but what do replace it with, please?

I tried guessing (Yes Shane, I know, don’t bloody GUESS!),  set subscriptionsList to (current application's jsonURL's objectsForKey:(("subscriptions") as list)) —< jsonURL doesn’t understand the “objectForKey_” message.


How do I  get the list of subscriptions from jsonURL, please?

Again thank you, and regards

Santa

use AppleScript version "2.4"
use framework "Foundation"
use framework "AppKit"
use scripting additions


try
if (count of jsonURL) > 0 then
set p to 3
set jsonURL to current application's class "NSURL"'s URLWithString:(jsonURL)
set p to 4
set jsonData to current application's class "NSData"'s dataWithContentsOfURL:(jsonURL)
set p to 5
set {jsonObject, theError} to current application's class "NSJSONSerialization"'s JSONObjectWithData:(jsonData) options:(0) |error|:(reference) --< returns "data parameter is nil"
set p to 6
if (jsonObject is missing value) then error (theError's localizedDescription() as text)
set p to 7
set subscriptionsList to (jsonObject's objectForKey:("subscriptions")) as list
end if
on error errmsg
display dialog "Json conversion " & errmsg & " p = " & p --< gives "Json conversion The data couldn’t be read because it isn’t in the correct format. p = 6"
end try



On 16 Sep 2017, at 6:51 am, Jim Skibbie <JSkibbie@...> wrote:

I would suggest opening up Terminal and trying this from the command line
using curl’s --verbose flag until you can verify your request is working
correctly.

curl --verbose -A UserAgentString -u
2V57JR9HQNAZNZVOW6OZXG:F7l-9f3SR2We7q9L6mzds
https://api.fastspring.com/subscriptions?page=1&limit=1


When I do this, I get the below result. Note that the response is “401
Unauthorized”. I’m assuming you didn’t publish your real username and
password above.

Once you get it working, you can just wrap the command inside the do shell
script command.

*   Trying 54.88.60.171...
* Connected to api.fastspring.com (54.88.60.171) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
* Server certificate: *.fastspring.com
* Server certificate: Amazon
* Server certificate: Amazon Root CA 1
* Server certificate: Starfield Services Root Certificate Authority - G2
* Server auth using Basic with user '2V57JR9HQNAZNZVOW6OZXG'
GET /subscriptions?page=1 HTTP/1.1
Host: api.fastspring.com
Authorization: Basic
MlY1N0pSOUhRTkFaTlpWT1c2T1pYRzpGN2wtOWYzU1IyV2U3cTlMNm16ZHM=
User-Agent: UserAgentString
Accept: */*

< HTTP/1.1 401 Unauthorized
< Date: Fri, 15 Sep 2017 20:45:42 GMT
< Server: nginx
< Content-Length: 0
< Connection: keep-alive




Date: Fri, 15 Sep 2017 15:51:58 +1000
From: Brian Christmas <ozsanta@...>
To: Applescript Xcode new list <applescript@apple-dev.groups.io>,
Applescript Users <applescript-users@...>
Subject: Re: Tearing my bloody hair out.
Message-ID: <4CA9A161-3D16-4C87-99B7-7CD8F743B38B@...>
Content-Type: text/plain; charset="utf-8"




G’day again scripters

I’ve been trying to study Curl for days, and now how to use Curl in a ‘do
shell script’.

I can’t for the life of me see why this won’t work? BUT, I’m really a
novice at using CURL, completely new to me.

Fast Springs site says I have to use GET. This handler returns “"

Santa

set jsonURL to do shell script "curl    -H  -u
'2V57JR9HQNAZNZVOW6OZXG:F7l-9f3SR2We7q9L6mzds'   -G
\"https://api.fastspring.com/subscriptions?limit=10000\”"


_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (applescript-users@...)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/applescript-users/ozsanta%40gmail.com
Archives: http://lists.apple.com/archives/applescript-users

This email sent to ozsanta@...

Join applescript@apple-dev.groups.io to automatically receive all group messages.