Question

Sending data from the authentication form is not received in the API endpoint


Userlevel 1
Badge

Hello guru developers, after doing some research and my homework I get here to ask (beg) :pray_tone2: for help from you, maybe this could be simple but I'm not able to receive in my API the data submitted by the authentication form in my API endpoint.

Maybe I don't understand well the data flow but as far as I could understand Zapier will post the fields I specify in the authentication form to the token exchange URL and I will be able to get the POST information and work with that to generate the token zapier will exchange. (I hope to be clear at this point)

I'm doing exactly so, posting but the posted fields seem not to be going to the endpoint.

this is my form:

 

This is the endpoint configuration, what could be missing here?

I tried filling headers, request body but no luck :disappointed_relieved:

 

in my API code, I validate if a post was received.

     if ($this->request->getMethod() === 'post')
{
$pUsername=$this->request->getPost('pUsername');
$pPassword=$this->request->getPost('pPassword');
$pCompany=$this->request->getPost('pCompany');
$pWebWervice=$this->request->getPost('pWebWervice');

}

but it seems it is not getting the post

what I'm doing wrong?

Thanks in advance for any help.


12 replies

Userlevel 6
Badge +9

Would you mind posting the configuration for your authentication test request? When you create a connected account for your integration, using session auth, Zapier is going to try that test request first. Only when the the test request returns a 401 response will Zapier run your token exchange request, to trade your user’s auth material for a token, then it’ll try the test request again with that newly minted token.  

I’d guess here that your exchange endpoint is not getting hit because the test request isn’t returning a 401… but that’s just a guess. 

Userlevel 1
Badge

Sure
 

const options = {
url: 'https://reborncabinets.herokuapp.com/authenticateuser',
method: 'GET',
headers: {
'X-P-USERNAME': bundle.authData.pUsername,
'X-P-PASSWORD': bundle.authData.pPassword,
'X-P-COMPANY': bundle.authData.pCompany,
'X-P-WEB-WERVICE': bundle.authData.pWebWervice

},
params: {
'pUsername': bundle.authData.pUsername,
'pPassword': bundle.authData.pPassword,
'pCompany': bundle.authData.pCompany,
'pWebWervice': bundle.authData.pWebWervice
}
}

return z.request(options)
.then((response) => {
response.throwForStatus();
const results = response.json;

// You can do any parsing you need for results here before returning them

return results;
});

 

Userlevel 6
Badge +9

Is that your test request?  What you want to see in your test request is a use of the token.  It should fail the first time you call it because there’s not valid token in context. Generally this is a “/me” kind of endpoint or just any random endpoint that requires authentication, and allows Zapier to confirm we have a good token before doing anything else.

This appears to be the same as the token exchange request. This request is using the user-provided auth material, not a token.  If you’re using session auth, this is not what you’ll want to use as your authentication test configuration.

 

Userlevel 1
Badge

I will test and post here again, thanks.

Userlevel 1
Badge

I'm not sure if I explain myself correctly maybe not :

In my configuration I have two Methods:

1- authenticateuser this is for: Configure a Token Exchange Request
2-me: Configure a Test Request this expect /paparemter1/parameter2  the second is the token (for now any value works)

 

When I try to test the Authentication Form it seems it is not sending the POST to my API Endpoint, I'm using PHP and trying to get the post with php://input I also had tried other technics, but it seems the post is not being received by the API

 

When I try to reconnect the account with this form, should not be the fields be posted to the API Endpoint?
 



I received this error because the fields are not going into the API

 

Any help would be appreacited.

Userlevel 1
Badge

Hello @Zane did you see my last update about this issue?

Userlevel 6
Badge +9

I think you might need to reach out to contact@zapier.com so someone can look at your logs to make sense of what’s going wrong. 

Also note that from that error message, it looks like you might be trying to communicate with a SOAP API, in which case you’ll want to move your project to the Zapier CLI, and use library to help with XML parsing/marshalling/unmarshalling of requests and responses, etc.  

Userlevel 1
Badge

Thanks, yes I’m consuming a SOAP service, but I did a layer to get convert the response to JSON, that part is covered

I get a token now 

 

I changed the Authentication Method to API Key and it was easier, the thing now is that I want to send the token I get to the triggers and I don’t know how :cry:

 

Userlevel 6
Badge +9

Have you added the sessionKey to the appropriate header in each request you’re making - starting with the test request. So replace all that user provided material with that sessionKey - available in bundle.authData.sessionKey.  Be mindful of the header name your API is actually expecting. 

With session auth we don’t attempt to add a default to requests like we do with the other auth methods, so you’ll need to remember to do that for each request.  Hopefully that’s the issue and the only problem left blocking you. 

 

 

Userlevel 2
Badge

Hey @rafaelsanchezrd! Just checking in to see how you’re getting on. Were you able to get this set up?

Userlevel 1
Badge

Hello @SamB , yes after a lot of clicks :grimacing: I was able to solve it, even it seem obvious the Request Body was sending fields with names in the same format of the headers and the fields names were not the sames.

 

 

in the API side I just get the post from the fields with a function like this:
 

public function getpostfromzapier(){
//get post from zapier
$datos = json_decode($this->request->getBody());
if ($datos) {
$company =
array(
'pUsername' =>$datos->pUsername,
'pPassword' =>$datos->pPassword,
'pCompany'=>$datos->pCompany,
'pWebWervice'=>$datos->pWebWervice,
'pEmpresa'=>$datos->pEmpresa,
'token'=>$datos->token
);
return json_encode($company);
} else {
$myJSON=$this->invalid_credentials('getpostfromzapier');
return $myJSON;
}
}

 

Userlevel 2
Badge

That’s great news! Thanks for sharing the solution that you found @rafaelsanchezrd!

Reply