Skip to main content

There are some postings on this topic but it does not work for me yet:

I am trying to contact an external API via HTTP POST to get a token back. If I use Postman from the same computer everything is okay:

The response from Postman is:

{

 

"access_token": "<access_token>",

 

"expires_in": 300,

 

"refresh_expires_in": 1800,

 

"refresh_token": "<refresh_token>",

 

"token_type": "bearer",

 

"not-before-policy": 0,

 

"session_state": "c25bf161-2dee-426c-9bdc-970836fe4f4f",

 

"scope": "email profile"

 

}

 

Comment: Hostname, company, username, password, access_token and refresh_token are replaced by dummy text in this posting...

This response ist correct! But when I try to do the same in FME 2019 I got errors:

Multipart Upload 'password' is missing in this screenshot. Other values are replaced by dummy text... There are no parameters set in Query String Parameters and Headers.

The FME 2019 translation log includes the following:

>>>

HTTPCaller_2 (HTTPFactory): HTTP/FTP Transfer: Downloading resource '<url>' to internal memory buffer

 

HTTPCaller_2 (HTTPFactory): HTTP transfer summary - status code: 400, download size: '84 bytes', DNS lookup time: '1e-6 seconds', total transfer time: '0.328 seconds', url: '<url>'

 

HTTPCaller_2 (HTTPFactory): Received HTTP response header: 'HTTP/1.1 400 Bad Request' from '<url>'

<<<

Data Inspector:

>>>

 

error:

 

HTTP/1.1 400 Bad Request - <url>

 

 

fme_rejection_code:

 

NO_RESULT

 

 

response_body:

 

{"error":"invalid_request","error_description":"Missing form parameter: grant_type"}

 

 

http_status_code:

 

400

<<<

The parameter 'grant_type' is included in the Multipart Upload, why does the error message says that it is a "missing form parameter"? Do you have any idea why it does work in Postman but not in the HTTPcaller? Any hints?

 

Best regards,

Frank

 

 

Edit:

I always use Specify Upload Body. Working workspace template attached.

gettoken2019.fmwt


It's getting better all the time...

Your workspace does work for me! I have change my HTTPcaller from Mulitpart/Form data to Specify Upload Body and I put the keys and values into the Upload Body. Now I get the following response:

{"error":"invalid_grant","error_description":"Invalid user credentials"}

and

error (string): HTTP/1.1 401 Unauthorized - <url>

Username and password are the same as in Postman. There are special characters like "_", "+" in the username and the password. Is it necessary to handle these in a special way? Something like encoding?


It's getting better all the time...

Your workspace does work for me! I have change my HTTPcaller from Mulitpart/Form data to Specify Upload Body and I put the keys and values into the Upload Body. Now I get the following response:

{"error":"invalid_grant","error_description":"Invalid user credentials"}

and

error (string): HTTP/1.1 401 Unauthorized - <url>

Username and password are the same as in Postman. There are special characters like "_", "+" in the username and the password. Is it necessary to handle these in a special way? Something like encoding?

Hi @frank,

 

this might be related to the string encoding. I would try 2 options:

1. When you use the example of @nielsgerrits try to create your string in with an AttributeCreator and then encode it (Encoding Type: URL) with the TextEncoder and then reference the resulting attribute in the Upload Body parameter.

2. Using your initial approach with Multipart/Form Data make sure you set a Content-Type Header in the HTTPCaller with the value "application/x-www-form-urlencoded".

I thought that the HTTPCaller would take care of the encoding automatically, but I think it's worth trying these options.

Let us know how this goes!


Hi @frank,

 

this might be related to the string encoding. I would try 2 options:

1. When you use the example of @nielsgerrits try to create your string in with an AttributeCreator and then encode it (Encoding Type: URL) with the TextEncoder and then reference the resulting attribute in the Upload Body parameter.

2. Using your initial approach with Multipart/Form Data make sure you set a Content-Type Header in the HTTPCaller with the value "application/x-www-form-urlencoded".

I thought that the HTTPCaller would take care of the encoding automatically, but I think it's worth trying these options.

Let us know how this goes!

As @gerhardatsafe points out I think url encoding the body will fix your problem.

Encoding was the solution: the values for username and password must be encoded (type: url) and integrated into the upload body string via StringConcatenator. If I encode the whole UploadBody it does not work for me! Thanks a lot @gerhardatsafe and @nielsgerrits!


It's getting better all the time...

Your workspace does work for me! I have change my HTTPcaller from Mulitpart/Form data to Specify Upload Body and I put the keys and values into the Upload Body. Now I get the following response:

{"error":"invalid_grant","error_description":"Invalid user credentials"}

and

error (string): HTTP/1.1 401 Unauthorized - <url>

Username and password are the same as in Postman. There are special characters like "_", "+" in the username and the password. Is it necessary to handle these in a special way? Something like encoding?

Encoding was the solution: the values for username and password must be encoded (type: url) and integrated into the upload body string via StringConcatenator. If I encode the whole UploadBody it does not work for me! Thanks a lot @gerhardatsafe and @nielsgerrits!


Reply