-1

I am successfully doing this API request in Postman and it returns me well.

Postman results: https://prnt.sc/10tlrbr

But when I try to do Postman's auto-generated RestSharp code it's returning forbidden just like below.

Auto-generated RestSharp code results:

<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Access to this page has been denied.</title> <link href="https://fonts.googleapis.com/css?family=Open+Sans:300" rel="stylesheet"> <style> html, body { margin: 0; padding: 0; font-family: 'Open Sans', sans-serif; color: #000; } a { color: #c5c5c5; text-decoration: none; } .container { align-items: center; display: flex; flex: 1; justify-content: space-between; flex-direction: column; height: 100%; } .container > div { width: 100%; display: flex; justify-content: center; } .container > div > div { display: flex; width: 80%; } .customer-logo-wrapper { padding-top: 2rem; flex-grow: 0; background-color: #fff; visibility: hidden; } .customer-logo { border-bottom: 1px solid #000; } .customer-logo > img { padding-bottom: 1rem; max-height: 50px; max-width: 100%; } .page-title-wrapper { flex-grow: 2; } .page-title { flex-direction: column-reverse; } .content-wrapper { flex-grow: 5; } .content { flex-direction: column; } .page-footer-wrapper { align-items: center; flex-grow: 0.2; background-color: #000; color: #c5c5c5; font-size: 70%; } @media (min-width: 768px) { html, body { height: 100%; } } </style> <!-- Custom CSS -->  </head> <body> <section class="container"> <div class="customer-logo-wrapper"> <div class="customer-logo"> <img src="" alt="Logo"/> </div> </div> <div class="page-title-wrapper"> <div class="page-title"> <h1>Please verify you are a human</h1> </div> </div> <div class="content-wrapper"> <div class="content"> <div id="px-captcha"> </div> <p> Access to this page has been denied because we believe you are using automation tools to browse the website. </p> <p> This may happen as a result of the following: </p> <ul> <li> Javascript is disabled or blocked by an extension (ad blockers for example) </li> <li> Your browser does not support cookies </li> </ul> <p> Please make sure that Javascript and cookies are enabled on your browser and that you are not blocking them from loading. </p> <p> Reference ID: #93318f50-8bf1-11eb-85a7-c78da2bc2a80 </p> </div> </div> <div class="page-footer-wrapper"> <div class="page-footer"> <p> Powered by <a href="https://www.perimeterx.com/whywasiblocked">PerimeterX</a> , Inc. </p> </div> </div> </section> <!-- Px --> <script> window._pxAppId = 'PX0UqK4c76'; window._pxJsClientSrc = '/0UqK4c76/init.js'; window._pxFirstPartyEnabled = true; window._pxVid = ''; window._pxUuid = '93318f50-8bf1-11eb-85a7-c78da2bc2a80'; window._pxHostUrl = '/0UqK4c76/xhr'; </script> <script src="/0UqK4c76/captcha/captcha.js?a=c&u=93318f50-8bf1-11eb-85a7-c78da2bc2a80&v=&m=0"></script> <!-- Custom Script -->  </body> </html>

Auto-generated RestSharp code for C#:

var client = new RestClient("https://api.foursquare.com/v2/checkins/add?oauth_token=XXX&venueId=4c0c79aa2466a593b4337621&ll=36.86361515148467,30.64172744750977&v=20210322");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);

Auto-generated headers: https://prnt.sc/10tlnfo

You can try this code without an oauth_token or parameter like this:

var client = new RestClient("https://api.foursquare.com/v2/checkins/add");

I have tried the Postman auto-generated headers and change user-agent but nothing changed.

What am I missing or doing something wrong?

API docs: https://developer.foursquare.com/docs/api-reference/checkins/add/

  • Capture requests from your client app and compare with one you send via Postman. Following may help to setup Postman as proxy - https://stackoverflow.com/questions/41366909/how-do-i-capture-https-requests-with-postman-native-app-using-windows-10 if you dislike Fiddler for some reason. Then [edit] post to clarify what parts of request (like cookies,...) you need help with. – Alexei Levenkov Mar 23 '21 at 16:42

1 Answers1

0

You should look at the HTML:

Title: Pease verify you are a human.

Access to this page has been denied because we believe you are using automation tools to browse the website.

This may happen as a result of the following:

  • Javascript is disabled or blocked by an extension (ad blockers for example)
  • Your browser does not support cookies

Please make sure that Javascript and cookies are enabled on your browser and that you are not blocking them from loading.

Also you should not set the oauth token within the Parameters but via the Authenticate functionality of Postman. Then it will be also correctly in the generated code as well. Here you get more Info.

LedStarr
  • 49
  • 4
  • In Postman, I have disabled "Postman-Token" variable. And get this HTML page. I think problem is the "Postman-Token" is not in the request. – Can Uğurlu Mar 24 '21 at 10:25
  • Yes, that makes sense. Look into adding the oauth token to the Authenticate Tab in Postman, – LedStarr Mar 24 '21 at 12:52