Re: RESTful PUT error

2017-12-29 Thread Andrew Bell via use-livecode
Thanks for the feedback on proper headers! I looked again at the  
PipeDrive API  
[https://developers.pipedrive.com/docs/api/v1/#!/Persons/put_persons_id] in  
more detail and noticed that the Phone I was trying to change was  
actually looking for an array rather than a number or string so I  
thought I would try making a smaller change first. Name is a string so  
it should be easier to get a proof of concept with (or so I thought).


This is the sample test I'm doing in LiveCode (9dp11):
   Put random(999) into tID
   Put  
"https://api.pipedrive.com/v1/persons/3?api_token=ce95ed7f11e167194b0b4a6f6f1032df4fa13792; into  
tRequestURL
   Put "Content-Type: application/json" & "Accept:  
application/json" into tHeaders

   Put "Homer Simpson" into tArray["name"]
   Put ArrayToJSON(tArray) into tJSONtoUpload
   put tsNetPost(tID, tRequestURL, tHeaders, tJSONtoUpload,  
"updateWasCompleted") into tResult


But I end up getting this returned:
{"status":false,"error":"Unknown method ."}

So I tried sending the command as FORM data:
   put "Homer Simpson" into tName
   put "Accept: application/json" into tHeaders
   set the httpHeaders to tHeaders
   put  
"https://api.pipedrive.com/v1/persons/3?api_token=ce95ed7f11e167194b0b4a6f6f1032df4fa13792; into  
tRequestURL

   get libURLFormData("name", tName)
   put it into url tRequestURL

But I didn't get a response from the server via "it" or "the result"  
so I had to manually verify the data. What I discovered was that the  
Name was successfully updated! So my issue seems to be my header  
announcing to the server what format I am sending data in. A response  
from the server would be nice, but I can always do some error checking  
to verify myself. I didn't see a tsNet command for PUT, but I could be  
mistaken.


The API doc says an "update" must be done as PUT but a "create new" be  
done as POST. After lots of trial & error it seems that I am able to  
POST JSON, but can't PUT JSON. And I'm able to PUT FORM data, but  
can't POST FORM data. Still not sure why one format doesn't work both  
places, but happy that I cracked this and will be able to upsell a  
client on an integration to my existing product with them!


--Andrew Bell


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: RESTful PUT error

2017-12-15 Thread Sean Cole (Pi) via use-livecode
Actually, your json needs to also include the name as a requirement,
looking at the post format for 'Persons'. So it would be something like:

Put "{ 'name': 'John Smith' " & lf & " 'phone': '555-555-' }" into tJSON

replace "'" with quote in tJSON
Put "https://api.pipedrive.com/v1/persons/1?api_token=; & tToken into tURL

Set the httpheaders to "Content-Type: application/json" & "Accept:
application/json"
Post tJSON to tURL


'Put' you would use if you were only sending a query which can be added
after the main url. But because you have other data to send you need to use
'Post' so you can transmit other data to the queried uri.

I hope this helps.

Sean Cole
*Pi Digital Productions Ltd*


On 16 December 2017 at 01:27, Sean Cole (Pi)  wrote:

> Hi Andrew,
>
> I've been doing a whole heap of this just recently so have gained more
> experience in this than I would have hoped for :(  In other words, I had
> hoped it would have been easier. especially working with oAuth procedures
> which ended up as a rolling nightmare for me these last few weeks. Here's
> what I notice first off. And not wanting to jump to any conclusions, I have
> checked the PipeDrive site too. (I'm working on a library for the new Adobe
> Sign API using oAuth which I am converting from the previous SOAP method we
> used to use)
>
> Their API, under Request Format states:
>
>  In order to do a proper JSON-formatted request, make sure you provide 
> Content-Type:
>> application/json as part of your HTTP request.
>
> So your header would require this also. Ordinarily, it would be
> recommended to put your access token in your header too for security
> reasons (even if it IS via https). But, they require you add it as a query
> in your uri. So you should now have something like:
>
> Put "{'phone':'555-555-'}" into tJSON
>
> replace "'" with quote in tJSON
>
> Put "https://api.pipedrive.com/v1/persons/1?api_token=; & tToken into tURL
>
> Set the httpheaders to "Content-Type: application/json" & "Accept:
> application/json"
>
> Post tJSON to tURL
>
>
> So, really it's only this Content-Type that's holding you back as
> otherwise it is wondering what you are sending it and you have to be
> explicit.
>
> That's it really. The only characters that tend to cause me trouble are
> misplaced quotes, hashes, pound sign (£), slashes and new lines. But these
> you either provide ascii alternatives or backslash escape them. But you
> have used everything appropriately. It just doesn't recognise you've sent
> it any JSON formatted content.
>
> All the best.
>
> Sean Cole
> *Pi Digital Productions Ltd*
>
>
> On 15 December 2017 at 17:19, Andrew Bell via use-livecode <
> use-livecode@lists.runrev.com> wrote:
>
>> I tried suggestions from several users (on and off the list), but nothing
>> has worked for me. After contacting Pipedrive tech support, I got the
>> typical IT response of "it works for us" as they blamed LiveCode. They
>> suggested that somehow using regex would fix the issue, but I'm not sure
>> how that would even apply here (their API is telling me the characters are
>> disallowed, not LC). Using tsNet calls gave me the same errors as libURL
>> from LC (8.2dp2 and 9.0dp10).
>>
>> httpHeaders: {"Accept":"application/json"}
>> JSON being POSTed (not PUT as their API requests):
>> {"phone":"555-555-"}
>> URL being POSTed to (includes my API key for a test account):
>> https://api.pipedrive.com/v1/persons/1?api_token=ce95ed7f11e
>> 167194b0b4a6f6f1032df4fa13792
>>
>> Reply from their support team:
>> I checked with our engineers regarding the "Disallowed Key Characters"
>> message, and they believe this is related to your code editor of choice.
>> Some additional programming may be necessary to include these "disallowed"
>> characters. They also tested updating the phone value themselves via API,
>> and were successful.
>>
>> For more reference on this issue, they also recommend the following
>> resources:
>> https://stackoverflow.com/questions/4197976/codeigniter-disa
>> llowed-key-characters
>> http://www.darwinbiler.com/disallowed-key-characters-in-codeigniter/
>>
>>
>> --Andrew Bell
>>
>>
>> ___
>> use-livecode mailing list
>> use-livecode@lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
>
>
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: RESTful PUT error

2017-12-15 Thread Sean Cole (Pi) via use-livecode
Hi Andrew,

I've been doing a whole heap of this just recently so have gained more
experience in this than I would have hoped for :(  In other words, I had
hoped it would have been easier. especially working with oAuth procedures
which ended up as a rolling nightmare for me these last few weeks. Here's
what I notice first off. And not wanting to jump to any conclusions, I have
checked the PipeDrive site too. (I'm working on a library for the new Adobe
Sign API using oAuth which I am converting from the previous SOAP method we
used to use)

Their API, under Request Format states:

 In order to do a proper JSON-formatted request, make sure you provide
Content-Type:
> application/json as part of your HTTP request.

So your header would require this also. Ordinarily, it would be recommended
to put your access token in your header too for security reasons (even if
it IS via https). But, they require you add it as a query in your uri. So
you should now have something like:

Put "{'phone':'555-555-'}" into tJSON

replace "'" with quote in tJSON

Put "https://api.pipedrive.com/v1/persons/1?api_token=; & tToken into tURL

Set the httpheaders to "Content-Type: application/json" & "Accept:
application/json"

Post tJSON to tURL


So, really it's only this Content-Type that's holding you back as otherwise
it is wondering what you are sending it and you have to be explicit.

That's it really. The only characters that tend to cause me trouble are
misplaced quotes, hashes, pound sign (£), slashes and new lines. But these
you either provide ascii alternatives or backslash escape them. But you
have used everything appropriately. It just doesn't recognise you've sent
it any JSON formatted content.

All the best.

Sean Cole
*Pi Digital Productions Ltd*


On 15 December 2017 at 17:19, Andrew Bell via use-livecode <
use-livecode@lists.runrev.com> wrote:

> I tried suggestions from several users (on and off the list), but nothing
> has worked for me. After contacting Pipedrive tech support, I got the
> typical IT response of "it works for us" as they blamed LiveCode. They
> suggested that somehow using regex would fix the issue, but I'm not sure
> how that would even apply here (their API is telling me the characters are
> disallowed, not LC). Using tsNet calls gave me the same errors as libURL
> from LC (8.2dp2 and 9.0dp10).
>
> httpHeaders: {"Accept":"application/json"}
> JSON being POSTed (not PUT as their API requests): {"phone":"555-555-"}
> URL being POSTed to (includes my API key for a test account):
> https://api.pipedrive.com/v1/persons/1?api_token=ce95ed7f11e
> 167194b0b4a6f6f1032df4fa13792
>
> Reply from their support team:
> I checked with our engineers regarding the "Disallowed Key Characters"
> message, and they believe this is related to your code editor of choice.
> Some additional programming may be necessary to include these "disallowed"
> characters. They also tested updating the phone value themselves via API,
> and were successful.
>
> For more reference on this issue, they also recommend the following
> resources:
> https://stackoverflow.com/questions/4197976/codeigniter-disa
> llowed-key-characters
> http://www.darwinbiler.com/disallowed-key-characters-in-codeigniter/
>
>
> --Andrew Bell
>
>
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: RESTful PUT error

2017-12-15 Thread Alex Tweedly via use-livecode



On 15/12/2017 17:19, Andrew Bell via use-livecode wrote:
They also tested updating the phone value themselves via API, and were 
successful.
I'd ask them for the sample code they used to do this update, and see if 
that gives us a clue.


-- Alex.

___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: RESTful PUT error

2017-12-15 Thread Andrew Bell via use-livecode
I tried suggestions from several users (on and off the list), but  
nothing has worked for me. After contacting Pipedrive tech support, I  
got the typical IT response of "it works for us" as they blamed  
LiveCode. They suggested that somehow using regex would fix the issue,  
but I'm not sure how that would even apply here (their API is telling  
me the characters are disallowed, not LC). Using tsNet calls gave me  
the same errors as libURL from LC (8.2dp2 and 9.0dp10).


httpHeaders: {"Accept":"application/json"}
JSON being POSTed (not PUT as their API requests): {"phone":"555-555-"}
URL being POSTed to (includes my API key for a test account):  
https://api.pipedrive.com/v1/persons/1?api_token=ce95ed7f11e167194b0b4a6f6f1032df4fa13792


Reply from their support team:
I checked with our engineers regarding the "Disallowed Key Characters"  
message, and they believe this is related to your code editor of  
choice. Some additional programming may be necessary to include these  
"disallowed" characters. They also tested updating the phone value  
themselves via API, and were successful.


For more reference on this issue, they also recommend the following resources:
https://stackoverflow.com/questions/4197976/codeigniter-disallowed-key-characters
http://www.darwinbiler.com/disallowed-key-characters-in-codeigniter/


--Andrew Bell


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: RESTful PUT error

2017-11-27 Thread Alex Tweedly via use-livecode

"programming pattern"

I (sometimes) do something like this - so that each and every line of 
additional output looks and feels the same, e.g.


put "something" & CR after tVariable
put "something else" & CR after tVariable
etc.

i.e. every line finishes with   "  & CR after tVariable " so that can be 
pasted in (or, more likely, applied as a keyboard macro or Block-edit or 
 whatever your favourite editor convenience is).


And if you're doing that, then for robustness you should start with "put 
empty into tVariable" so that you are not vulnerable to any subsequent 
code changes that use the same variable name earlier.



Don't know if that's the same as Todd's answer or not :-)

-- Alex.


On 27/11/2017 23:20, Bob Sneidar via use-livecode wrote:

Why do you set the httpHeaders to empty just before you set them to something?

Bob S




On Nov 27, 2017, at 04:27 , Todd Fabacher via use-livecode 
 wrote:

*--Build the REST API Header*

*set* the httpHeaders to empty

*put* "Accept: application/json" & CR after tHeaders

*put* "Content-Type: application/x-www-form-urlencoded"  & CR after tHeaders

*set* the httpHeaders to tHeaders



___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode



___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: RESTful PUT error

2017-11-27 Thread Bob Sneidar via use-livecode
Why do you set the httpHeaders to empty just before you set them to something? 

Bob S



> On Nov 27, 2017, at 04:27 , Todd Fabacher via use-livecode 
>  wrote:
> 
> *--Build the REST API Header*
> 
> *set* the httpHeaders to empty
> 
> *put* "Accept: application/json" & CR after tHeaders
> 
> *put* "Content-Type: application/x-www-form-urlencoded"  & CR after tHeaders
> 
> *set* the httpHeaders to tHeaders
> 


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: RESTful PUT error

2017-11-27 Thread Todd Fabacher via use-livecode
What are you setting your headers to??  Are you sending JSON or posting a
form??

This is to send a form and get back JSON. You may also want XML or TEXT

FYI, most RestAPI use POST.


*--Build the REST API Header*

*set* the httpHeaders to empty

*put* "Accept: application/json" & CR after tHeaders

*put* "Content-Type: application/x-www-form-urlencoded"  & CR after tHeaders

*set* the httpHeaders to tHeaders


People forget to set this in LiveCode, It makes a big difference.


--Todd
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: RESTful PUT error

2017-11-26 Thread Pi Digital via use-livecode
I’ve been working on a library connecting LiveCode with MS Dynamics365 CRM via 
some APIs custom made for us in c#. LiveCode makes its calls to the API by 
REST. At first I was using Put url to send some simple calls but started 
getting errors in some. I was advised to switch over to using Post instead of 
Put (which acts more like Get anyway). So I’d just use Post empty to url when 
no parameters were needed. Errors all gone. 

So my advice to you is use only Get and Post. 

tRequestURL1 = 
https://api.pipedrive.com/v1/persons?api_token=ef2c59a67144d185277fee92aa9ede877c6c10ff

tRequestURL2 = 
https://api.pipedrive.com/v1/persons/2?api_token=ef2c59a67144d185277fee92aa9ede877c6c10ff

tJSONtoUpload = {"phone":"555-555-"}

Post empty to url(tRequestURL1)
Put it into tResponse1

Post tJSONtoUpload to url(tRequestURL2)
Put it into tResponse2

Sean Cole
Pi Digital

> On 26 Nov 2017, at 16:07, Roger Eller via use-livecode 
>  wrote:
> 
> If I remember correctly, PUT was never implemented in LibUrl.  I have only
> needed GET and POST in my rather limited uses.
> 
> ~Roger
> 
> 
> On Nov 26, 2017 10:37 AM, "Andrew Bell via use-livecode" <
> use-livecode@lists.runrev.com> wrote:
> 
> I'm working on connecting to a 3rd-party API (Pipedrive) to a LiveCode app
> I've done and seem to have a problem; any assistance would be appreciated.
> Dummy (sandbox) account information has been included with my code sample.
> 
> I've never used RESTful before, but the API seems pretty well documented
> and I've had success much faster than anticipated working with the data in
> LiveCode. It looks like commands are broke down into 3 types: GET (to
> retrieve data), POST (to create new data), and PUT (to update existing
> data).
> 
> I can retrieve data using "put URL tRequestURL1 into tJSONfromPipedrive"
> I can create new data using "post tJSONtoUpload to url tRequestURL2"
> But when I try to update data using "put tJSONtoUpload into url
> tRequestURL2" I get a 400 error from the server. I tried to
> urlEncode(tJSONtoUpload) but got the same error.
> 
> Their API includes a sandbox for testing, and my code seems to align with
> their examples and helped me get my tests in order. I'm just not sure
> what's wrong with my PUT command. https://developers.pipedrive.c
> om/docs/api/v1/#!/Persons/put_persons_id
> 
> VARIABLE VALUES:
> httpHeaders = {"Accept":"application/json"}
> tRequestURL1 = https://api.pipedrive.com/v1/persons?api_token=ef2c59a67144d
> 185277fee92aa9ede877c6c10ff
> tRequestURL2 = https://api.pipedrive.com/v1/persons/2?api_token=ef2c59a6714
> 4d185277fee92aa9ede877c6c10ff
> tJSONtoUpload = {"phone":"555-555-"}
> 
> Is there something glaring I'm missing? I can get this to execute on their
> developer website, but using the same code seems to error out for me in
> LiveCode 8.2.0dp2 Business.
> 
> --Andrew Bell
> 
> 
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription 
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Re: RESTful PUT error

2017-11-26 Thread Roger Eller via use-livecode
If I remember correctly, PUT was never implemented in LibUrl.  I have only
needed GET and POST in my rather limited uses.

~Roger


On Nov 26, 2017 10:37 AM, "Andrew Bell via use-livecode" <
use-livecode@lists.runrev.com> wrote:

I'm working on connecting to a 3rd-party API (Pipedrive) to a LiveCode app
I've done and seem to have a problem; any assistance would be appreciated.
Dummy (sandbox) account information has been included with my code sample.

I've never used RESTful before, but the API seems pretty well documented
and I've had success much faster than anticipated working with the data in
LiveCode. It looks like commands are broke down into 3 types: GET (to
retrieve data), POST (to create new data), and PUT (to update existing
data).

I can retrieve data using "put URL tRequestURL1 into tJSONfromPipedrive"
I can create new data using "post tJSONtoUpload to url tRequestURL2"
But when I try to update data using "put tJSONtoUpload into url
tRequestURL2" I get a 400 error from the server. I tried to
urlEncode(tJSONtoUpload) but got the same error.

Their API includes a sandbox for testing, and my code seems to align with
their examples and helped me get my tests in order. I'm just not sure
what's wrong with my PUT command. https://developers.pipedrive.c
om/docs/api/v1/#!/Persons/put_persons_id

VARIABLE VALUES:
httpHeaders = {"Accept":"application/json"}
tRequestURL1 = https://api.pipedrive.com/v1/persons?api_token=ef2c59a67144d
185277fee92aa9ede877c6c10ff
tRequestURL2 = https://api.pipedrive.com/v1/persons/2?api_token=ef2c59a6714
4d185277fee92aa9ede877c6c10ff
tJSONtoUpload = {"phone":"555-555-"}

Is there something glaring I'm missing? I can get this to execute on their
developer website, but using the same code seems to error out for me in
LiveCode 8.2.0dp2 Business.

--Andrew Bell


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your
subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


RESTful PUT error

2017-11-26 Thread Andrew Bell via use-livecode
I'm working on connecting to a 3rd-party API (Pipedrive) to a LiveCode  
app I've done and seem to have a problem; any assistance would be  
appreciated. Dummy (sandbox) account information has been included  
with my code sample.


I've never used RESTful before, but the API seems pretty well  
documented and I've had success much faster than anticipated working  
with the data in LiveCode. It looks like commands are broke down into  
3 types: GET (to retrieve data), POST (to create new data), and PUT  
(to update existing data).


I can retrieve data using "put URL tRequestURL1 into tJSONfromPipedrive"
I can create new data using "post tJSONtoUpload to url tRequestURL2"
But when I try to update data using "put tJSONtoUpload into url  
tRequestURL2" I get a 400 error from the server. I tried to  
urlEncode(tJSONtoUpload) but got the same error.


Their API includes a sandbox for testing, and my code seems to align  
with their examples and helped me get my tests in order. I'm just not  
sure what's wrong with my PUT command.  
https://developers.pipedrive.com/docs/api/v1/#!/Persons/put_persons_id


VARIABLE VALUES:
httpHeaders = {"Accept":"application/json"}
tRequestURL1 =  
https://api.pipedrive.com/v1/persons?api_token=ef2c59a67144d185277fee92aa9ede877c6c10ff
tRequestURL2 =  
https://api.pipedrive.com/v1/persons/2?api_token=ef2c59a67144d185277fee92aa9ede877c6c10ff

tJSONtoUpload = {"phone":"555-555-"}

Is there something glaring I'm missing? I can get this to execute on  
their developer website, but using the same code seems to error out  
for me in LiveCode 8.2.0dp2 Business.


--Andrew Bell


___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode