6

I am trying to pass a URL as a input parameter to a ApiController from an Angular REST call. The URL comes as a query string (this is a Provider Hosted app in SharePoint, I need the URL to query SP FWIW).

Here is the method signature in the ApiController:

// GET: api/ProjectSite/5
public IEnumerable<ProjectSite> Get(string id)
{
    return ProjectSite.GetAllProjectSites(id);
}

And here is where I am making the call in Angular:

var spUrl = "'" + getParameterByName("SPHostUrl") + "'";

var queryUrl = "/api/ProjectSite/" + encodeURIComponent(spUrl);
return $http.get(queryUrl);

This generates a GET request that looks like this:

https://localhost:12345/api/ProjectSite/https%3A%2F%2Fcompany.sharepoint.com%2Fsites%2Fsite_dev%2Fweb

When I do I get 'HTTP 400 (Bad Request)' back. If I stop on a break point in the Angular code and change the input param to a simple string (e.g. 'asdf') the REST call is made and I see the Api is called. If I do not change the string and put a breakpoint inside the Get Api method the breakpoint is not reached, indicating that the code is blowing up somewhere in the route engine.

What I don't get is, while its encoded, the string I am trying to pass in should still be treated as a string, right? I also tried changing the input to Uri but that doesn't appear to work (and Uri isn't listed as a supported input type, anyways).

Anyone know how to pass a URL as input parameter?

1 Answer 1

13

Have you tried calling it using a query string?

var queryUrl = "/api/ProjectSite?id=" + encodeURIComponent(spUrl);
Sign up to request clarification or add additional context in comments.

Comments

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.