Hello everyone,
I am attempting to get connected to the Ford API in order to integrate my truck into my home automation dashboard I am creating for my home.
I went through the documentation and got everything working with Postman, however when I try to use ignition scripts to hit the API, but for some reason will not work. I believe I have everything formatted the same as postman, but it still is not working. Below are some screenshots of my script and then screenshots of Postman with a valid response. I will also include pictures of the headers that Postman is sending to the URL as well as body context.
Refresh Token API Call "Valid response / not showing the token for security reasons" (Postman)
Headers (same API Call)
Body (also same API Call)
Now on the scripting side I have the refresh_token populated in a tag as well as client_secret and client_id (here is a picture of my script with the result)
Update: I got part of it working, however I noticed in a different Ignition post on the forum that there is no support for multipart/form-data in ignition at this time. Is that still true? The post was from 2022.
I have used the multipart/form-data
content type before - the only caveat is you have to manually create the boundary and format the fields within the form. Here is a code snippet I pulled from a previous project:
def jsonToMultipartFormData(json):
"""
Translates the application/json content type to
the multipart/form-data type for easier processing
"""
import mimetypes
import os
boundary = "----WebKitFormBoundary7MA4YWxkTrZuOgW"
CRLF = "\r\n"
body = ""
for key, value in json.items():
body += '--' + boundary + CRLF
body += 'Content-Disposition: form-data; name="{}"'.format(key) + CRLF
body += CRLF
body += str(value) + CRLF
body += '--' + boundary + '--' + CRLF
content_type = 'multipart/form-data; boundary={}'.format(boundary)
return { "content_type": content_type, "body": body }
Just to warn you, the code formatting might be messed up because I had to send it to myself through Teams, but that should give you an idea of what you can do to use that MIME type.
I wrote this code what seems like years ago, so I don't remember the exact usage, but I believe what gets returned from this function would end up as your httpClient
's body
(Postman terminology).
I'm posting a screenshot of
- My script that I'm attempting to use in order to get a response from an API.
- The way your script formatted it as multipart/form-data
- The response from the API
I have the grant_type parameter in the payload so I'm assuming its not formatted as form-data correctly?