api.net-corestrava

How to return a string response from a .NET Core API endpoint that has a quotations in it?


In order to subscribe to Strava's webhook, I need to return a specifically formatted string when they call my endpoint.

The string needs to look like this:

{ “hub.challenge”:”123” }

however when I actually try to return this, in the response it appears like this:

"{ \"hub.challenge\":\"123\" }"

This is my actual endpoint being called:

       [HttpGet]
        public OkObjectResult Get([FromQuery(Name = "hub.mode")] string mode,
            [FromQuery(Name = "hub.challenge")] string challenge,
            [FromQuery(Name = "hub.verify_token")] string verifyToken)
        {
            return Ok("{ " + $"\"hub.challenge\":\"{challenge}\"" + " }");
        }

How can I return this string properly so it matches up with what Strava is looking for? Or is this simply not possible in C#.


Solution

  • Here's what I did:

    [HttpGet]
    public object Get([FromQuery(Name = "hub.mode")] string mode,
       [FromQuery(Name = "hub.challenge")] string challenge,
       [FromQuery(Name = "hub.verify_token")] string verifyToken)
    {
        Dictionary<string, string> result = new Dictionary<string, string>();
        result.Add("hub.challenge", challenge);
        return result;
    }