tripit / api

TripIt's API Documentation and Support Forum
http://www.tripit.com/developer
Other
47 stars 16 forks source link

401: Unauthorized #253

Open dondauphineeMaritimeTravel opened 4 years ago

dondauphineeMaritimeTravel commented 4 years ago

In the past few months, we have been having issues with using the API to transfer XML trip data to user's TripIt accounts. We are getting a 401: Unauthorized message. This has been in use for about 9 years and only recently have we been getting the 401: Unauthorized message.

I am able to successfully get the request token, user signs in, successfully goes back to our call back page, and then I do a call to get the Access Token, which is also successful.

Then, when I go to do a t.Create(XML) I get: System.Net.WebException: 'The remote server returned an error: (401) Unauthorized.'

However, I have a proper OAuth credential attached to the "t" object with the 4 keys that are needed: ConsumerKey, ConsumerSecret, Token, and Token Secret.

This is a sample call that I am doing:

t.Create("2020-08-232020-08-28true")

Again, this has been working for about 9 years now without issue, and no code changes have been made on our side. So wondering if there is a recent change on TripIt's end that I need to account for? Has anyone else run into this?

Also to note, I do force TLS 1.2 using ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; // Force TLS 1.2

And to reenforce that i seem to have no issues getting both the request, and access tokens using the t.GetAccessToken() and GetRequestToken methods of the API.

Here is my code. All the keys are successfully populated and obtained. The bottom line is where it fails:

    ServicePointManager.CertificatePolicy = new TrustAllCertificatesPolicy();

    strEntryId = Convert.ToInt32(Request.QueryString["id"]); //Get entry ID
    int tripItId = 0; // the TripIt id returned after a trip object is created

    TripIt.TravelObject.Response response;
    TripIt.TripIt t;

    ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; // Force TLS 1.2

    Credential credential = new OAuthCredential(
    ConfigurationManager.AppSettings["TRIPITAPIKEY"].ToString(), ConfigurationManager.AppSettings["TRIPITAPISECRET"].ToString(),
            HttpContext.Current.Session["RequestToken"].ToString(), HttpContext.Current.Session["RequestTokenSecret"].ToString());

    t = new TripIt.TripIt(credential, "https://api.tripit.com/oauth/access_token");

    OAuthCredential authorizedCredential = t.GetAccessToken();

    try
    {
        t = new TripIt.TripIt(authorizedCredential, "https://api.tripit.com/v1/create");

    }
    catch (Exception error)
    {
        Response.Write(error.ToString());
        return;
    }

    GalileoEntities context = new GalileoEntities();

    //Get the trip information basd on the EntryId
    try
    {
        GatherTripInformation(strEntryId, context);

    }
    catch
    {

    }

    //Create Trip object       
    //try
    //{
        response = t.Create(BuildTripXML());     <----- 401 here

Thanks, Don

nholmes3 commented 4 years ago

Hello Don,

Can you provide a rough timeframe for when these errors started occurring so that we can look through our logs and try to get some additional information regarding this problem?

dondauphineeMaritimeTravel commented 4 years ago

Hi,

It looks like it started happening around December 4th , 2019. We only noticed in April when someone reported it to us, and now we are just getting the resources to try to resolve the problem.

A few days prior to that we kept receiving a 503 Bad Gateway error which was confirmed by TripIt as an issue but then was fixed and was working, but starting in December of last year we seem to be getting the 401 error.

Thanks, Don

From: nholmes3 notifications@github.com Sent: Tuesday, August 18, 2020 6:03 PM To: tripit/api api@noreply.github.com Cc: Don Dauphinee ddauphinee@Maritimetravel.ca; Author author@noreply.github.com Subject: [EXTERNAL] Re: [tripit/api] 401: Unauthorized (#253)

Hello Don,

Can you provide a rough timeframe for when these errors started occurring so that we can look through our logs and try to get some additional information regarding this problem?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://urldefense.com/v3/__https:/github.com/tripit/api/issues/253*issuecomment-675719017__;Iw!!EGoMcmNbZ0q9Mn_6!aSdgifQYkUJ2_6zF3MDRiLtQCi6uYbDIR8RS8lJNTl81wsEfJjJ1eIHqBf4c6TtFt47_0vJ1$, or unsubscribehttps://urldefense.com/v3/__https:/github.com/notifications/unsubscribe-auth/AKDMVKKODJLA67IE64PZ6R3SBLUBNANCNFSM4QD7W73Q__;!!EGoMcmNbZ0q9Mn_6!aSdgifQYkUJ2_6zF3MDRiLtQCi6uYbDIR8RS8lJNTl81wsEfJjJ1eIHqBf4c6TtFt9533u3c$.


Please be cautious This email was sent from outside of the Maritime Travel organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

nholmes3 commented 4 years ago

Hey Don,

Unfortunately I am having trouble locating specific failures for your client(s). If you can provide me with some samples that include exact times and dates that would help a lot. Also, can you confirm that these errors are occurring for clients titled "Maritime Travel"

Thanks

dondauphineeMaritimeTravel commented 4 years ago

Hi,

The most recent one I have is from Tuesday

Tue 8/18/2020 4:02 PM Atlantic (5:02 PM Eastern Time). Got the 401: Unauthorized at that time. That was creating the trip and should be the same or similar XML passed through the web service as in my initial example. I would have been trying to send this trip information to my test TripIt account development@maritimetravel.camailto:development@maritimetravel.ca

The clients would all be different names, but for my tests they would have all been attempted under development@maritimetravel.camailto:development@maritimetravel.ca. The failure doesn’t happen when I try to obtain the request/access tokens (those are successful), it just happens when I try to send over the create request as shown in my sample.

Thanks, Don

From: nholmes3 notifications@github.com Sent: Wednesday, August 19, 2020 8:39 PM To: tripit/api api@noreply.github.com Cc: Don Dauphinee ddauphinee@Maritimetravel.ca; Author author@noreply.github.com Subject: [EXTERNAL] Re: [tripit/api] 401: Unauthorized (#253)

Hey Don,

Unfortunately I am having trouble locating specific failures for your client(s). If you can provide me with some samples that include exact times and dates that would help a lot. Also, can you confirm that these errors are occurring for clients titled "Maritime Travel"

Thanks

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://urldefense.com/v3/__https:/github.com/tripit/api/issues/253*issuecomment-676812443__;Iw!!EGoMcmNbZ0q9Mn_6!ZyOvgf1ypH5ELxvAVVvILJeKVshuL39fQq-Q7HJsDXdhuEb9yFiL2Y_F3epTNy_MMcO7lNEW$, or unsubscribehttps://urldefense.com/v3/__https:/github.com/notifications/unsubscribe-auth/AKDMVKKDEJAFAHT3UFZT4DTSBRPALANCNFSM4QD7W73Q__;!!EGoMcmNbZ0q9Mn_6!ZyOvgf1ypH5ELxvAVVvILJeKVshuL39fQq-Q7HJsDXdhuEb9yFiL2Y_F3epTNy_MMbMY_6V6$.


Please be cautious This email was sent from outside of the Maritime Travel organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

nholmes3 commented 4 years ago

Can you send me the full response including all http headers from the error?

dondauphineeMaritimeTravel commented 4 years ago

That is great, thank you very much!

Don

From: nholmes3 notifications@github.com Sent: Thursday, August 20, 2020 3:56 PM To: tripit/api api@noreply.github.com Cc: Don Dauphinee ddauphinee@Maritimetravel.ca; Author author@noreply.github.com Subject: [EXTERNAL] Re: [tripit/api] 401: Unauthorized (#253)

Thanks for the info. I was able to find errors corresponding to your failure in our logs and am working to diagnose and fix the exact issue

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://urldefense.com/v3/__https:/github.com/tripit/api/issues/253*issuecomment-677839298__;Iw!!EGoMcmNbZ0q9Mn_6!ZmrTlboq4f5qWECjUL7zzmK2gExy7KuaFBfueSIcSViiSc8yCKBi4O9fG-RGQX8r2oYHGocr$, or unsubscribehttps://urldefense.com/v3/__https:/github.com/notifications/unsubscribe-auth/AKDMVKNSYRMLJHX7YFSDDWDSBVWSXANCNFSM4QD7W73Q__;!!EGoMcmNbZ0q9Mn_6!ZmrTlboq4f5qWECjUL7zzmK2gExy7KuaFBfueSIcSViiSc8yCKBi4O9fG-RGQX8r2ruEw0GT$.

nholmes3 commented 4 years ago

Hello Don,

Were you able to grab the full error response including all http headers to send over?

dondauphineeMaritimeTravel commented 4 years ago

Hi,

This is everything I am able to capture from the exception:

} System.Net.WebHeaderCollection

} System.Net.WebHeaderCollection m_IsCacheFresh false bool m_IsFromCache false bool m_IsMutuallyAuthenticated false bool m_IsVersionHttp11 true bool m_IsWebSocketResponse false bool m_MediaType null string m_StatusCode Unauthorized System.Net.HttpStatusCode m_StatusDescription "Unauthorized" string

} System.Net.WebHeaderCollection

From: nholmes3 notifications@github.com Sent: Monday, August 24, 2020 5:18 PM To: tripit/api api@noreply.github.com Cc: Don Dauphinee ddauphinee@Maritimetravel.ca; Author author@noreply.github.com Subject: [EXTERNAL] Re: [tripit/api] 401: Unauthorized (#253)

Hello Don,

Were you able to grab the full error response including all http headers to send over?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://urldefense.com/v3/__https:/github.com/tripit/api/issues/253*issuecomment-679343852__;Iw!!EGoMcmNbZ0q9Mn_6!b04lG7-9L1l8fbomEHwRuTyrouV4aBAA5Orj6_YvjHfcryw4MY3eCy4oJ0U3PyFPUkS1GJvH$, or unsubscribehttps://urldefense.com/v3/__https:/github.com/notifications/unsubscribe-auth/AKDMVKJZSE4G6O35I3Z5HQ3SCLDH7ANCNFSM4QD7W73Q__;!!EGoMcmNbZ0q9Mn_6!b04lG7-9L1l8fbomEHwRuTyrouV4aBAA5Orj6_YvjHfcryw4MY3eCy4oJ0U3PyFPUmVE8Dlg$.


Please be cautious This email was sent from outside of the Maritime Travel organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

nholmes3 commented 4 years ago

based on the above output it looks like your request is attempting to hit the /v1/create/v1/create endpoint which does not exist.

AbsolutePath    "/v1/create/v1/create" string
AbsoluteUri        "https://api.tripit.com/v1/create/v1/create"  

you should double check your code to make sure you are requesting the correct /v1/create endpoint

dondauphineeMaritimeTravel commented 4 years ago

Hi,

I looks like I am not duplicating the path as you show below. I am using the C# TripIt.dll from your website, and calling it like this. Perhaps I am missing a step when using this dll? As a reminder, I’m able to get all the tokens without issue prior to this code being hit:

Credential credential = new OAuthCredential( ConfigurationManager.AppSettings["TRIPITAPIKEY"].ToString(), ConfigurationManager.AppSettings["TRIPITAPISECRET"].ToString(), HttpContext.Current.Session["RequestToken"].ToString(), HttpContext.Current.Session["RequestTokenSecret"].ToString()); t = new TripIt.TripIt(credential, "https://api.tripit.com/oauth/access_token"); OAuthCredential authorizedCredential = t.GetAccessToken();

    try
    {
        t = new TripIt.TripIt(authorizedCredential, "https://api.tripit.com/v1/create");

    }
    catch (Exception error)
    {
        Response.Write(error.ToString());
        return;
    }
    GalileoEntities context = new GalileoEntities();
    //Get the trip information basd on the EntryId
    try
    {
        GatherTripInformation(strEntryId, context);

    }
    catch
    {
    }
    //Create Trip object
    //try
    //{
        response = t.Create(BuildTripXML());  <---- Code fails here, just sending in the XML from my original example.

From: nholmes3 notifications@github.com Sent: Monday, August 31, 2020 3:36 PM To: tripit/api api@noreply.github.com Cc: Don Dauphinee ddauphinee@Maritimetravel.ca; Author author@noreply.github.com Subject: [EXTERNAL] Re: [tripit/api] 401: Unauthorized (#253)

based on the above output it looks like your request is attempting to hit the /v1/create/v1/create endpoint which does not exist.

AbsolutePath "/v1/create/v1/create" string

AbsoluteUri "https://api.tripit.com/v1/create/v1/createhttps://urldefense.com/v3/__https:/api.tripit.com/v1/create/v1/create__;!!EGoMcmNbZ0q9Mn_6!ZrCxNmTfTuwNa6jQZXknRLnPcSdTWMHbPEAZb0P8RmjnZMzO3KMQJgjxNKgAFvFT0JT1hqSv$"

you should double check your code to make sure you are requesting the correct /v1/create endpoint

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://urldefense.com/v3/__https:/github.com/tripit/api/issues/253*issuecomment-683955008__;Iw!!EGoMcmNbZ0q9Mn_6!ZrCxNmTfTuwNa6jQZXknRLnPcSdTWMHbPEAZb0P8RmjnZMzO3KMQJgjxNKgAFvFT0Nx6V_XV$, or unsubscribehttps://urldefense.com/v3/__https:/github.com/notifications/unsubscribe-auth/AKDMVKL7HIQBTTGNEXRVVRLSDPUQBANCNFSM4QD7W73Q__;!!EGoMcmNbZ0q9Mn_6!ZrCxNmTfTuwNa6jQZXknRLnPcSdTWMHbPEAZb0P8RmjnZMzO3KMQJgjxNKgAFvFT0MdToVol$.


Please be cautious This email was sent from outside of the Maritime Travel organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

lundbrianh commented 4 years ago

Hi Don, This line looks curious to me t = new TripIt.TripIt(authorizedCredential, "https://api.tripit.com/v1/create");. That url should be the "top level" api url, and the functions like Create() would build the appropriate url to call from that base.

I had to look back at the binding, but I think you either want to omit the second parameter there, or use https://api.tripit.com: https://github.com/tripit/csharp_binding_v1/blob/master/TripIt.cs#L47

Hope that helps, Brian

dondauphineeMaritimeTravel commented 4 years ago

Hi there,

Even in making that change I still get an error (same unauthorized error) when I call t.Create

t.Create("2020-08-312020-09-04true");

Within the t object, I have a proper t.Credential with values for ConsumerKey, ConsumerSecret, Token, and Token Secret

Not sure if there’s anything else at the account level preventing me from creating trips?

Thanks, Don

From: lundbrianh notifications@github.com Sent: Tuesday, September 1, 2020 4:06 AM To: tripit/api api@noreply.github.com Cc: Don Dauphinee ddauphinee@Maritimetravel.ca; Author author@noreply.github.com Subject: [EXTERNAL] Re: [tripit/api] 401: Unauthorized (#253)

Hi Don, This line looks curious to me t = new TripIt.TripIt(authorizedCredential, "https://api.tripit.com/v1/createhttps://urldefense.com/v3/__https:/api.tripit.com/v1/create__;!!EGoMcmNbZ0q9Mn_6!aLRIx729i4IfP71xQZPMbPfsoBaIJc0pWuTSFIG5qE9x9dImJana7pMwe3L_uCttOgmu4dy2$");. That url should be the "top level" api url, and the functions like Create() would build the appropriate url to call from that base.

I had to look back at the binding, but I think you either want to omit the second parameter there, or use https://api.tripit.comhttps://urldefense.com/v3/__https:/api.tripit.com__;!!EGoMcmNbZ0q9Mn_6!aLRIx729i4IfP71xQZPMbPfsoBaIJc0pWuTSFIG5qE9x9dImJana7pMwe3L_uCttOnPTN5Vw$: https://github.com/tripit/csharp_binding_v1/blob/master/TripIt.cs#L47https://urldefense.com/v3/__https:/github.com/tripit/csharp_binding_v1/blob/master/TripIt.cs*L47__;Iw!!EGoMcmNbZ0q9Mn_6!aLRIx729i4IfP71xQZPMbPfsoBaIJc0pWuTSFIG5qE9x9dImJana7pMwe3L_uCttOvIETkbD$

Hope that helps, Brian

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://urldefense.com/v3/__https:/github.com/tripit/api/issues/253*issuecomment-684501837__;Iw!!EGoMcmNbZ0q9Mn_6!aLRIx729i4IfP71xQZPMbPfsoBaIJc0pWuTSFIG5qE9x9dImJana7pMwe3L_uCttOqRjyGWH$, or unsubscribehttps://urldefense.com/v3/__https:/github.com/notifications/unsubscribe-auth/AKDMVKIMMHQF7K6VNGDQ6ADSDSMNHANCNFSM4QD7W73Q__;!!EGoMcmNbZ0q9Mn_6!aLRIx729i4IfP71xQZPMbPfsoBaIJc0pWuTSFIG5qE9x9dImJana7pMwe3L_uCttOiUJMLTC$.


Please be cautious This email was sent from outside of the Maritime Travel organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

dondauphineeMaritimeTravel commented 4 years ago

Hi there,

Just wondering if there’s anything else that you could see that could be causing this problem to happen.

Thanks, Don

From: Don Dauphinee Sent: Tuesday, September 1, 2020 4:41 PM To: tripit/api reply@reply.github.com; tripit/api api@noreply.github.com Cc: Author author@noreply.github.com Subject: RE: [EXTERNAL] Re: [tripit/api] 401: Unauthorized (#253)

Hi there,

Even in making that change I still get an error (same unauthorized error) when I call t.Create

t.Create("2020-08-312020-09-04true");

Within the t object, I have a proper t.Credential with values for ConsumerKey, ConsumerSecret, Token, and Token Secret

Not sure if there’s anything else at the account level preventing me from creating trips?

Thanks, Don

From: lundbrianh notifications@github.com<mailto:notifications@github.com> Sent: Tuesday, September 1, 2020 4:06 AM To: tripit/api api@noreply.github.com<mailto:api@noreply.github.com> Cc: Don Dauphinee ddauphinee@Maritimetravel.ca<mailto:ddauphinee@Maritimetravel.ca>; Author author@noreply.github.com<mailto:author@noreply.github.com> Subject: [EXTERNAL] Re: [tripit/api] 401: Unauthorized (#253)

Hi Don, This line looks curious to me t = new TripIt.TripIt(authorizedCredential, "https://api.tripit.com/v1/createhttps://urldefense.com/v3/__https:/api.tripit.com/v1/create__;!!EGoMcmNbZ0q9Mn_6!aLRIx729i4IfP71xQZPMbPfsoBaIJc0pWuTSFIG5qE9x9dImJana7pMwe3L_uCttOgmu4dy2$");. That url should be the "top level" api url, and the functions like Create() would build the appropriate url to call from that base.

I had to look back at the binding, but I think you either want to omit the second parameter there, or use https://api.tripit.comhttps://urldefense.com/v3/__https:/api.tripit.com__;!!EGoMcmNbZ0q9Mn_6!aLRIx729i4IfP71xQZPMbPfsoBaIJc0pWuTSFIG5qE9x9dImJana7pMwe3L_uCttOnPTN5Vw$: https://github.com/tripit/csharp_binding_v1/blob/master/TripIt.cs#L47https://urldefense.com/v3/__https:/github.com/tripit/csharp_binding_v1/blob/master/TripIt.cs*L47__;Iw!!EGoMcmNbZ0q9Mn_6!aLRIx729i4IfP71xQZPMbPfsoBaIJc0pWuTSFIG5qE9x9dImJana7pMwe3L_uCttOvIETkbD$

Hope that helps, Brian

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://urldefense.com/v3/__https:/github.com/tripit/api/issues/253*issuecomment-684501837__;Iw!!EGoMcmNbZ0q9Mn_6!aLRIx729i4IfP71xQZPMbPfsoBaIJc0pWuTSFIG5qE9x9dImJana7pMwe3L_uCttOqRjyGWH$, or unsubscribehttps://urldefense.com/v3/__https:/github.com/notifications/unsubscribe-auth/AKDMVKIMMHQF7K6VNGDQ6ADSDSMNHANCNFSM4QD7W73Q__;!!EGoMcmNbZ0q9Mn_6!aLRIx729i4IfP71xQZPMbPfsoBaIJc0pWuTSFIG5qE9x9dImJana7pMwe3L_uCttOiUJMLTC$.


Please be cautious This email was sent from outside of the Maritime Travel organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

nholmes3 commented 4 years ago

Hey Don. It would help us to have some additional logging information from the requests that you are sending on your end as we are unable to reproduce the issue.

Can you please log the content length and data string after this line in the binding and report back?

Something along the lines of: Console.WriteLine($"content-length: {request.ContentLength}"); Console.WriteLine("'" + Encoding.UTF8.GetString(data) + "'");