Jump to content

UPS API with JSON


This topic is 1200 days old. Please don't post here. Open a new topic instead.

Recommended Posts

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

 

 

Link to comment
Share on other sites

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 by jvagla
  • Like 1
Link to comment
Share on other sites

  • 1 year later...
  • Newbies
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

 

Link to comment
Share on other sites

This topic is 1200 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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.