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" &lf& "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

Reply via email to