-1

I am attempting to build my own integration in zapier that will allow me to create quotes in Xero (a feature not currently supported natively). I've been using this this post and this reference to help me.

I've gotten to the point where I'm creating the action and testing it with test data. Unfortunately, the response I get is "Got 400 calling POST https://identity.xero.com/connect/token, expected 2xx." Perhaps I'm sending the json data incorrectly. I've tried using the 'pretty' and 'raw' ways of sending data:

Could a zapier "expert" help me with this? Perhaps by creating their own xero integration?

EDIT

enter image description here enter image description here enter image description here enter image description here

Not sure if necessary, but blocked out the IDs. Although I now see that I didn't do that for the contactID in the first post lol... enter image description here

Matthew
  • 13
  • 3
  • Instead of web builder you can use Zapier CLI for custom Xero integration. If you didn't have experience with Zapier CLI then you can hire a certified expert from https://zapier.com/experts/. I used certified expert from zapier for one of my integartion and got a better result. – Kishor Patidar Feb 27 '20 at 11:48
  • I'd block out that ContactID, if you are working from a dummy account it may not be a huge deal but if this is your actual than I'd at least remove that particular contact and re-enter them so that they receive a new id. – littlecoder Feb 28 '20 at 13:47

1 Answers1

-1

Here is how to get it done, but remember that you will need to have a search action to find information for the required ID's. Given your error I think the problem is that you did not have the tenantId that should be defined in your header like so: 'xero-tenant-id': 'YOURNUMBERHERE'. See step 8 below to compare it to yours.

In case you can't find it, these are the steps I took:

XERO

  1. Create Account
  2. Create Xero App and add the Zapier OAuth Redirect URL to the Xero redirect section(from your 'Zapier Dev' app on 'step 2').

ZAPIER

  1. In your dev app, add the CLient ID & Secret from xero to the appropriate sections in 'Zapier Dev step 3'
  2. Add the POST endpoint (requested in 'Zapier Dev step 4') https://login.xero.com/identity/connect/authorize with the HTTP headers:

    response_type: code
    client_id: {{process.env.CLIENT_ID}}
    redirect_uri: {{bundle.inputData.redirect_uri}}
    state: {{bundle.inputData.state}}
    
  3. Add the scope: openid profile email accounting.transactions

  4. Refresh token ('Zapier Dev step 4: Access Token') can be obtained using this:

    REFRESH TOKEN: POST https://identity.xero.com/connect/token
    TEST CALL: GET https://api.xero.com/connections
    

    -Keep the returned tenantId for later use

    -Test the authentication. Does it work? If yes, move on to step 7.

    -If test fails: review for typos, check for correct url's and make sure your Headers match what xero requires (see link at bottom).

  5. Add Action called createQuote

    -Add input contactID

    -Add input lineitem with label of description

    -Add input tenantId

  6. Add POST to API Config at url https://api.xero.com/api.xro/2.0/Quotes

    Example POST:

    const options = {
      url: 'https://api.xero.com/api.xro/2.0/Quotes/',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        'Authorization': `Bearer ${bundle.authData.access_token}`,
        'xero-tenant-id': bundle.inputData.tenantID
      },
      params: {
      },
      body: {
        "Contact": { 
        "ContactID": bundle.inputData.ContactID
        },
        "Date": "2019-11-29",
        "LineItems": [
        {
          "Description": bundle.inputData.LineItems
        }
        ]
      }
    }
    
    return z.request(options)
      .then((response) => {
        response.throwForStatus();
        const results = z.JSON.parse(response.content);
        return results;
      });
    
  7. Plug in the test contactID, tenantID, lineitems and test it out

After completing this you will need to create a search action to grab the contactID and tenantID if you want it all automated. If you have problems I found the start-up doc to be useful.

littlecoder
  • 356
  • 2
  • 15
  • Thanks for the response. I tried what you said and am still getting the same response. Have you successfully implemented what you did above? – Matthew Feb 27 '20 at 03:50
  • Yes, the call above I copy/pasted from the working model I ran (assuming you enter in a valid contactID and tenantID). So I would bet the issue is on the Oauth setup, when you hit 'test connection' does it say success or failure? – littlecoder Feb 27 '20 at 14:32
  • Could you provide your oAuth2 setup (hide the client ID/Secret and any private info)? If you had a picture of that or further detail I think we could find the issue pretty quickly (if its on that end, which I suspect it is). – littlecoder Feb 27 '20 at 14:49
  • I was able to successfully connect to a xero account which is why I doubt it's a problem with oauth. But what do I know lol. All add images to a question edit. – Matthew Feb 27 '20 at 23:05
  • I compared your oAuth to mine. No problem most likely there. So, with the variables you named, if you copy/pasted my code in step 8 it should work assuming (I tried it all again by starting over and using your setup exactly as shown). If you do that then there are only 2 reasons it can fail. First, you may have an invalid tenentID, contactID, missing string for LineItem or Date. Second, that there is a typo, missing bracket, comma, etc. somewhere in the Action step. When I built one for Quickbooks I stumped Zapier support and the stacks with a missing comma. – littlecoder Feb 28 '20 at 14:20
  • Also, what is the error code now? It should not be the same one as you posted initially (as the token error should not be there if you successfully test the connection). Basically I think we have 2 separate errors. – littlecoder Feb 28 '20 at 14:24
  • So now I'm getting a similar error, but it's when calling https://api.xero.com/api.xro/2.0/Quotes/ – Matthew Mar 02 '20 at 21:19
  • Just realized something! I've been using the tenant ID as the contact ID. How do I get the contact ID? – Matthew Mar 02 '20 at 21:25
  • nevermind found the contact id, but still getting an error – Matthew Mar 02 '20 at 21:32
  • ok I got it working all of the sudden. unfortunately I made multiple changes before I got it working, so I'm not sure what the root of the problem was. Quick question, is tenant ID always going to be the same? I'm guessing it would be since I'm authorizing from the same account always. If not, where can I pull it from? Obviously I can't manually enter it for every zap. – Matthew Mar 02 '20 at 21:38
  • I believe the best way to do it would be entering 'xero-tenant-id': process.env.TENANT_ID in the headers. – Matthew Mar 02 '20 at 22:31
  • Yes, you will always need the tenant ID. It is basically the Xero user number. So if you can store that as a process variable for later use during authentication it would be best. When I was setting it up I kept having trouble pulling it into the action step so I just skipped it for the sake of time. – littlecoder Mar 03 '20 at 17:09