Expensify.org/hunger SNAP campaign status 


The number of families signing up for reimbursement has vastly outnumbered the limited funds available. Though we’re unable to provide a specific timeline on when your report will be reimbursed, we’re doing our best to drive donations and keep our fund moving forward. Rest assured, we’ll review every report that’s submitted per our instructions. 


Thanks for your patience! 

Powershell to update tags using API

MarkW2MarkW2 Expensify Customer Posts: 3

I'm using Invoke-Webrequest to emulate the curl command in the API for updating tags using a file. I've used community posts to resolve most of my issues. I can successfully connect with the API and post the JSON portion. However, I've not been able to upload the file that contains the tags. The curl example shows this as '[email protected]' after the JSON portion of the post. I've tried Invoke-RestMethod as well. No matter how I format it, I can't seem to emulate that portion of the curl and the response is always "Tag file is missing". Any help would be appreciated.

Answers

  • MarkW2MarkW2 Expensify Customer Posts: 3

    further examined the example by DMuncy and encoded the filename to get past the "Tag file is missing"

    Now I get "Could not split the file on multiple lines. The file probably does not have proper End Of Line characters"

    Confirmed csv has CR LF end of each line.

    Following is the current code


    $ptruserID = 

    $ptrusersec = 

    $PolicyID = 

    $dependency = $false

    $glCodes =$true

    $header = $true

    $setRequired=$false

    $json = [ordered]@{

        "type"="update";

        "credentials"[email protected]{

          "partnerUserID"=$ptruserID;

          "partnerUserSecret"=$ptrusersec

        };

        "inputSettings"[email protected]{

          "type"="policy";

          "policyIDList"[email protected]($PolicyID)

        };

        "tags"[email protected]{

          "action"="replace";

          "source"="file";

          "config"[email protected]{

              "dependency"=$dependency;

              "glCodes"=$glCodes;

              "header"=$header;

              "setRequired"=$setRequired;

              "fileType"="csv"

              };

        };

      } | ConvertTo-Json

    $url = "https://integrations.expensify.com/Integration-Server/ExpensifyIntegrations"

    $request = "requestJobDescription="

    $file = Get-Item -Path C:\PM_to_Expensify.csv

    $encode = [System.Web.HttpUtility]::UrlEncode($file)

    $body = $request + $json + "'&file='$encode"


    Invoke-Webrequest -uri $url -body $body -Method Post

  • Francois LaithierFrancois Laithier Expensify Team Posts: 22 Expensify Team
    edited November 2019
    Hi there,

    Any chance you can check the value of [System.Web.HttpUtility]::UrlEncode($file) and see if the line breaks are preserved? The result shouldn't be on one single line.

    If the line breaks are still present as expected, can you try to convert them to just LF (instead of CRLF)?

    Cheers
  • MarkW2MarkW2 Expensify Customer Posts: 3
    I assumed that the API is looking for two inputs ("requestjobdescription" and "file"), so I did a slight rewrite so make those elements of an array in the Powershell.  It didn't seem to make a difference.  No matter what I try, I get the same 666 response code (should I take that as a sign?).  The API seems to accept the "requestjobdescription" component, but I have no idea what the API is expecting for the "file" input.  I've tried:
    • full path to the file
    • relative path to the file
    • encoded paths (using [System.Web.HttpUtility]::UrlEncode)
    • content of the file using Get-Content
    • encoded content of the file
    For the file itself, I've tried:
    • File with header information
    • File with just a single line and no header (header set to $false)
    • CRLF for EOL
    • LF for EOL
  • Francois LaithierFrancois Laithier Expensify Team Posts: 22 Expensify Team
    The API does expect a second parameter called file if your requestJobDescription contains:
            "tags": {
                "action": "replace",
                "source":"file",
            "..."
    
    which is the case for you. The fact that you received a Could not split the file on multiple lines error means that the data in your CSV file was transmitted to our API, but the line breaks weren't correct, e.g. if your CSV file contained:
    a,b,c
    d,e,f
    
    then we received
    a,b,cd,e,f
    
    Since you only have one level of tags, you can also directly pass them as JSON objects in the requestJobDescription:
    {
        "type": "update",
        "credentials": {
            "...": "...",
        },
        "...": "...",
        "tags": {
            "data": [
                {
                    "name": "Tag Level 1",
                    "setRequired": true,
                    "tags": [
                        {
                            "name": "Tag 1",
                            "glCode": "Tag 1 GL Code"
                        },
                        {
                            "name": "Tag 2",
                            "glCode": "Tag 2 GL Code"
                        }
                    ]
                }
            ]
        }
    }
    
  • ComportTomComportTom Expensify Customer Posts: 10 Expensify Newcomer

    Powershell rookie....

    Hoping to resurrect this issue. I am also trying to import tags using Powershell. In my case, the tags ARE dependent, so I need to import from a file. It looks to me like the import from file was never made to work, instead the user included the content in the json.

    I tried the same code in post 3, and I too get the:

    Could not split the file on multiple lines. The file probably does not have proper End Of Line characters.","responseCode":666

    Looks like the script is passing the file's directory info instead of its contents... See below.

    ------------------------- Here is the content of $file ------

    PS C:\Users\Repetto> $file

      Directory: C:\users\repetto

    Mode        LastWriteTime     Length Name                                                                                                       

    ----        -------------     ------                                                                                                       

    -a----    2/11/2020 10:10 AM     362446 ExpensifyTags.csv                                                                                                


    ------------------------ and the content of $encode ---------------

    PS C:\Users\Repetto> $encode

    C%3a%5cusers%5crepetto%5cExpensifyTags.csv

  • ComportTomComportTom Expensify Customer Posts: 10 Expensify Newcomer
    edited February 11

    So maybe I am looking at this wrong. When I UrlEncode, is it the filename or the file contents I am trying to encode?

    When I query the $body variable, I see this:

    PS C:\Users\Repetto> $body

    requestJobDescription={

       "type": "update",

       "credentials": {

                           "partnerUserID": "*********",

                           "partnerUserSecret": "********"

                       },

       "inputSettings": {

                             "type": "policy",

                             "policyIDList": [

                                                  "***********"

                                              ]

                         },

       "tags": {

                    "config": {

                                   "setRequired": true,

                                   "glCodes": false,

                                   "header": true,

                                   "dependency": true,

                                   "fileType": "csv"

                               },

                    "source": "file",

                    "action": "replace"

                }

    }'&file='C%3a%5cusers%5crepetto%5cExpensifyTags.csv

  • Francois LaithierFrancois Laithier Expensify Team Posts: 22 Expensify Team

    Hi there,

    It looks like you're only passing the path to the CSV file in the request, instead of the file's content.

    Have you tried using Get-Item and [System.Web.HttpUtility]::UrlEncode($file) like in the posts above?

  • madslindenmadslinden Expensify Customer Posts: 6

    I’m on a Mac using curl and also have this issue “could not split bla....”

    did anyone find the solution?

    Thanks

Sign In or Register to comment.