1

I'm trying to get a JSON string via CURL:

curl https://{subdomain}.zendesk.com/api/v2/ticket_fields/{id}.json \
-v -u {email_address}:{password}

I can't get my head around how to convert this into a C# command, but I have been trying to use the WebClient and WebRequst class, but without any luck.

First i tried to access the URL via the WebClient:

var tags = api.Tickets.GetTicketFieldById(123456789);
WebClient client = new WebClient();
client.Credentials = new NetworkCredential("[email protected]", "abc123", "https://domain.zendesk.com/api/v2");
string json = client.DownloadString(tags.TicketField.Url);

But it throws an exception of 401 un-authorized.

I tried the same approach with the WebRequest/WebResponse, but same error came. I saw Zendesk was providing a CURL string to access the data, but I'm not sure on how to convert the CURL string into a C# command.

Can anybody help me access the returning JSON string?

Thanks in advance, Jesper.

0

1 Answer 1

1
string json;
using(var client = new WebClient())
{
    client.Credentials = new NetworkCredential("{email_address}", "{password}");
    json = client.DownloadString(
        "https://{subdomain}.zendesk.com/api/v2/ticket_fields/{id}.json");
}
// use json...

Obviously you'll need to replace the values. I'm assuming that isn't the problem.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, I'm replacing the values. But I guess i got the NetworkCredentials wrong, by entering the wrong uri. Thanks :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.