REST API using POST for getting data

Hi Guys

I am struggling with setting up a connection to an API which uses the POST method for getting data and not the GET. Looks like Appgyver is set up differently than what this API expects.

There are three things to send in the body, 2 static values and 1 from a variable out of the app.

Thanks for the insights. If you have an idea, try to explain it to me in easy words since I am not a programmer.

Andreas

Hey @Andreas_Niedermann
Please, tell me which API you are using.

Thanks.

Hi @Fernando_Oliveira

Thanks for your answer. We are running an api by ourselves in combination with our iOS and Android app. Check out the screenshot. That’s working when using an API test program on my Mac.

I am trying to create a simple Appgyver app for support purposes.

Thanks for your help
Andreas

Hey @Andreas_Niedermann
Sorry, but please show me the settings in Appgyver and the error displayed by it.
Thanks

@Fernando_Oliveira

Error: TypeError: Preflight response is not successfulstatus: -1

because Appgyver uses GET but I need to query the server with POST

@Andreas_Niedermann

Does this mean parameters to retain certain type of information or what do you want to record/save this information?

I’m a little confused so let’s forget for a moment the HTTP Get and POST “verbs”. Objectively, what do you want to do: save information or get information?
Additionally, please replicate the settings made in the “DATA CONFIGURATOR” option of AppGyver. You are doing this, right?
Lastly, please explain to me the “GetAppUser” in your URL.
Thanks.

@Fernando_Oliveira

I would like to use the GET DATA COLLECTION from AppGyver but not use the GET but the POST method for it, since the API requires it to query information. I would like to query the API and get information from it.

The API doesn’t accept GET where all parameters are sent in the URL but it requires the parameters sent in the body with the basic http authorization sent in the header.

POST

URL
http://our-domain.com/GetAppUser

Header
basic http authorization

Body
parameter1 = static
parameter2 = static
UserId = variable

When doing this post with the UserId X I get in return a json with numerous infos about the User X

In AppGyver I would like to use the GET COLLECTION (GET), run the test and SET SCHEMA FROM RESPONSE

Hope now it is more clear what I am trying to do.

Hey @Andreas_Niedermann

First, let’s try this approach and see what happens :slight_smile:

Step 1
DATA CONFIGURATOR → BASE


Step 2

Step 3

Step 4

Good luck!

@Fernando_Oliveira

Thanks for all the work. I did exactly as you asked but still get

Error: TypeError: Preflight response is not successfulstatus: -1

Hey @Andreas_Niedermann

Okay. But don’t be discouraged :slight_smile:
This error message may also be related to IIS settings. So see this technical article (IIS Team Blog - Getting started with the IIS CORS Module). He can help resolve this situation. It will most likely be necessary to add other elements to HEADER for use through AppGyver.

Good luck.

Hi @Fernando_Oliveira yeah, thats probably the issue.

In the Web.config I found this

  <system.web>
   <compilation targetFramework="4.0" />
   <customErrors mode="Off" />
   <authorization>
     <deny users="*" />
  </authorization>
</system.web>

Problably that’s the issue

1 Like

Hi @Fernando_Oliveira

I am getting nowhere here sadly. I activated CORS on our IIS6.2 but still can’t access our API from Appgyver.

Any idea left?
Andreas

Hey @Andreas_Niedermann

Try adding to the header:
Origin: http://our-domain.com
Access-Control-Request-Headers: additional-header

:muscle:

@Fernando_Oliveira got a little further. We have indeed IIS8 on our server and that needs an extension to be installed for CORS.

Now I have set up CORS in Web.config

    <cors enabled="true"> 
<add origin="https://platform.appgyver.com"  allowCredentials="true"/>
    </cors>

Appgyver now gives me back a different error message:

Error: TypeError: Request header field Content-Type is not allowed by Access-Control-Allow-Headers.status: -1

Any idea what’s left?

Hey @Andreas_Niedermann

Try this now:

<add origin="https://platform.appgyver.com"  allowCredentials="true"/>
        <allowMethods>
            <add method="GET" />
            <add method="POST" />
        </allowMethods>
      </add>

Additionally…
What values are you passing in the DATA CONFIGURATOR → BASE–>HTTPHeader?
Can you make the API call through the browser?

You can try that too…

<httpProtocol>
  <customHeaders>
    <add name="Access-Control-Allow-Origin" value="*" />
    <add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept" />
    <add name="Access-Control-Allow-Methods", "GET,HEAD,OPTIONS,POST,PUT" />
  </customHeaders>
</httpProtocol>

@Fernando_Oliveira thanks a lot for your patience it worked now!

Hey @Andreas_Niedermann

Congratulations! I’m really glad you made it. I never give up and apparently you don’t either!
A hug and keep going! :clap: