PaulSamuelson Posted March 21, 2018 Posted March 21, 2018 I am having trouble with the UPS JSON API. I know it has been done here before, because I have seen questions about decoding the return. UPS doesn't like what I am sending. I am using JSONSetElement to create my JSON: JSONSetElement ( "{}"; ["UPSSecurity"; ""; JSONObject]; ["UPSSecurity.UsernameToken"; ""; JSONObject]; ["UPSSecurity.UsernameToken.Username"; "psamuelson"; JSONString]; ["UPSSecurity.UsernameToken.Password"; "xxxxxx"; JSONString]; ["UPSSecurity.ServiceAccessToken"; ""; JSONObject]; ["UPSSecurity.ServiceAccessToken.AccessLicenseNumber"; "ABCABC"; JSONString]; ["TrackRequest"; ""; JSONObject]; ["TrackRequest.Request"; ""; JSONObject]; ["TrackRequest.Request.RequestOption"; "1"; JSONString]; ["TrackRequest.Request.TransactionReference"; ""; JSONObject]; ["TrackRequest.Request.TransactionReference.CustomerContext"; "Your Test Case Summary Description"; JSONString]; ["TrackRequest.InquiryNumber"; "1Z5690980355503859"; JSONString] ) Which creates the following JSON, after a JSONFormatElements : { "TrackRequest" : { "InquiryNumber" : "1Z5690980355503859", "Request" : { "RequestOption" : "1", "TransactionReference" : { "CustomerContext" : "Your Test Case Summary Description" } } }, "UPSSecurity" : { "ServiceAccessToken" : { "AccessLicenseNumber" : "ABCABC" }, "UsernameToken" : { "Password" : "XXXXXX", "Username" : "psamuelson" } } } The UserName and Password are for my UPS account. The AccessLicenseNumber is my Access Key from UPS. The format of my XML appears to match the JSON example from their documentation, other than the order of objects (FileMaker seems to list them in alphabetical order), but I don't think that matters. The URL is "httpspost://wwwcie.ups.com/rest/Track?"& $$UPS_JSON_Formatted (where $$UPS_JSON_Formatted is my variable containing the JSON above). I am using cURL options "--header \"Content-type: application/json\" --data-urlencode" The response I get back from UPS is {"Error":{"Code":"4","Description":"JSON Syntax error"}}. I think the JSON is correct, so I wonder if I am missing something with cURL options or something else. Any ideas? Thanks, Paul
PaulSamuelson Posted March 21, 2018 Author Posted March 21, 2018 This is what the documentation shows:
villeglad Posted March 22, 2018 Posted March 22, 2018 (edited) I do not know about UPS api but try by setting data as --data option. Instead of "httpspost" format in url, use curl options with data set from variable. Below is example (did just wrote from memory, not sure if syntax is 100% correct) "--data @$$UPS_JSON_Formatted " & "-X POST " & "-H \"Content-type: application/json\"" Set url as "https://wwwcie.ups.com/rest/Track" Edited March 22, 2018 by jvagla 1
PaulSamuelson Posted March 22, 2018 Author Posted March 22, 2018 That did it. Thanks! Now, on to decoding the returned data... Thanks, Paul
bcooney Posted March 22, 2018 Posted March 22, 2018 Paul, Have you tried using Generator? It'll parse the JSON for you.
Newbies Bluetec Posted April 26, 2019 Newbies Posted April 26, 2019 On 3/22/2018 at 2:23 PM, PaulSamuelson said: That did it. Thanks! Now, on to decoding the returned data... Thanks, Paul Hi Paul, I still can't get this to work properly. Would you please post the working code of your "Track Request" Thanks Gary
Recommended Posts
This topic is 2106 days old. Please don't post here. Open a new topic instead.
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 accountSign in
Already have an account? Sign in here.
Sign In Now