2

I am using this code to get form's sumbitted data from formstack

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net; //webClient
using System.IO; // use for StreamReader

namespace Test_to_integrate_FormStack
{
    class Program
    {
        static void Main(string[] args)
        {

            var uri = string.Format("https://www.formstack.com/api/v2/submission/:313004779.json");
            try
            {
                using (var webClient = new WebClient())
                {
                    webClient.Headers.Add("Accept", "application/json");
                    webClient.Headers.Add("Authorization", "apikey" + "4D6A94162B2");

                    string Response = string.Empty;
                    Response = webClient.DownloadString(uri);
                }
            }
            catch (WebException we)

            {
                using (var sr = new StreamReader(we.Response.GetResponseStream()))
                {
                }
            }
        }
    }
}

It is giving me error:The remote server returned an error: (400) Bad Request.

Where should I wrong? Please do let me know.

Thank You

  • Double check the documentation you are using to make sure you are crafting the request correctly. As the error states, the request you are building and sending is not valid. Is your url correct, the headers and their values correct, are you missing anything? – Phil Cooper Mar 15 '17 at 11:02
  • Thank You Phil for the response. I am verifying as you told. Do you have any example on this? – Abdul Wahab Mar 15 '17 at 12:51

2 Answers2

0

I know its late in the game, but the authentication looks incorrect to me.

It should be "Bearer [API KEY]"

0

Your URL is incorrect.

You used: https://www.formstack.com/api/v2/submission/:313004779.json

but it should be: https://www.formstack.com/api/v2/submission/313004779.json

https://developers.formstack.com/reference#submission-id-get

The documentation shows /:id and that means it expects a variable.

https://www.formstack.com/api/v2/submission/id.json

Robert Saylor
  • 1,279
  • 9
  • 11