Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.
This repository was archived by the owner on Apr 18, 2025. It is now read-only.

Code 500 When Creating Request #2

@sebasijan

Description

@sebasijan

Trying to execute this request, but getting null response data with response code 500:

var insightlyService = new InsightlyService();
var response = insightlyService
    .With<Contact>(true)
    .GetAll();
var contacts = response.ResponseData();

I managed to narrow it down to the creation of the FlurlClient in InsightlyService.Authorise, where the return object is not being cast to FlurlClient.

Original

public FlurlClient Authorise(string path)
{
	var request = InsightlyUri + path;
	return request.WithBasicAuth(ApiKey, "");
}

Error in VS

Cannot implicitly convert type 'Flurl.Http.IFlurlClient' to 'Flurl.Http.FlurlClient'. An explicit conversion exists (are you missing a cast?)

First Change

So I updated the code to look like this:

public IFlurlClient Authorise(string path)
{
    var request = InsightlyUri + path;
    var o = request.WithBasicAuth(ApiKey, "");
    return o;
}

But now I am seeing an error on this line:

responseData = await response.ReceiveJson<T>().ConfigureAwait(false);

Exception

{"Request to https://api.insight.ly/v2.2/Contacts/ failed. JSON integer 100224663348 is too large or small for an Int32. Path '[0].CONTACTINFOS[0].CONTACT_INFO_ID', line 1, position 411."}

Second Change

I noticed that the encoded API Key in the header looks different to when I manually make this call from PowerShell (Maybe a problem with the base64 encoding?) So I tried adding it manually here like so:

public FlurlClient Authorise(string path)
{
    var request = InsightlyUri + path;
    var flurlClient = new FlurlClient(request);
    flurlClient.WithHeader("Authorization", "Basic EncodedAPIKeyasperPowershellbase64Encoding");
    return flurlClient;
}

But this resulted in the same error as above (request integer is too large), so it looks like the issue is happening in Flurlclient?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions