1

Below is the code sample

public string getIssueList(string email)
{
    dynamic JsonContent = "";
    string url = baseAddress + "resource/Issue/?fields=[%22subject%22,%22status%22]&filters=[[%22Issue%22,%22raised_by%22,%22=%22,%22" + email + "%22]]";

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
               | SecurityProtocolType.Tls11
               | SecurityProtocolType.Tls12
               | SecurityProtocolType.Ssl3;

    HttpClientHandler handler = new HttpClientHandler();
    HttpClient client = new HttpClient(handler);
    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("token", AccessToken);

    var APIResponse = client.GetAsync(url).Result;

    if (APIResponse.IsSuccessStatusCode)
    {
        JsonContent = APIResponse.Content.ReadAsStringAsync().Result;
        WriteToFile(" getIssueList APIResponse : " + JsonContent.ToString());
    }


    return JsonContent;
}

the link in above code is making some problem I think when I am sending get request in response it is getting StatusCode: 403, ReasonPhrase: 'FORBIDDEN', Version: 1.1.....

I think it is not accepting the %22 => " in raw string " is also it is not working

Chillar Anand
  • 27,936
  • 9
  • 119
  • 136
Aakash
  • 11
  • 1
  • It is more likely your token isn't correct because that is what the 403 normally means. Try without any fields or just `?fields=` and see if you still get a 403. Are you sure `new AuthenticationHeaderValue("token", AccessToken);` is corent? Is AccessToken a JWT? If yes, shouldn't `"token"` then be `"Bearer"` instead? – rene Jul 02 '22 at 13:20
  • I tried without any parameter then it's working fine but when adding parameters it's not getting 200 ok response and data from server. I want to pass " in url, it's containing JSON data in url. – Aakash Jul 02 '22 at 13:32
  • So you can't add the `"`? Did you try escaping the " with a \ like `"resource/Issue/?fields=[\"subject\"` ... etc .... – rene Jul 02 '22 at 13:45
  • Yes I tried, but not working getting same response.and also resource/Issue/?fields= is getting replaced with resource/Issue?fields= automatically, is there any to way stop this replacement. – Aakash Jul 02 '22 at 14:14
  • If you replace your string url line with just `string url = baseAddress + "resource/Issue/?fields=[\"subject\"]";` does that work? – rene Jul 02 '22 at 14:23
  • Not working same response, can we pass double quotes " in url, i think because of double quotes" it's showing that error – Aakash Jul 02 '22 at 14:25
  • In my quick testing the URL seems to be encoded correctly: https://i.stack.imgur.com/sSHkI.png and the approach is inline with what ERPNext seems to expect https://frappeframework.com/docs/v13/user/en/guides/integration/rest_api/listing_documents so I'm out of ideas right now. – rene Jul 02 '22 at 14:59
  • Ok boss, 'Met dank' Thanks for help – Aakash Jul 02 '22 at 15:32
  • There are a number of side issues with the above code: setting `SecurityProtocol` is a bad idea, let .NET work out for itself what is the best protocol. `handler` `client` and `APIResponse` need disposing with `using`, although it's generally recommended to cache a single `client` with its `handler` for the lifetime of the app. Don't call `.Result` it could cause a deadlock, instead do `async` all the way. – Charlieface Jul 03 '22 at 02:18
  • hii,can you suggest me code for it, beacause i tried with 'using' also but still not getting expected result. – Aakash Jul 03 '22 at 07:32

0 Answers0